API reference
The server speaks HTTP/1.1 with keep-alive (an idle connection stays open ten minutes, longer than client pools keep one, so the client closes it first), chunked request bodies and Server-Sent Events for streaming. The base URL is wherever serve bound, http://127.0.0.1:8080 by default.
Routes
| Method | Path | Purpose |
|---|---|---|
POST |
/v1/chat/completions |
OpenAI chat completion, streaming and tool calling |
POST |
/v1/responses |
OpenAI response: typed items, semantic stream events, function calling, stored conversations |
GET |
/v1/responses (WebSocket) |
The Responses API’s WebSocket mode |
GET, DELETE |
/v1/responses/{id} |
A stored response, and its deletion |
GET |
/v1/responses/{id}/input_items |
The items a stored response was generated from |
POST |
/v1/responses/input_tokens |
The prompt length a response request renders to |
POST |
/v1/responses/{id}/cancel |
400: only a background response can be cancelled, and none runs here |
POST |
/v1/messages |
Anthropic message, streaming, tool use and message threads |
POST |
/v1/messages/count_tokens |
The prompt length a message request renders to |
POST, GET |
/v1/files |
Upload a batch input file, list files |
GET, DELETE |
/v1/files/{id}, /v1/files/{id}/content |
A file, its content, its deletion |
POST, GET |
/v1/batches, /v1/batches/{id}, /v1/batches/{id}/cancel |
OpenAI batches |
POST, GET, DELETE |
/v1/messages/batches, /v1/messages/batches/{id}, /v1/messages/batches/{id}/results, /v1/messages/batches/{id}/cancel |
Anthropic message batches |
GET |
/v1/models |
The loaded model |
GET |
/v1/models/{id} |
The loaded model, 404 for any other id |
GET |
/health, /healthz |
Readiness, no key needed |
GET |
/metrics |
Prometheus text |
OPTIONS |
any | CORS preflight, no key needed |
POST, GET |
/v1/sessions |
Create and list sessions |
GET, DELETE |
/v1/sessions/{id} |
Inspect and delete a session |
POST |
/v1/sessions/{id}/generate |
Ask a question over a session’s context |
POST |
/v1/sessions/{id}/push |
Queue data for background ingestion |
POST |
/v1/sessions/{id}/warm |
Prefill a conversation ahead of the session’s next turn, generating nothing |
POST, GET |
/v1/sessions/{id}/flash |
Register and list flash queries |
DELETE |
/v1/sessions/{id}/flash/{fid} |
Remove a flash query |
GET |
/v1/sessions/{id}/events |
The session’s event stream (SSE) |
GET |
/v1/sessions/{id}/ws |
The session’s event stream and push channel (WebSocket) |
The session routes are described on the Sessions page. A trailing slash is ignored. A known path with the wrong method answers 405; an unknown path answers 404.
Authentication
By default the API is open: no route needs a key. Started with --api-key <KEY>, every route except OPTIONS, /health and /healthz requires that key, which has nothing to do with the license key:
Authorization: Bearer <KEY>x-api-key: <KEY> is accepted too, which is what Anthropic SDKs send. A missing or wrong key answers 401 with missing or invalid API key; send it as 'Authorization: Bearer <KEY>', in the envelope of the client (Anthropic’s under /v1/messages, and on the other routes under an anthropic-version header; OpenAI’s otherwise). A WebSocket upgrade without the key is refused with a plain HTTP 401 before the handshake. Without --api-key any Authorization or x-api-key header is ignored. The examples on this page leave the header out.
Errors
OpenAI routes, the session routes included (except as below for an Anthropic client):
{"error": {"message": "'min_p' is not supported", "type": "invalid_request_error"}}| Status | type |
|---|---|
| 401 | authentication_error |
| 402, 403 | permission_error |
| 400, 404, 405, 408, 409, 413, 431 | invalid_request_error |
| 429 | rate_limit_error |
| 5xx | server_error |
A prompt that does not fit the context is refused with 400 before anything is streamed, so a client can compact the conversation and retry. On /v1/chat/completions, a session turn there, /v1/sessions/{id}/generate and a warm turn the body is OpenAI’s, with param and code (/v1/sessions/{id}/generate and the warm turn answer in Anthropic’s envelope instead for a request that sent an anthropic-version header). The context is the longest sequence admitted, so a prompt of exactly that many tokens is refused too, as it leaves the reply no position:
{"error": {"message": "This model's maximum context length is 32768 tokens. However, your messages resulted in 40112 tokens, leaving no room for the reply. Please reduce the length of the messages.", "type": "invalid_request_error", "param": "messages", "code": "context_length_exceeded"}}/v1/messages uses Anthropic’s envelope, with a request_id that the request-id response header repeats:
{"type": "error", "error": {"type": "invalid_request_error", "message": "'max_tokens' is required"}, "request_id": "req_..."}| Status | type |
|---|---|
| 401 | authentication_error |
| 403 | permission_error |
| 404 | not_found_error |
| 409 | conflict_error |
| 413 | request_too_large |
| 429 | rate_limit_error |
| other 4xx | invalid_request_error |
| 503, 529 | overloaded_error |
| 504 | timeout_error |
| other 5xx | api_error |
The /v1/responses routes answer in OpenAI’s envelope with param and code too (null where none applies): {"error": {"message", "type", "param", "code"}}. A prompt past the context there is code: "context_length_exceeded" with param: "input"; with "stream": true it comes inside the stream instead, as OpenAI’s stream sends it (see Streaming events).
Every error on a route under /v1/messages comes in this envelope, a request too large to read or an unknown sub-route included, and so does every error on the other routes for a request that sent an anthropic-version header (except /v1/chat/completions, whose requests are OpenAI-shaped). On /v1/sessions/{id}/generate that holds for an error event inside a stream too. A prompt past the context, on /v1/messages, on a warm turn sent in the Messages shape and on /v1/sessions/{id}/generate under the header, is:
{"type": "error", "error": {"type": "invalid_request_error", "message": "prompt is too long: 40112 tokens > 32767 maximum"}, "request_id": "req_..."}The maximum is the longest prompt admitted: the reply needs one position.
A streaming response sends its status line with the first generated token, so anything that refuses the request before then (an image the engine cannot take, a KV pool with no room, a backend fault) is an HTTP error with its own status and envelope, as on a non-streaming request. Only an error after the first token arrives as an event: an OpenAI error object as a data: frame followed by data: [DONE], an Anthropic event: error frame, or on /v1/responses an error event followed by response.failed.
Request parameters the engine cannot honour are refused by name with a 400. The exceptions are model, which is accepted and ignored on every route, metadata on /v1/messages, and on /v1/responses the fields that only steer billing, caching, telemetry, routing or presentation, which are accepted without effect, and any field the reference does not define, which is ignored as the reference servers ignore it (see Request fields).
POST /v1/chat/completions
curl http://127.0.0.1:8080/v1/chat/completions \ -H "Content-Type: application/json" \ -d '{ "messages": [ {"role": "system", "content": "Be brief."}, {"role": "user", "content": "Why is the sky blue?"} ], "max_tokens": 200, "temperature": 0.2 }'Request
| Field | Default | Notes |
|---|---|---|
messages |
required | Roles system, user, assistant, tool (ipython is accepted as tool, and OpenAI’s developer as system, which it renders as). content is a string or an array of parts: {"type": "text", "text": ...}, image_url (a data: URL) on a checkpoint with a vision tower, and input_audio on one with an audio tower (see Audio input); other part types are refused. |
max_tokens or max_completion_tokens |
none | Left out, the reply runs until it stops or the context is full (finish_reason: "length"). A value past the room the prompt leaves is accepted, not refused: the reply ends with length when the context fills. |
temperature |
the checkpoint’s generation_config.json, else 1.0 |
0 is greedy. |
top_p |
the checkpoint’s generation_config.json, else 1.0 |
|
top_k |
the checkpoint’s generation_config.json, else none |
Each draw is kept to the top_k most probable tokens, before top_p, which then takes that fraction of their mass. 0 or -1 is no cap. |
seed |
none | |
stop |
none | A string, or an array of up to 4 strings of at most 64 bytes each. Excluded from the returned text. |
stream |
false |
|
stream_options |
none | {"include_usage": true} appends a final usage chunk. |
response_format |
{"type": "text"} |
{"type": "json_object"} or {"type": "json_schema", "json_schema": {"name", "schema", "strict"}} holds the reply to JSON (see Structured outputs). |
tools |
none | {"type": "function", "function": {"name", "description", "parameters"}}. |
tool_choice |
auto |
auto, none, required, or {"type": "function", "function": {"name": ...}}. required and a named function force a call on every template that calls tools (see Tool calling). They run the turn without thinking unless the request asks for it (enable_thinking: true, or a reasoning_effort of medium and up): then the model thinks first and calls after. A named function is one call. |
parallel_tool_calls |
true |
false: at most one tool call this turn. The turn ends where the call does, one decode step sooner. |
reasoning_effort |
none | none, minimal, low (no thinking) or medium, high, xhigh, max (thinking), for templates that render a reasoning setting. |
chat_template_kwargs |
none | date_string sets the template’s date; enable_thinking (a bool) turns a reasoning checkpoint’s thinking block on or off (on Qwen3 false closes an empty think block in the generation prompt, as the reference does), and an explicit reasoning_effort wins over it. add_generation_prompt and tools_in_user_message are accepted only as true. Other keys are refused. |
ignore_eos |
false |
Keep generating past end of sequence, to exactly max_tokens. |
logit_bias |
none | A map of token id to a bias from -100 to 100, added to that token’s logit before sampling: -100 bans the token, 100 forces it. |
skip_special_tokens |
true |
The vocabulary’s special tokens (an end of turn, the next turn’s header, a padding id) stay out of the reply’s text, as the reference decodes it. The markers the reply is read by still are: a reasoning block’s, a tool call’s, Harmony’s channel headers. false returns every generated token’s text, those tokens included. |
logprobs |
false |
Report every generated token’s logprob in choices[0].logprobs (see below). |
top_logprobs |
none | 0 to 20: also list that many of each position’s most probable tokens. Needs logprobs: true. |
include_reasoning |
true |
false leaves the reasoning out of the reply: no reasoning field or delta, and the reasoning tokens’ logprobs are dropped. It is still generated and counted. |
separate_reasoning |
true |
false leaves the reasoning in content as the model wrote it, markers included where the vocabulary spells them as text (Qwen3’s <think>); markers it flags special (Gemma 4’s thought channel, Mistral’s [THINK]) are special tokens like any other, kept with skip_special_tokens: false. Tool calls are still read. With include_reasoning: false the reasoning is left out either way. |
stream_reasoning |
true |
false sends the reasoning as one delta once it is complete, instead of as it is written. |
Assistant messages may carry tool_calls and their reasoning as reasoning (or the older reasoning_content; reasoning wins when both are sent); tool messages carry tool_call_id. Refused by name: n or best_of other than 1, min_p, repetition_penalty, a nonzero presence_penalty or frequency_penalty, other servers’ reply-constraint fields (structured_outputs, guided_json, guided_regex, guided_choice, guided_grammar, guided_decoding_backend, guided_whitespace_pattern, regex, ebnf, a top-level json_schema: use response_format), the deprecated functions and function_call, and audio output (modalities other than text, an audio field): every reply is text.
The x-layerscale-session-id header runs the turn against a session. A session_id body field is refused with 400. The same body sent to POST /v1/sessions/{id}/warm prefills the conversation into the session without generating, as background work the next turn takes over from.
Audio input
Gemma 4’s E-series (gemma-4-E2B-it, gemma-4-E4B-it) and Muse Spark Open carry an audio tower, and take a clip as a user content part:
{"type": "input_audio", "input_audio": {"data": "<base64 of the file>", "format": "wav"}}format is wav or mp3, and an {"type": "audio_url", "audio_url": {"url": "data:audio/wav;base64,..."}} part (or data:audio/mpeg) is the same clip, as is an audio block on /v1/messages, shaped like its image block: {"type": "audio", "source": {"type": "base64", "media_type": "audio/wav", "data": "..."}} (or audio/mpeg). These are hints: the file’s first bytes decide how it is read. The file is a WAV of integer PCM (8, 16, 24 or 32 bits) or IEEE float (32 or 64 bits) at 1 to 384 kHz, or an MPEG-1 or MPEG-2 Layer III file (MP3: 16 to 48 kHz, CBR or VBR, mono, stereo or M/S joint stereo), with any number of channels, averaged and resampled to 16 kHz (24 kHz on Muse Spark Open). Every other format (Ogg, FLAC, MP4, Layer I or II, MPEG-2.5, free-format or intensity-stereo MP3, a remote URL) is refused by name, as is a truncated file or a clip over 30 seconds (refused, not cut) or under 20 ms. A clip is one placeholder token per 40 ms (750 for 30 s; 80 ms on Muse Spark Open), counted in prompt_tokens; a request takes at most 16 clips, and a session turn none yet. The tower runs on the CPU and CUDA backends; on ROCm and Metal these checkpoints serve text and refuse an audio part by name, as other checkpoints do.
Image input
A checkpoint with a vision tower takes pictures as user content parts: {"type": "image_url", "image_url": {"url": "data:image/png;base64,..."}} here, an image block with a base64 source on /v1/messages. The file is a PNG or a JPEG (the first bytes decide, not the declared type; EXIF orientation is applied). A remote URL is refused by name, as is any other format, a truncated or corrupt file, a header past 32768 pixels a side, 89.5 megapixels or 1536 MiB to decode, and more than 16 pictures or 768 MiB of media in one request. A picture larger than the model takes is shrunk to its size: 8192 image tokens on Qwen3.5, Qwen3.8 and Qwen2.5-VL (about 8 megapixels on Qwen3.5 and 3.8), fewer on a card with little memory beside the weights (the start log’s vision_tower_sized line). A turn on a named session may carry pictures (see Sessions). Each picture is resized and cut as the checkpoint’s own processor cuts it and becomes that many placeholder tokens between the family’s markers, counted in prompt_tokens.
| Checkpoint | Image input | Backends that run the tower |
|---|---|---|
| Gemma 4 E2B, E4B, 26B-A4B, 31B | yes | CPU, CUDA |
| Llama 4 Scout and Maverick | yes | CPU, CUDA, ROCm |
| Mistral Small 3.x and Mistral Small 4 | yes | CPU, CUDA, ROCm |
| Qwen3.5, Qwen3.8 and Qwen3.8-Flash-Next | yes | CPU, CUDA, ROCm |
| Qwen2.5-VL (3B, 7B, 32B, 72B) | yes | CPU, CUDA |
| Nemotron 3.5 Super VL | yes | CPU, CUDA, ROCm |
| GLM-5.3-Flash | yes | CPU, CUDA |
| Kimi K3 and K3.1 Pro | yes | CPU, CUDA |
| Inkling 2 Mini | yes | CPU, CUDA |
| Muse Spark Open | yes | CPU, CUDA |
On a backend that does not run a checkpoint’s tower (Metal for every tower, ROCm for those the table lists without it), the checkpoint serves text and an image part is refused by name.
On Gemma 4’s 26B-A4B and 31B a picture’s tokens attend to one another in both directions on the sliding-window layers, as the checkpoints were trained; a prompt is never split between two prefill chunks inside a picture.
Response
{ "id": "chatcmpl-...", "object": "chat.completion", "created": 1757000000, "model": "nvidia-nemotron-3.5-super-vl-120b-a12b-nvfp4", "choices": [{ "index": 0, "message": {"role": "assistant", "content": "..."}, "logprobs": null, "finish_reason": "stop" }], "usage": {"prompt_tokens": 31, "completion_tokens": 57, "total_tokens": 88, "prompt_tokens_details": {"cached_tokens": 0}}}finish_reason is stop, length or tool_calls. On a checkpoint that reasons (see Reasoning) the message also carries reasoning. logprobs is null unless the request asked for it; then it is {"content": [...]} with one entry per completion token, in order:
{"token": " Paris", "logprob": -0.0123, "bytes": [32, 80, 97, 114, 105, 115], "top_logprobs": [{"token": " Paris", "logprob": -0.0123, "bytes": [32, 80, 97, 114, 105, 115]}, ...]}A reply speculative decoding drafted for (an MTP head or prompt lookup) carries its acceptance statistics twice: choices[0].speculative_decoding_stats (streaming, on the chunk with finish_reason) and metrics.speculative_decoding at the root (streaming, on the usage chunk, so it needs stream_options.include_usage). Both hold num_spec_steps (verify forwards), num_spec_tokens (the draft length k), num_draft_tokens (draft tokens proposed), num_accepted_draft_tokens, mean_acceptance_length (1 + accepted / steps) and draft_acceptance_rate (accepted / proposed, 0..1). acceptance_histogram counts the verify forwards that accepted exactly j drafts: an object keyed "j" (empty buckets left out) per choice, a list k + 1 long at the root. Nothing is added when nothing drafted; the Anthropic route carries no such field.
The logprobs are the model’s raw log-softmax, before temperature and top_p, so they are the same at any temperature. top_logprobs is sorted most probable first. token is the token’s bytes read as UTF-8, with U+FFFD for a byte-fallback piece of a character; bytes are the token’s own. Tokens a tool call’s scaffolding forced into the reply were not sampled, and report logprob 0 and no alternatives. usage.prompt_tokens_details.cached_tokens is always present and counts every prompt token served from cache: the KV a session turn resumed, and the prefix cache’s pages another request with the same opening computed, finished or still running. The two never overlap, so prompt_tokens minus cached_tokens is what the request computed. usage.prompt_tokens_details.prefix_cached_tokens, present only when nonzero, is the prefix cache’s part of cached_tokens. The streamed usage chunk carries the same fields.
Reasoning
A checkpoint that thinks before it answers returns its reasoning apart from the answer. Its markers come from its chat template, read once at load: the <think> block of Qwen3, Qwen3.5, Qwen3.8, Nemotron 3.5, GLM-5.3, Ripple-65B and Flint, Gemma 4’s thought channel, Mistral 4’s [THINK] block (and a Mistral checkpoint’s whose vocabulary spells both markers), gpt-oss’s analysis channel, Kimi K3’s think channel, Inkling 2 Mini’s thinking messages and Muse Spark’s messages to itself. There is no flag. Llama, Llama 4, phi-4 and the other Mistral checkpoints have no reasoning mode: their replies, fields and usage are unchanged.
"message": {"role": "assistant", "content": "Paris.", "reasoning": "The user asks for the capital of France."},"usage": {"prompt_tokens": 31, "completion_tokens": 57, "total_tokens": 88, "prompt_tokens_details": {"cached_tokens": 0}, "completion_tokens_details": {"reasoning_tokens": 41}}reasoningis a string, ornullwhen the reply had none (thinking off, or a reply that answered directly). The block’s markers are not part of it, nor the newlines the template writes around it.contentisnullwhen it is empty beside reasoning or tool calls. A reply cut off inside its thinking (max_tokens, a stop string) is all reasoning, withcontent: null.- Tool calls are read from the content only: a call written inside the thinking is not a call.
- Where the prompt leaves the reply decides where it starts: a generation prompt that opens the block (Qwen3.8’s
<think>) starts in the reasoning, one that closes it (enable_thinking: false,reasoning_effort: "none", a forcedtool_choicewithout thinking asked for) starts in the content, and otherwise the model opens a block or answers directly. A stray close marker in the content is dropped. usage.completion_tokens_details.reasoning_tokenscounts the reasoning’s tokens, its markers included, on a checkpoint that reasons;completion_tokenscounts every token, the end of sequence a reply stopped on included (output_tokenson/v1/messagesalike).- A message sent back with its
reasoningrenders it as the template does. The Qwen3, Qwen3.5 and Nemotron 3.5 templates keep it only inside the current tool loop, as does Gemma 4’s while thinking is on; Qwen3.8, GLM-5.3, Ripple-65B, Flint and Mistral 4 keep every turn’s; gpt-oss renders a call turn’s as its analysis message while no final answer follows, and never a final answer’s. - Whether a reply thinks when the request does not say is the shipped template’s default, read at load: Qwen3, Qwen3.8, Nemotron 3.5 and the Qwen3.5 4B and 9B think unless
enable_thinkingis false; the Qwen3.5 0.8B and 2B only when it is true. Gemma 4 and Mistral 4 think only when the request asks. gpt-oss always thinks, atmediumunless the request sets the effort. GLM-5.3-Flash always thinks:lowandhighset its template’s effort level, and every other value keeps its default, Max. Ripple-65B thinks when its reply opens with<think>: its template has no switch, keeps every turn’s reasoning, and a forcedtool_choicenever thinks first. Flint decides the same way, from a template with no switch. Kimi K3 and K3.1 Pro think unless the effort isnoneorenable_thinkingis false, atmaxunless the request asks for less. Inkling 2 Mini thinks athighunless the request sets the effort.
Streaming
With "stream": true the response is text/event-stream. Each data: frame is a chat.completion.chunk: first a delta of {"role": "assistant"}, then reasoning deltas ({"reasoning": "..."}, on a checkpoint that reasons; the first, empty, as the model opens its thinking), then content deltas, then a final chunk carrying finish_reason, then data: [DONE]. With logprobs, every entry arrives on that final chunk as choices[0].logprobs.content (the engine streams text, not token ids); OpenAI’s SDKs accumulate the list across chunks, so the result is the same list a non-streaming reply carries. With include_usage, every chunk carries "usage": null and one more chunk with empty choices and the totals precedes [DONE]. No bytes are sent while the prompt is being prefilled.
Tool calling
Offer tools and read finish_reason: "tool_calls":
"message": { "role": "assistant", "content": null, "tool_calls": [{ "id": "call_...", "type": "function", "function": {"name": "get_weather", "arguments": "{\"city\": \"Paris\"}"} }]}arguments is a JSON string. Text ahead of the first call is returned as content (null when there is none); text between or after calls is not returned. Send each result back as a tool message with the same tool_call_id. On a session, a call echoed with its id and arguments that mean the same renders as the model wrote it, so the returning turn resumes past the call.
When streaming, each call arrives as two chunks: one with id, type, the function name and empty arguments, sent the moment the name reads, then one with the complete arguments string when the call closes, before the finish chunk. A call is never streamed as content. Llama 3’s bare JSON call, Llama 4’s call list and gpt-oss’s call go out when the reply ends.
Qwen3.5, Qwen3.8, Nemotron 3.5, GLM-5.3 and Flint write each argument untyped. A parameter the tool’s schema types as a string (or string or null) comes back as the text the model wrote; any other is read as JSON ({"a": 1} an object, 42 a number, true a boolean). The same holds on /v1/messages and /v1/responses.
tool_choice required or a named function forces a call on every template that calls tools (phi-4’s takes no tools; Muse Spark refuses a forced choice by name): the call’s opening goes into the prompt, so the model’s first token is already the call’s, and the opening counts as prompt tokens. When the request asks for thinking beside it (enable_thinking: true, reasoning_effort medium and up), the model thinks first and the opening goes in when it closes its thinking; the opening is then completion tokens, reported with logprob 0.
- The reply is the call,
finish_reason: "tool_calls"(OpenAI reportsstopfor a named function). requiredmay return several calls unlessparallel_tool_callsisfalse; a named function returns one.requiredwith one tool on offer is that tool, named, though it still allows several calls.- A named tool that is not in
tools, ortoolsempty, is refused. - A forced call the model botches comes back as content beginning with the opening,
finish_reason: "stop", and counts intool_calls_malformed_total. Streamed, one whose name went out ends as that call with{}arguments, and one that named nothing is dropped.
With parallel_tool_calls: false the turn ends where its first call does, and the reply carries that one call (on gpt-oss and Llama 4 the reply is cut to the first call instead).
With a strict: true tool on offer, every call is masked token by token as Structured outputs mask a reply: it names an offered tool, and a strict tool’s arguments are valid against its parameters (a non-strict tool’s are any object). The text around a call stays free. A request may offer up to 512 strict tools. A keyword the call cannot hold is refused with a 400 naming it, as is strict: true on Llama 3, Llama 4, Gemma 4, Mistral Small 3.1 and Muse Spark.
On Qwen3.5, Qwen3.8 and Nemotron 3.5 a string argument holds any text but </parameter>. On GLM-5.3 and Flint an argument holds any text but </arg_value>, which a JSON string inside an array or object argument writes as \u003c/arg_value>.
Structured outputs
response_format holds the reply to JSON:
type |
The reply |
|---|---|
text, or no response_format |
Free text. |
json_object |
One JSON object, any members. |
json_schema |
One JSON value valid against json_schema.schema, enforced whatever strict says. name and description are accepted. No schema is any JSON value. |
"response_format": {"type": "json_schema", "json_schema": {"name": "city", "strict": true, "schema": { "type": "object", "additionalProperties": false, "required": ["name", "population_millions"], "properties": {"name": {"type": "string"}, "population_millions": {"type": "number", "minimum": 0}}}}}Each generated token is masked to the ones that keep the reply a prefix of a valid value, and the turn ends with finish_reason: "stop" the moment the value is complete and nothing may follow it. A reply cut by max_tokens ends with length and is a prefix of a valid value. The JSON is content, streamed as it is written. The layout is the model’s own, compact or indented, with bounded whitespace; properties come in the schema’s order, and numbers have at most 20 integer, 20 fraction and 3 exponent digits. Bytes the schema determines (a property’s name and its :, a , between members, the rest of a chosen enum value) are forced instead of decoded, cost fewer forwards, and report logprob 0. Speculative decoding stays on: a draft is cut at its first token the schema refuses.
- Reasoning: on a checkpoint that thinks, the thinking is free and the format holds from the answer on;
reasoningcomes back as usual. - Tools: with
toolson offer andtool_choiceautothe reply is a call or the JSON. A forcedtool_choiceis a call, not held to the format. - Sessions: a turn’s format is its own and does not carry to the next turn.
- A new schema is compiled before the request queues; the 256 most recent stay compiled.
Honored keywords: type (a name or an array), properties, required, additionalProperties (absent or false: no extra members; true or a schema: extra members), enum, const, anyOf, oneOf (as anyOf), allOf (merged), nullable, $ref into the schema itself (#, #/$defs/..., #/definitions/..., recursion included), items, prefixItems, additionalItems, minItems, maxItems, minLength, maxLength, pattern (matched whole: ECMAScript without backreferences, lookaround, inline flags, \b, \B, \p{...} or \c, repetition counts up to 1000), format (date, time, date-time, duration, email, hostname, ipv4, ipv6, uuid, uri, uri-reference; others are annotations), minimum, maximum, exclusiveMinimum and exclusiveMaximum (draft 4’s boolean form too). Annotations and unknown keywords are ignored. Refused by name with a 400: not, if/then/else, dependentRequired, dependentSchemas, dependencies, patternProperties, propertyNames, contains, minContains, maxContains, multipleOf, maxProperties, minProperties above 0, uniqueItems: true, unevaluatedProperties and unevaluatedItems other than false, dynamic references, a $ref outside the schema, pattern or format beside minLength or maxLength, anyOf beside oneOf, a schema no value satisfies, and one past the compiler’s bounds (deeper than 64 levels, more than 1024 properties in an object or 4096 enum values, minItems/maxItems past 4096 positions, 400,000 automaton states or 2 seconds to compile).
POST /v1/responses
OpenAI’s Responses API over the same engine: input and output are lists of typed items, a stored response is continued by its id, and the stream sends semantic events. The official OpenAI SDKs work against it unmodified.
curl http://127.0.0.1:8080/v1/responses \ -H "Content-Type: application/json" \ -d '{"instructions": "Be brief.", "input": "Why is the sky blue?", "max_output_tokens": 200}'Request
| Field | Default | Notes |
|---|---|---|
input |
required, unless previous_response_id is sent |
A string (one user message) or an array of items (see Input items). |
instructions |
none | The system message. It is not carried over from a previous response: each request sends its own. |
previous_response_id |
none | Continue a stored response: its conversation, then this request’s input (see Stored responses). |
store |
true |
Keep the response for previous_response_id, GET and input_items. false keeps nothing. |
stream |
false |
See Streaming events. |
max_output_tokens |
none | Reasoning and text alike. Left out, the reply runs until it stops or the context is full. |
temperature, top_p |
the checkpoint’s generation_config.json, else 1.0 |
|
tools |
none | Every tool kind a client runs: function, custom, namespace, shell, apply_patch, local_shell and a client-run tool_search (see Tools). Web search is accepted and not run; the other hosted tools are refused by name. |
tool_choice |
auto |
auto, none, required, {"type": "function", "name"}, {"type": "custom", "name"}, {"type": "shell"}, {"type": "apply_patch"}, or {"type": "allowed_tools", "mode": "auto" or "required", "tools": [...]}, which offers only the tools it lists. required and a named tool open the call in the prompt, as on /v1/chat/completions, and a named tool is one call (a namespace member is named by its own name or its flat one). A choice that names a hosted tool, or a required that leaves no tool the model can call, is refused: tool_choice requires a function call, but tools contains no function tool the model can call. |
parallel_tool_calls |
true |
false: at most one call this turn. |
text |
{"format": {"type": "text"}} |
format is text, json_object or {"type": "json_schema", "name", "schema", "strict", "description"}, held as response_format is on /v1/chat/completions (see Structured outputs); the schema is enforced whatever strict says, and description is echoed, not shown to the model. verbosity is accepted, any value, without effect: the model writes at its own length, and the response echoes medium. |
reasoning |
none | effort: none, minimal, low (no thinking) or medium, high, xhigh, max (thinking), for templates that render a reasoning setting; left out, the template’s default. summary (or the deprecated generate_summary): any kind but none asks for one (see Reasoning items). context, mode and any other key are accepted without effect: which earlier reasoning a turn renders is the chat template’s own rule. |
include |
none | reasoning.encrypted_content and message.output_text.logprobs do what they say; every other value (output.encrypted_content, message.input_image.image_url, the hosted tools’ entries) is accepted without effect. |
top_logprobs |
0 | 0 to 20. The text’s logprobs come with include: ["message.output_text.logprobs"] or a top_logprobs above 0. |
metadata |
{} |
Up to 16 string pairs (keys of at most 64 characters, values of at most 512), kept with the response. |
top_k, seed |
as on /v1/chat/completions |
This server’s sampling controls. |
model is accepted and ignored; the response carries the server’s model name. The session header works as on /v1/chat/completions, a turn continued by previous_response_id included.
POST /v1/responses/compact (server-side compaction) is refused by name with a 400.
Request fields
Every field the popular agent clients send is taken: Codex’s client_metadata, prompt_cache_key, service_tier and text.verbosity on every request, Copilot’s truncation and context_management, the AI SDK’s prompt cache options. A field is used, accepted without effect where it only steers billing, caching, telemetry, routing or presentation (as the reference servers accept it), or refused by name where ignoring it would silently change the answer. Refusals come in OpenAI’s envelope with param and code.
| Field | Here | Why |
|---|---|---|
client_metadata, user, safety_identifier, metadata |
accepted; all but client_metadata echoed |
Telemetry and abuse tracking, which a self-hosted server has no use for. |
prompt_cache_key |
accepted, echoed | The prefix cache is one, shared and keyed by content: a request whose prompt opens as an earlier one did reuses its pages, with or without a key, so there is no machine to route the key to. |
prompt_cache_retention, prompt_cache_options |
accepted (prompt_cache_retention echoed) |
Cached pages stay until memory needs them. |
service_tier |
any value accepted; the response says default |
There is one tier. |
truncation |
auto runs as disabled; the response says disabled |
A conversation past the context is refused with context_length_exceeded (streamed, a response.failed with that code). The agents compact their history at thresholds of their own; Codex ends the turn on the error and, for a model it does not know, assumes a 272,000-token window, so give it the server’s context as model_context_window in its config.toml. |
context_management |
accepted | No server-side compaction: the clients compact on their own. |
max_tool_calls |
accepted, echoed | It caps hosted tool calls, and none run here. |
stream_options |
include_obfuscation and reasoning_summary_delivery accepted |
No obfuscation field is ever sent; a summary comes as its own events either way. |
text.verbosity, reasoning.context, reasoning.mode, other include values |
accepted | Presentation and caching choices of OpenAI’s own models. |
| any field the reference does not define | ignored, named in a debug line (--layerscale-debug-log) |
As the reference servers ignore them. |
background: true |
refused | Every response runs while its request waits; stream: true reads it as it is written. |
conversation |
refused | The Conversations API: continue a conversation with previous_response_id. |
prompt |
refused | Stored prompt templates: send the instructions and input themselves. |
personality, and moderation and access_programs unless null |
refused | Each would change the answer, ignored. |
response_format |
refused | The Chat Completions spelling: the format is text.format here. |
an input_file part |
refused | Nothing here reads files. |
a previous_response_id or item_reference this server does not hold |
400, code previous_response_not_found |
The code a client sends its whole history again on. |
Tools
Each tool kind a client runs is offered to the model as a function in the chat template’s own tool format (the shims the reference servers use), under one name, and the model’s call to that name comes back as the kind’s own output item: one rendered call is one item both ways, so a history renders again byte for byte and the prefix cache serves it.
| Tool | Offered to the model as | A call comes back as | Its stream | Its output comes back as |
|---|---|---|---|---|
function |
itself | function_call |
response.function_call_arguments.delta, .done |
function_call_output |
custom |
a function of its name with one string parameter, input; a grammar format’s syntax and definition follow the description: The payload must conform to this <syntax> grammar: and the definition |
custom_tool_call, input the payload as the model wrote it (JSON-unescaped where the template’s calls are JSON, the raw parameter text on the XML of Qwen3.5, Qwen3.8 and Nemotron 3.5 and in GLM-5.3’s and Flint’s <arg_value>; bare text taken as it is) |
response.custom_tool_call_input.delta, .done |
custom_tool_call_output |
namespace |
each function and custom member as <namespace>__<name> (Codex’s MCP servers, mcp__server, give mcp__server__tool) |
its member’s kind, name the member’s own and namespace beside it |
its member’s kind’s | its member’s kind’s |
shell, environment local or none |
shell, commands, timeout_ms and max_output_length, described; a local environment’s skills are listed in the description |
shell_call: action (commands, timeout_ms, max_output_length) and environment {"type": "local"} |
response.shell_call_command.added, .delta, .done per command |
shell_call_output, its output entries as the JSON they are |
apply_patch |
apply_patch, type (create_file, update_file, delete_file), path and diff, the description explaining V4A diffs |
apply_patch_call: operation (type, path, and diff but for delete_file) |
the item opens when the call closes, its operation’s type and path with it, then response.apply_patch_call_operation_diff.delta, .done |
apply_patch_call_output, its status and output as JSON |
local_shell |
local_shell, command (an argv list), working_directory, timeout_ms, env |
local_shell_call: action {"type": "exec", "command", "env"} with working_directory and timeout_ms where the model gave them |
its item’s added and done | local_shell_call_output, naming its call by call_id or, as the reference’s own type does, by id |
tool_search, execution client |
tool_search, the client’s description and parameters (else a query) |
tool_search_call, execution client and the arguments object |
its item’s added and done | tool_search_output: the tool definitions it carries render in that tool turn, one a line in the template’s tool notation, and join the prompt’s tool list from then on |
A call reads its arguments leniently: a shell call’s single command string is a list of one, a local_shell command string runs through bash -lc, an apply_patch operation nested under operation or a type spelled create or delete reads as its kind. Item ids follow the kind (fc_, ctc_, shc_, apc_, lsc_, tsc_) and call ids are call_.... Only the last item of a cut reply is not completed; an apply_patch_call, whose type has no incomplete, stays in_progress.
A custom tool’s grammar is described to the model, not enforced: a call’s payload sits inside the call envelope the template writes, where no constraint scoped to one parameter’s span exists, and the engine compiles JSON schemas and their patterns, not Lark.
A function tool’s strict holds its calls as on /v1/chat/completions, async is accepted (the call is an ordinary one), output_schema is accepted and not shown, and allowed_callers must include direct. defer_loading: true beside a client tool_search keeps a tool out of the prompt’s tool list until a tool_search_output loads it; without one, the tool is offered up front. The list sits at the prompt’s start, so the turn after a search that loads new tools renders its prompt afresh, once. Two tools under one name are refused.
web_search and web_search_preview (and their dated names), which Codex offers on every request, are accepted and not run: echoed in the response’s tools, never offered to the model, named in a debug line. The engine has no hosted tools. The other hosted tools are refused by name: file_search, code_interpreter, computer, computer_use_preview, image_generation, remote mcp, programmatic_tool_calling, a tool_search the server would run, and a shell in a container. None of the popular clients sends them by default.
Input items
| Item | Notes |
|---|---|
message |
role user, system, developer or assistant (type may be left out). content is a string or an array of parts: input_text, input_image (image_url as a data: URL, on a checkpoint with a vision tower; detail is low, high, auto or original, kept as sent and auto when left out, and the image is read at its own size whatever it says, as on /v1/chat/completions) and input_audio (on a checkpoint with an audio tower); an assistant’s output_text and refusal. phase is accepted and kept. |
function_call |
call_id, name, arguments (a JSON string), as the response gave them; with its namespace, it renders under the flat name. |
custom_tool_call, shell_call, apply_patch_call, local_shell_call, tool_search_call |
As the response gave them: each renders as the call to its shim (a custom tool’s input as {"input": ...}), as the model wrote it. |
function_call_output, custom_tool_call_output |
call_id and output, a string or an array of input_text and input_image parts. The images a tool returned (Codex’s view_image) render in a user turn after the run of tool results, on a checkpoint with a vision tower. |
shell_call_output, apply_patch_call_output, local_shell_call_output, tool_search_output |
See Tools. |
item_reference |
{"type": "item_reference", "id"}, or an item that is only an id: an output item of a response this server keeps (the AI SDK sends its earlier assistant messages, reasoning items and tool calls this way under store), copied in its place, so the response keeps the item itself. One no kept response holds is refused with previous_response_not_found. |
reasoning |
Its content (reasoning_text parts), else what its encrypted_content carries, else its summary, renders as the template renders a past turn’s reasoning. |
Refused by name: an input_file part, an image by file_id or by a remote URL, an encrypted_content this server did not produce, and every hosted tool’s item (web_search_call, file_search_call, computer_call, code_interpreter_call, image_generation_call, mcp_*, compaction and the rest).
The items render through the model’s chat template as /v1/chat/completions renders the same conversation. instructions and the system and developer messages that open the items are one system message, joined by a blank line; a later system or developer message is its own turn (a user turn of the same text on templates that render none there: Qwen3.5, Qwen3.8, Mistral). A run of reasoning, assistant message and call items is one assistant turn: its reasoning, its text, then its calls. Every call needs its output after it, and every output its call, as OpenAI requires.
Response
{ "id": "resp_...", "object": "response", "created_at": 1761480000, "status": "completed", "background": false, "completed_at": 1761480001, "error": null, "incomplete_details": null, "instructions": "Be brief.", "max_output_tokens": 200, "model": "nvidia-nemotron-3.5-super-vl-120b-a12b-nvfp4", "output": [ {"id": "rs_...", "type": "reasoning", "summary": [], "content": [{"type": "reasoning_text", "text": "..."}], "encrypted_content": null, "status": "completed"}, {"id": "msg_...", "type": "message", "status": "completed", "role": "assistant", "content": [{"type": "output_text", "text": "...", "annotations": [], "logprobs": []}]} ], "parallel_tool_calls": true, "previous_response_id": null, "reasoning": {"effort": null, "summary": null}, "service_tier": "default", "store": true, "temperature": 0.6, "text": {"format": {"type": "text"}, "verbosity": "medium"}, "tool_choice": "auto", "tools": [], "top_logprobs": 0, "top_p": 0.95, "truncation": "disabled", "usage": {"input_tokens": 31, "input_tokens_details": {"cached_tokens": 0, "cache_write_tokens": 0}, "output_tokens": 57, "output_tokens_details": {"reasoning_tokens": 41}, "total_tokens": 88}, "user": null, "metadata": {}}The response echoes its request’s parameters, temperature and top_p as the reply ran with them. status is completed, incomplete with incomplete_details.reason max_output_tokens when the budget or the context cut the reply, or failed with error (code server_error) when the engine failed mid-stream. output holds, in order, a reasoning item when the reply reasoned, a message when it wrote text (an empty one when it wrote nothing), and an item per call, of its tool’s kind (see Tools). As on /v1/chat/completions, text between or after calls is not returned, and a call cut by max_output_tokens is its item marked incomplete. usage.input_tokens_details.cached_tokens counts the prompt tokens served from cache, prefix-cache pages and session KV alike; cache_write_tokens is always 0. output_text.logprobs, when asked for, has the shape of /v1/chat/completions’ logprobs.content.
Reasoning items
On a checkpoint that reasons (see Reasoning) the reasoning comes back whole as a reasoning item’s content. There is no summarizer: with reasoning.summary asked for, summary carries the same text as one summary_text part, with the summary’s stream events beside the reasoning text’s. With include: ["reasoning.encrypted_content"] the item carries encrypted_content, which a client that keeps the conversation itself (store: false) sends back in place of the text: lsr1. and the reasoning in base64, an encoding rather than a cipher, so it survives a restart. One this server did not produce is refused by name. Sent back, a reasoning item renders as the template renders a past turn’s reasoning.
Streaming events
With "stream": true the response is text/event-stream, each frame an event: line and a data: object whose type names it and whose sequence_number counts from 0: response.created and response.in_progress, then per output item response.output_item.added, response.content_part.added (and response.reasoning_summary_part.added for a summary), the deltas (response.reasoning_text.delta, response.reasoning_summary_text.delta, response.output_text.delta, and each call kind’s own, see Tools), their .done with the whole text, the part’s .done and response.output_item.done; last response.completed, response.incomplete or response.failed with the whole response. There is no [DONE]. Items open one at a time, in output_index order. The reasoning item is added the moment the model opens its thinking; a call’s item is added, empty, the moment its name reads (an apply_patch_call when it closes), and its payload follows in one delta when it closes. Logprobs ride response.output_text.done and the final response. A refusal before the first token is an HTTP error, except a prompt past the context: that stream opens and fails at once (response.created, response.in_progress, an error event and response.failed, with code context_length_exceeded), as OpenAI’s stream reports it and as Codex reads it to compact its conversation. An engine error after the first token closes the open item incomplete, then sends an error event (code server_error) and response.failed with the output so far.
Stored responses
A response with store: true (the default) is kept, with its input items, for previous_response_id. A continued request renders the stored conversation and then its own input exactly as the whole history sent at once renders, so it answers the same, and the prefix cache serves the earlier turns’ pages (cached_tokens counts them). The server keeps at most 16,384 responses and 512 MiB of them, evicting the least recently used; a kept response holds its whole conversation, so it continues even after an earlier one was evicted or deleted. A previous_response_id that is not kept is refused with 400, code previous_response_not_found, and the client can send the whole history instead. A streamed response is kept from response.created on: while it streams, GET answers it in_progress and a previous_response_id naming it is refused (still in progress). Responses live in the server’s memory: a restart forgets them.
| Method | Path | Answers |
|---|---|---|
GET |
/v1/responses/{id} |
The response as it was served. include[]=reasoning.encrypted_content adds the reasoning’s encrypted_content; stream=true is refused (it replays a background response). |
DELETE |
/v1/responses/{id} |
{"id", "object": "response.deleted", "deleted": true}. |
GET |
/v1/responses/{id}/input_items |
{"object": "list", "data", "first_id", "last_id", "has_more"}: the items the response was generated from, its conversation’s earlier items included, newest first unless order=asc, limit (1 to 100, 20 by default) at a time after the item after names. |
POST |
/v1/responses/{id}/cancel |
400: only a background response can be cancelled, and none runs here. |
An id that is not kept answers 404, Response with id '...' not found.
WebSocket mode
responses.connect() in the OpenAI SDKs opens a WebSocket on /v1/responses (the key on the handshake under --api-key) for up to 60 minutes. Each {"type": "response.create", ...} message carries a POST /v1/responses body and gets back the streaming events as JSON text frames; a refusal is an error event with its HTTP status. A stream_id names a lane: a lane runs its requests in order, lanes run side by side (up to 16 responses at once, 32 named lanes), and a named lane’s events carry its stream_id. Continue with previous_response_id and only the new input, under store: false too: the connection keeps each lane’s latest response. "generate": false prefills the input and answers a response with no output, to continue from.
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="KEY")with client.responses.connect() as connection: connection.response.create(model="local", input="Why is the sky blue?", store=False) for event in connection: if event.type == "response.completed": print(event.response.output_text) breakPOST /v1/responses/input_tokens
{"object": "response.input_tokens", "input_tokens": N}: the prompt a /v1/responses request with the same body renders to, a stored conversation included, counted on the tokenizer without generating.
POST /v1/messages
The Anthropic Messages API over the same engine.
curl http://127.0.0.1:8080/v1/messages \ -H "Content-Type: application/json" \ -d '{ "system": "Be brief.", "messages": [{"role": "user", "content": "Why is the sky blue?"}], "max_tokens": 200 }'Request
| Field | Default | Notes |
|---|---|---|
messages |
required | Roles user, assistant and system. content is a string or an array of blocks: text, image (a base64 source, on a checkpoint with a vision tower) and tool_result in user messages; text, tool_use, thinking and redacted_thinking in assistant messages; text in system messages. A tool_result’s content is a string or text, image and tool_reference blocks: its images render in a user turn after the tool results, and a tool_reference renders a deferred tool’s definition, or the name of a tool already on offer. A system message before any turn joins the system prompt; a later one renders where it stands, as a user turn on templates without a later system turn (Qwen3.5, Qwen3.8, Mistral). An assistant message’s thinking blocks join into its reasoning; their signatures are not checked, except that an empty block under display: omitted reads as the thinking its signature carries. A redacted_thinking block is accepted and dropped. |
system |
none | A string or an array of text blocks. |
max_tokens |
required | |
temperature |
the checkpoint’s generation_config.json, else 1.0 |
|
top_p |
the checkpoint’s generation_config.json, else 1.0 |
|
top_k |
the checkpoint’s generation_config.json, else none |
As on /v1/chat/completions. |
seed |
none | |
stop_sequences |
none | An array of strings. |
stream |
false |
|
tools |
none | {"name", "description", "input_schema"}, type left out or custom. A tool with defer_loading: true stays out of the system prompt until a tool_reference names it, so the prompt before the search, and the cache over it, stays the same as tools load (Claude Code defers its MCP tools behind its ToolSearch tool); strict: true holds a call’s input to input_schema as on /v1/chat/completions, and cache_control is accepted without effect. A typed tool is one of Anthropic’s own, refused by name (tools.N: tool type '...' is not supported): its server tools (web_search_20250305, which Claude Code’s WebSearch sends, so that tool fails cleanly instead of answering from the model’s memory; code execution; the advisor) run on Anthropic’s side, and its built-in client tools’ schemas are its own. |
tool_choice |
{"type": "auto"} |
auto, none, any, or {"type": "tool", "name": ...}. any and a named tool open the call in the prompt, as required and a named function do on /v1/chat/completions, on every template that calls tools, and stop_reason is tool_use; a named tool is one call. "disable_parallel_tool_use": true beside the type asks for at most one tool call: the turn ends where the call does, one decode step sooner. |
ignore_eos |
false |
|
skip_special_tokens |
true |
As on /v1/chat/completions. |
thinking |
none | {"type": "enabled", "budget_tokens": N} (N an integer of at least 1024), {"type": "adaptive"} or {"type": "disabled"}, for templates that render a reasoning setting: enabled and adaptive think, disabled does not, as reasoning_effort and enable_thinking set it on /v1/chat/completions. The model’s thinking budget is not enforced. display is summarized (the default) or omitted, which sends the thinking block with empty text. Any other type or key is refused. |
output_config |
none | effort: low (no thinking) or medium, high, xhigh, max (thinking). It decides over thinking enabled or adaptive; thinking disabled stays off whatever the effort. format: {"type": "json_schema", "schema": {...}} holds the reply’s text to the schema as response_format does on /v1/chat/completions (see Structured outputs); the deprecated top-level output_format of the same shape is accepted, not both. Any other key (Claude Code’s task_budget) is accepted without effect. |
metadata |
Accepted and ignored. |
With neither thinking nor output_config.effort the template’s default applies, as on /v1/chat/completions without reasoning_effort. On a checkpoint that reasons (see Reasoning) the thinking comes back as a thinking block ahead of the text and the calls. A forced tool_choice (any or a named tool) runs without thinking, and thinking turned on beside one is refused, as the Messages API refuses it. The session header works as on /v1/chat/completions. An audio block carries a clip as an image block carries a picture (a base64 source, audio/wav or audio/mpeg) to a checkpoint with an audio encoder; an input_audio block, a video block and the modalities and audio fields are refused by name. A document block, and an image to a checkpoint without a vision tower, are refused with exactly capability_rejected: document_block and capability_rejected: image_block, on which Claude Code sends the request again without them.
Response
{ "id": "msg_...", "type": "message", "role": "assistant", "model": "nvidia-nemotron-3.5-super-vl-120b-a12b-nvfp4", "content": [{"type": "text", "text": "..."}], "stop_reason": "end_turn", "stop_sequence": null, "usage": {"input_tokens": 31, "cache_creation_input_tokens": 0, "cache_read_input_tokens": 0, "output_tokens": 57}}stop_reason is end_turn, max_tokens, stop_sequence, tool_use, or model_context_window_exceeded when the context filled before max_tokens was reached. A reply that reasons opens with {"type": "thinking", "thinking": "...", "signature": "..."}; a client keeps the signature with the block and sends it back. Under display: omitted the signature carries the block’s thinking, encrypted for this deployment; any other signature reads as no thinking, never as an error. A reply cut off inside its thinking is that block alone, with stop_reason: max_tokens. A tool call is a tool_use block with id, name and input (the arguments as the model wrote them when they are valid JSON, so a 19-digit id stays exact). On a session, a tool_use block echoed back with its id and an input that means the same resumes past the call (see Sessions). usage.cache_read_input_tokens counts the prompt tokens served from cache, session KV and prefix-cache pages alike, and input_tokens the rest, so the two add up to the prompt’s length; cache_creation_input_tokens is always 0. usage.prefix_cached_tokens, present only when nonzero, is the prefix cache’s part. The stream’s message_start carries the whole prompt as input_tokens; the closing message_delta carries the final figures.
Streaming
Named SSE events in Anthropic’s order: message_start, a ping, content_block_start, content_block_delta (thinking_delta and signature_delta for thinking, text_delta for text, input_json_delta for tool arguments), content_block_stop, message_delta with the stop reason and usage, message_stop. The thinking block comes first, started as the model opens its thinking: its thinking_deltas as the model writes them (none under display: omitted), then one signature_delta and its stop. Text comes only ahead of the calls, in its own block; each tool_use block is its start, sent when the name reads, then one input_json_delta with the whole arguments and its stop when the call closes. message_start goes out with the first generated token; an engine error before it is an HTTP error (see Errors), and one after it is an error event.
Message threads
"thread": {"type": "create"} keeps the conversation (its system, tools, messages and the reply) under the response’s id; "thread": {"type": "continue", "previous_message_id": "msg_..."} then sends only the messages after that response, without system or tools. Every request of a thread sends the header anthropic-beta: message-threads-2026-08-12. A thread runs on a session held behind the scenes, so a continue prefills only its new messages (cache_read_input_tokens counts the rest) and answers what the whole conversation sent at once answers; the thread also holds the conversation, so a continue never depends on that KV still being there. The thread helper of Anthropic’s SDKs works unchanged:
import anthropic
client = anthropic.Anthropic(base_url="http://127.0.0.1:8080", api_key="KEY")thread = client.beta.messages.thread(model="local", max_tokens=1024, system="Be brief.")thread.send({"role": "user", "content": "Why is the sky blue?"})second = thread.send({"role": "user", "content": "And at sunset?"})Each response id can be continued once, within five minutes of its response; a streamed one is kept by the time message_stop goes out. model, tool_choice, thinking, output_config, the top-level cache_control, context_management, mcp_servers, container.skills, fallbacks and the set of anthropic-beta values go on every request of a thread as its create request sent them; the other fields may change from turn to turn. A request carries at most four cache_control breakpoints, its system’s and tools’ counted on every turn. Errors name their cause in error.details.error_code:
| Status | error_code |
When |
|---|---|---|
| 404 | thread_not_found |
The id is unknown, expired or still generating: send the whole conversation in a new create request |
| 400 | thread_fingerprint_mismatch |
A fixed field differs from the create request’s; the message names it |
| 400 | thread_already_continued |
The id was continued already |
| 400 | thread_continue_in_flight |
Another continue from the id is running |
| 400 | thread_unsupported_request |
Over four breakpoints, compaction, or context editing other than clear_thinking_20251015 with keep: "all"; error.details.unsupported names it |
Token counting and batches refuse thread. Threads live in the server’s memory: a restart forgets them.
POST /v1/messages/count_tokens
The number of prompt tokens a /v1/messages request with the same body would run with: the system prompt, the messages, the tools, a forced tool_choice’s opening, image placeholders and the thinking setting. max_tokens and the sampling fields are not needed and are ignored; the session header is ignored too, and the count is the whole rendered prompt. Counting runs on the tokenizer only, so it never waits on generation. A body /v1/messages would refuse is refused the same way, in Anthropic’s envelope.
curl http://127.0.0.1:8080/v1/messages/count_tokens \ -H "Content-Type: application/json" \ -d '{"messages": [{"role": "user", "content": "Why is the sky blue?"}]}'{"input_tokens": 14}Batches
A batch runs many requests in the background through the same routes, a quarter of the engine’s sequences at a time across all batches, so interactive requests keep the rest. Files, batches and results live in the server’s memory, and a restart forgets them.
OpenAI: upload a JSONL file of {"custom_id", "method": "POST", "url", "body"} lines to /v1/files with purpose batch, create a batch on /v1/chat/completions or /v1/responses with completion_window 24h, poll it until completed, then download output_file_id (and error_file_id, for requests that failed) from /v1/files/{id}/content.
curl http://127.0.0.1:8080/v1/files \ -F purpose=batch -F file=@requests.jsonlcurl http://127.0.0.1:8080/v1/batches \ -H "Content-Type: application/json" \ -d '{"input_file_id": "file-...", "endpoint": "/v1/chat/completions", "completion_window": "24h"}'Anthropic: send the requests inline, poll until processing_status is ended, then read results_url.
curl http://127.0.0.1:8080/v1/messages/batches \ -H "Content-Type: application/json" \ -d '{"requests": [{"custom_id": "q1", "params": {"max_tokens": 200, "messages": [{"role": "user", "content": "Why is the sky blue?"}]}}]}'GET /v1/models
curl http://127.0.0.1:8080/v1/models{ "object": "list", "data": [{ "id": "nvidia-nemotron-3.5-super-vl-120b-a12b-nvfp4", "object": "model", "created": 1757000000, "owned_by": "local", "max_model_len": 1048576, "type": "model", "display_name": "nvidia-nemotron-3.5-super-vl-120b-a12b-nvfp4", "created_at": "2025-09-04T15:33:20Z", "max_input_tokens": 1048575, "max_tokens": 1048575, "lifecycle": "active", "capabilities": null, "deprecated_at": null, "retires_at": null, "line": null }], "has_more": false, "first_id": "nvidia-nemotron-3.5-super-vl-120b-a12b-nvfp4", "last_id": "nvidia-nemotron-3.5-super-vl-120b-a12b-nvfp4"}The list and its entry carry the fields of both APIs at once, so an OpenAI client and an Anthropic client each read their own: object, created and owned_by for the first, type, display_name, created_at, lifecycle (always active) and the paging fields has_more, first_id and last_id for the second. capabilities, deprecated_at, retires_at and line describe Anthropic’s own models and are null. after_id, before_id, limit and lifecycle[] are ignored, as there is one model.
max_model_len is the longest sequence, prompt plus completion, the server admits: the model’s context after --ctx and the KV pool have each capped it. A prompt of that many tokens or more answers 400, and a completion that reaches it ends with finish reason length (stop reason model_context_window_exceeded on /v1/messages), so a client can size its own context window, and decide when to compact a conversation, from this field. max_input_tokens is the longest prompt admitted, one token less, and max_tokens the same figure, the most a reply could have room for.
GET /v1/models/{id} returns the same entry when id matches the model name (case-insensitive) and 404 otherwise, in Anthropic’s envelope (not_found_error) for a request that sent anthropic-version. There is exactly one model per server.
GET /health
No key needed. 200 while the engine is stepping or idle, 503 when the engine thread has stopped or stalled. /healthz is an alias. The body is the same either way; status is ok or unavailable:
{ "status": "ok", "uptime_ms": 120345, "queued": 0, "queued_oldest_seconds": 0, "running": 2, "kv_pages_total": 4096, "kv_pages_free": 3900, "connections": 3, "steps": 15020, "preemptions": 0, "requests_started": 41, "requests_ok": 39, "requests_failed": 0, "requests_cancelled": 0, "prompt_tokens": 12034, "generated_tokens": 8871, "sessions": 1, "session_turns": 6, "prefix_cached_tokens": 9021, "session_cached_tokens": 5040, "session_snapshot_evictions": 0, "session_ingested_tokens": 1200, "session_warm_turns": 2, "session_warmed_tokens": 640, "session_flash_hits": 3, "session_ready_exits": 1, "tool_calls_malformed": 0, "tool_calls_recovered": 0, "tool_calls_jump_forward": 12, "tool_calls_forced_tokens": 138, "session_call_turns_exact": 4, "session_call_turns_diverged": 0}Every field after uptime_ms mirrors a /metrics counter (without the _total suffix) or gauge of the same name. step_tokens, the three speculative_* counters and connections_rejected are on /metrics only, as are the histograms.
GET /metrics
Prometheus text; the key is required. Every metric is prefixed layerscale_, and every sample carries the same two constant labels: model_name (the model directory’s name, lowercased) and backend (cuda, rocm or cpu).
Counters: requests_started_total, requests_ok_total, requests_failed_total, requests_cancelled_total, prompt_tokens_total, generated_tokens_total, steps_total, step_tokens_total, forward_microseconds_total and outside_forward_microseconds_total (engine-thread time inside forward steps, and between them while requests ran: the host’s cost a step), speculative_accepted_total, speculative_drafts_total, speculative_draft_tokens_total, preemptions_total, graph_captures_total (decode graphs captured), connections_rejected_total, session_turns_total, prefix_cached_tokens_total, prefix_window_miss_tokens_total (prompt tokens run again on a model with sliding-window layers because the window before a cached prefix’s end had been evicted), session_cached_tokens_total, session_snapshot_evictions_total (idle sessions on a model with recurrent layers whose saved state, or a /generate question’s copy of it, was given to a running request; their next turn prefilled in full), session_ingested_tokens_total, session_warm_turns_total, session_warmed_tokens_total, session_flash_hits_total, session_ready_exits_total, tool_calls_malformed_total, tool_calls_recovered_total, tool_calls_jump_forward_total, tool_calls_forced_tokens_total (the tokens those runs carried), structured_requests_total, structured_forced_runs_total and structured_forced_tokens_total (schema-determined runs forced instead of decoded, and their tokens), structured_refused_tokens_total (tokens a structured reply’s constraint refused; 0 unless something is broken), session_call_turns_exact_total and session_call_turns_diverged_total (session turns returning from a tool call whose prompt re-rendered the call exactly, or diverged inside it and prefilled it again).
Gauges: queued (sequences waiting: in the queue, or admitted to the batch and holding no KV room yet), queued_oldest_seconds (seconds since the request waiting longest was submitted; 0 with none waiting), running (sequences holding KV room: prefilling or decoding), kv_pages_total, kv_pages_free, connections, sessions, ready, speculative_acceptance_length (tokens a verify forward produced on average over the server’s life, the model’s own token included: (speculative_accepted_total + speculative_drafts_total) / speculative_drafts_total, the number --synthetic-acceptance-length pins), speculative_acceptance_rate (speculative_accepted_total / speculative_draft_tokens_total, 0..1). Both are derived from the counters at scrape time and read 0 before the first verify.
curl http://127.0.0.1:8080/metricsHistograms
| Metric | Buckets | One observation per |
|---|---|---|
time_to_first_token_seconds |
1 ms to 10 s | model-served request, from its first generated token |
inter_token_latency_seconds |
10 ms to 2.5 s | model-served request of two or more tokens |
e2e_request_latency_seconds |
0.3 s to 8 min | model-served request |
request_decode_time_seconds |
0.3 s to 8 min | model-served request of one or more tokens |
request_prompt_tokens |
1 to 50,000 tokens | model-served request |
request_generation_tokens |
1 to 50,000 tokens | model-served request |
iteration_tokens |
1 to 16,384 tokens | forward step |
Each exposes _bucket{le="..."} (cumulative, +Inf last), _sum and _count. The latency buckets and sums are seconds; the token ones are raw counts. A request that errored or was cancelled is counted by how it ended and never timed, and so is one the session caches answered without the model (the flash and speculative finish reasons, session_flash_hits_total and session_ready_exits_total). TTFT is taken at the first generated token whether or not it has streamed out yet, so a reply held back whole for tool-call detection is timed from the token.
Labelled counters
requests_finished_total{finish_reason} is the exclusive breakdown of concluded requests: every one lands in exactly one of stop, length, tool_calls, cancelled, error, flash (answered from a session’s flash cache), speculative (the ready-position exit) and other.
request_errors_total{error_kind} counts the requests answered with an error status, by class (never by the caller’s message, so the label set is bounded):
error_kind |
Status |
|---|---|
validation |
400, and any other 4xx not named here |
auth |
401, 403 |
not_found |
404, 405 |
conflict |
409 |
timeout |
408, 504 |
overload |
429, 503 |
internal |
5xx other than 503 and 504 |
Reading them
inter_token_latency_secondsis a per-request mean,(e2e - ttft) / (completion_tokens - 1), observed once when the request completes. Its p99 is therefore a tail of request means, not of tokens.requests_ok_totalincludes cancelled requests: a cancelled request finishes with what it had. Sorequests_cancelled_totalis a subset of it,ok + failedis every concluded request, andrequests_finished_total{finish_reason}is the exclusive split.- Queue time and prefill time are not exposed separately. The engine records no admission timestamp, and adding one would put a clock read in the step loop.
time_to_first_token_secondscovers queueing and prefill together;request_decode_time_secondscovers the rest of the request. - Speculation has two rates: acceptance is
speculative_accepted_total / speculative_draft_tokens_total(thespeculative_acceptance_rategauge), and how often speculation fires at all isspeculative_drafts_total / steps_total. Thespeculative_acceptance_lengthgauge is the tokens a verify forward produced on average, the model’s own token included.
layerscale_build_info
Always 1; everything is in its labels, which are the two constant labels followed by:
| Label | Value |
|---|---|
version |
The crate version |
git_sha |
The commit, twelve hex digits: LS_GIT_SHA from the build environment (CI passes the pipeline’s), else what git said about HEAD when the build script last ran, else unknown |
kv_cache_dtype |
bfloat16 or fp8_e4m3 |
ctx |
Context length in tokens |
max_seqs |
Sequences in the running batch |
kv_pages, page_size |
The KV pool’s size and page |
chunked_prefill_size, step_tokens |
The scheduler’s prefill chunk and the widest per-step token budget |
tp |
Tensor-parallel GPUs |
speculation, prefix_cache |
true or false |
Join on it to break a dashboard down by build or by configuration.
CORS
Every response carries Access-Control-Allow-Origin: *. A preflight OPTIONS answers 204 on any path, allowing GET, POST and OPTIONS with the Content-Type, Authorization and x-layerscale-session-id headers, and needs no key. DELETE and the x-api-key header are not in that list, so the session delete routes and key-as-x-api-key are for same-origin or non-browser callers.
Limits
| Limit | Value | When exceeded |
|---|---|---|
| Request body | 1088 MiB | 413 |
| Request headers | 64 KiB | 431 |
| Time for a request to arrive in full | 60 s | 408 |
| Request bodies, their parsed JSON and picture work held across all connections | a quarter of the host’s memory | the next body waits to be read; one already arriving gets 503 |
| Messages waiting for a WebSocket client that is not reading | 64 | the server stops reading from that client until it catches up |
| Socket read or write | 30 s | connection closed |
stop sequences |
4, each at most 64 bytes | 400 |
| WebSocket frame | 16 MiB | connection closed |
There is no fixed connection cap; each connection is a thread and the host’s limits apply. A prompt that reaches the context length is refused with 400 in each surface’s wording (see Errors). A request whose client disconnects is cancelled wherever it is (queued, prefilling or decoding, streamed or not), and its KV pages and state go back at the next step.