← Home
API

Run it as a local OpenAI-compatible provider

The engine ships a library, not a server. The OpenAI-compatible endpoint is the TinyCoder OpenAI gateway — a Go HTTP server that links the engine — so existing OpenAI-style tooling has something to point at.

Embed the library

Pull tinycoder_core into your own CMake project, then load and generate through the C++ API.

cmakeFetchContent
FetchContent_Declare(tinycoder_inference
    GIT_REPOSITORY https://github.com/mgorshkov/tinycoder-inference
    GIT_TAG <tag or commit>)
FetchContent_MakeAvailable(tinycoder_inference)
target_link_libraries(your_target PRIVATE tinycoder_core)
C++load + generate
#include "Model.hpp"
using namespace tinycoder;

Model model;
std::string err;
if (!model.load("/path/to/model.gguf", &err)) {
    // handle error
}

InferenceParams params;
params.maxTokens   = 512;
params.temperature = 0.7f;
params.topP        = 0.9f;

model.generate("Write a C++ function to add two numbers.",
    params, [](int32_t tokenId, const std::string &text) {
        std::cout << text << std::flush;
        return true;
    });

Serve the API

Build the gateway with its native engine, then point it at a models directory.

shelltinycoder-openai
./scripts/build.sh
./build/bin/tinycoder-openai \
    --listen :8080 \
    --models-dir /data/models
shellone model, no registry
./build/bin/tinycoder-openai \
    --model /data/models/qwen2.5-coder-1.5b-instruct-q2_k.gguf \
    --model-id qwen2.5-coder-1.5b --ctx 4096
shelllocalhost:8080
curl -s http://localhost:8080/v1/models

curl -s http://localhost:8080/v1/chat/completions \
  -H 'Content-Type: application/json' \
  -d '{"model":"qwen3.6-35b-a3b",
       "messages":[{"role":"user",
                    "content":"Write a C++ hello world."}]}'

Model ids come from the gateway's config registry: each entry points at a GGUF file or an EXL3 checkpoint directory. The registry is authoritative — files on disk that are not listed are never served. --model, --model-id and --ctx serve exactly one model without a registry, and --ctx 0 inherits max_seq_len.

Endpoints the gateway actually serves

Only these paths are served — there are no unversioned or legacy aliases.
Method Path What it does
GET/v1/modelsList registry models, with tinycoder metadata
POST/v1/chat/completionsChat completion; SSE streaming; tool calling
POST/v1/completionsText completion; SSE streaming
POST/v1/responsesOpenAI Responses API
POST/v1/messagesAnthropic Messages API
POST/v1/generateNative endpoint; accepts prompt or messages
GET/openai.json, /openai.yamlOpenAPI 3.1 document
GET/healthzLiveness probe
GET/readyzReadiness probe; reports model warm-up

A prompt longer than the model's context window is refused with HTTP 400 and the OpenAI error code context_length_exceeded — Anthropic-shaped on /v1/messages, and as an SSE error event when a stream is already open. It is not silently truncated.

What it supports

  • SSE streaming on the completion endpoints, a final data: [DONE], and keep-alive comments while a model loads or a long prompt prefills.
  • Tool calling on /v1/chat/completions: OpenAI tools, tool_choice and tool_calls, including streamed deltas.
  • Chat templates rendered inside the engine from the model's own template — send messages, not a pre-formatted prompt.
  • One model registry for both formats: each entry points at a GGUF file or an EXL3 checkpoint directory, and the engine auto-detects which.
  • Lazy loading with LRU idle eviction, optional bearer-token auth, CORS, request timeouts and a global concurrency cap.
  • /healthz is liveness and /readyz is readiness; optional preload / preload_models warms models at startup so an orchestrator holds traffic until they are warm.

What it is not

  • Not full OpenAI parity. Those paths are the whole surface, and there are no unversioned or legacy aliases.
  • Generation is serialized: the engine owns a single KV cache and one GPU, so requests queue rather than run concurrently. max_concurrent_requests bounds the queue, not the parallelism.
  • Tool calling is elicited through a text protocol, not constrained decoding: best effort, and only on /v1/chat/completions.
  • /v1/responses and /v1/messages accept and ignore fields they do not model (store, previous_response_id, tools, metadata); max_tokens is required on /v1/messages.