The OpenAI-compatible HTTP server¶
Each rank runs one C++ HTTP server (csrc/server/http_server.cpp). It tokenizes the request,
renders the chat template, hands the tokens to the C++ serve loop and streams the text back.
Parsing, tokenizing, templating, scheduling and detokenizing run in C++; the forward pass on the
GPU is run by the rank's Python model runner, which the serve loop calls once per step
(forward_ at csrc/server/serve_loop.cpp:2035). This page lists the routes, the request fields the server reads
and the ones it ignores, the response shapes and the status codes. It describes the code as it is
at this commit.
Where qix-serve starts several copies, tnd-node-router listens on the public port and forwards
each request to one copy. The router serves five of the routes below: /health, /metrics,
/v1/models, /v1/chat/completions and /v1/completions (csrc/distributed/node_router.cpp:1843-1906).
The other five exist only on each copy's own port. The router's own behaviour is on
operations.md.
Routes¶
Every route is declared once, in the table kRoutes (csrc/server/http_server.cpp:333-346). It has
10 rows.
| Method | Path | Purpose | Handler at |
|---|---|---|---|
GET |
/health |
{"status":"ok","model":"<id>"}. While the rank drains it answers 503 with "status":"draining". While the rank is asleep, falling asleep or waking it answers 503 with the state name as status and a Retry-After header. |
csrc/server/http_server.cpp:1035 |
GET |
/tnd/window_stats |
Cumulative token and request counters since start: requests_ok, requests_failed, input_tokens, cached_tokens, output_tokens, a context-length histogram ctx_bins, ctx_p50_le, ctx_p99_le, epoch_id, epoch_requests, distinct_first_blocks. Read two snapshots and subtract. |
csrc/server/http_server.cpp:1126 |
POST |
/tnd/reset_prefix_cache |
Drops every cached prefix that no request holds. Requests in flight keep their blocks. Answers the eviction policy in force. | csrc/server/http_server.cpp:1149 |
GET |
/metrics |
Prometheus text: token counters, out-of-memory counters and request metrics. See metrics.md. | csrc/server/http_server.cpp:1182 |
GET |
/v1/models |
A list with one entry: the served model id, owned_by "tnd". |
csrc/server/http_server.cpp:1192 |
POST |
/v1/chat/completions |
Chat completion, streaming or not. | csrc/server/http_server.cpp:1198 |
POST |
/v1/completions |
Text completion of a raw prompt, streaming or not. | csrc/server/http_server.cpp:1733 |
POST |
/sleep |
Puts the rank to sleep: it finishes open requests, then frees GPU memory. ?level=1 (the default) or ?level=2. |
csrc/server/http_server.cpp:1081 |
POST |
/wake_up |
Wakes a sleeping rank and takes requests again. | csrc/server/http_server.cpp:1094 |
GET |
/is_sleeping |
{"is_sleeping": <bool>, "state": "<state>"}, plus level while asleep. is_sleeping is true only when the rank is fully asleep. |
csrc/server/http_server.cpp:1108 |
The three sleep routes answer loopback peers only, unless the rank was started with
--sleep-remote. They are rows of the route table like the other seven, so an admission identity
plugin's check runs on them first, and the loopback rule runs after it. Their levels, answers and
status codes are on operations.md.
There is no /v1/embeddings route on this server.
Request fields¶
The parser is csrc/server/openai_schema.cpp; the structs are in csrc/server/openai_schema.h.
A body that is not valid JSON gets 400.
Read by both routes¶
| Field | Type | Meaning |
|---|---|---|
model |
string | Read and not checked. The response always names the served model. |
stream |
bool | true streams server-sent events. Default false. |
stream_options.include_usage |
bool | With stream, sends one more chunk with usage and an empty choices array, after the last content chunk and before data: [DONE]. |
stop |
string or array of strings | Stop strings, matched on the decoded text. |
max_completion_tokens |
int | Output token limit. Wins over max_tokens. |
max_tokens |
int | Output token limit when max_completion_tokens is absent. Default 128 (openai_schema.h:23). |
temperature |
number | Default 1.0, or the checkpoint's generation_config.json value (below). |
top_p |
number | Default 1.0, or the checkpoint's value. |
top_k |
int | -1 turns it off. Default -1, or the checkpoint's value. |
min_p |
number | Default 0.0, or the checkpoint's value. |
repetition_penalty |
number | Default 1.0, or the checkpoint's value. |
frequency_penalty |
number | Default 0.0. |
presence_penalty |
number | Default 0.0. |
seed |
integer | Seeds this request's sampling. Unset means unseeded. |
min_tokens |
int | The end-of-sequence token cannot end the request before this many output tokens. Default 0. |
ignore_eos |
bool | Never stop on the end-of-sequence token; run to the token limit. Default false. |
skip_special_tokens |
bool | Drop special tokens from the returned text. Default true. |
logprobs, top_logprobs |
bool or int | Parsed into the sampling parameters. The response carries no log probabilities: chat replies have no logprobs field and completion replies have "logprobs": null. |
priority |
integer | Lower runs first. Default 0. A negative value is clamped to 0, so a client can only lower its own priority. A value that is not an integer, or does not fit 32 bits, gets 400 (openai_schema.cpp:401-417). |
response_format, structured_outputs |
object | Constrain the output. See "Tool calls and structured output" below. |
When a request leaves a sampling field out, the server uses the checkpoint's own
generation_config.json value for temperature, top_p, top_k, min_p and
repetition_penalty. --generation-config off turns that off and uses the OpenAI defaults
instead. A value the request sends always wins (openai_schema.cpp:55, parse_sampling).
ignore_eos and min_tokens come from the client. A client can use them to make a request run to
its full token limit. trusted-network.md lists this.
/v1/chat/completions only¶
| Field | Meaning |
|---|---|
messages |
Array of messages. content is a string, or an array of parts of which only {"type":"text"} parts are read and joined. The generic parser drops image and audio parts (csrc/server/openai_schema.cpp:20-34). The DeepSeek-V4 renderer refuses any non-text part with a 400 (csrc/server/dsv4_chat.cpp:133-135). An assistant message may carry tool_calls; a tool message may carry tool_call_id and name (csrc/server/openai_schema.cpp:281-311, :441-445). |
chat_template_kwargs |
Passed to the DeepSeek-V4 renderer (thinking controls). The other renderers do not read it. |
reasoning_effort |
Read by the DeepSeek-V4 renderer only. |
tools, tool_choice, parallel_tool_calls |
See "Tool calls and structured output" below. |
The chat template is chosen once, at start (select_chat_format, csrc/server/chat_template.h:102-108):
- the checkpoint's Jinja template, when it has one;
- else DeepSeek-V4's own format, when the tokenizer holds V4's special tokens;
- else each message's content followed by a newline.
/v1/completions only¶
| Field | Meaning |
|---|---|
prompt |
A string, or an array whose first element is a string. Only one prompt is served per request; later elements are ignored. |
Header¶
| Header | Meaning |
|---|---|
X-Request-Deadline-Ms |
A positive integer of milliseconds, at most 12 digits (http_server.cpp:194-210). If the request would wait in the queue longer than this, it is refused with 503 and "code":"queue_full", or with "code":"queue_timeout" once the deadline passes while it waits. Anything else in the header gets 400. |
Ignored fields¶
The server does not read these. A request that sends them is served as if they were absent:
n (one choice is returned), best_of, echo, suffix, logit_bias, user, functions,
function_call.
The removed vLLM fields guided_json, guided_regex, guided_grammar and guided_choice are
also ignored: the output is not constrained, and the server logs one warning line the first time
it sees one (openai_schema.cpp:201-211). Use structured_outputs or response_format.
Tool calls and structured output¶
Tools¶
A tool format is the text convention a model writes a tool call in. The server picks one at
start from what the checkpoint declares, never from its name (detect_tool_format,
csrc/server/tool_calls.cpp:276-297), and logs the choice.
| Format | Chosen when | A call looks like |
|---|---|---|
| Hermes | the chat template shows <tool_call> tags around a JSON body with the keys name and arguments |
<tool_call>{"name": ..., "arguments": {...}}</tool_call> |
| Harmony | the tokenizer is a Harmony tokenizer (gpt-oss) | a message on the commentary channel addressed to functions.NAME |
| DeepSeek-V4 | the chat renderer is DeepSeek-V4's | a DSML tool_calls block |
| none | anything else, including a template whose <tool_call> body is not JSON |
no call is parsed |
The Hermes rule is a text match on the template. It is not checked against a served checkpoint.
What the server reads (parse_tools, csrc/server/openai_schema.cpp:315-382):
| Field | Rule |
|---|---|
tools |
An array of {"type":"function","function":{"name", "parameters"}}. An empty array means no tools. |
tool_choice |
"none", "auto", "required", or {"type":"function","function":{"name":...}}. Absent means "auto" with tools and "none" without. "none" renders no tools into the prompt. |
parallel_tool_calls |
Default true. false returns the first call only. |
What comes back:
- Non-streaming.
message.tool_callsis an array of{"id", "type":"function", "function":{"name", "arguments"}}.argumentsis JSON text.message.contentholds the text outside the calls, ornullwhen there is none. With a forced choice it is"". - Streaming. The first chunk's
deltais{"role":"assistant","content":""}. Calls arrive indelta.tool_calls: one entry withid,type,indexand the function name, then entries that carryargumentsfragments. finish_reasonis"tool_calls"when the reply holds a call and the model stopped by itself. A reply cut by the token limit keeps"length"(csrc/server/http_server.cpp:1588-1589,:1702-1703).
A forced choice ("required" or a named function) is served on a Hermes-format model only. The
server constrains the reply to a JSON schema built from tools
(csrc/server/http_server.cpp:1236-1249). The schema replaces a response_format the same request
sends. With a named function, finish_reason stays the engine's own reason. Harmony and
DeepSeek-V4 models serve "auto" and "none" only.
What is refused, all with 400 and "type":"invalid_request_error":
| Request | Why |
|---|---|
| Tools are active and the model's tool format is none | the server cannot parse a call from this model (check_tool_request, csrc/server/tool_calls.cpp:299-320). Omit tools or send tool_choice: "none". |
A forced tool_choice on a Harmony model |
the forced reply is bare JSON, and a Harmony reply must be channel markup |
A forced tool_choice on a DeepSeek-V4 model |
the forced-choice grammar has not been run with this model's reply format, so the pair stays refused |
A forced tool_choice with ignore_eos: true |
the tokens after the end of the call would not be constrained |
A forced tool_choice where structured output is refused (below) |
the forced reply needs a grammar |
A malformed tools, tool_choice or parallel_tool_calls |
for example tool_choice without tools, or a named function that is not in tools |
Structured output¶
The server reads two fields, on both routes (parse_grammar,
csrc/server/openai_schema.cpp:199-254):
| Field | Accepted shapes |
|---|---|
response_format |
{"type":"text"}, {"type":"json_object"}, or {"type":"json_schema","json_schema":{"name", "schema"}} |
structured_outputs |
exactly one of json (a JSON schema), regex, choice (an array of strings), grammar (EBNF whose root rule is root), json_object: true |
When both name the same kind, response_format wins. The grammar is compiled on the HTTP worker
thread before the request is queued (csrc/server/http_server.cpp:1276-1300).
What is refused:
| Request | Status |
|---|---|
A malformed value; response_format.type structural_tag; structured_outputs with structural_tag, whitespace_pattern, disable_any_whitespace: true or disable_additional_properties: true; two different kinds in one request |
400 |
| A grammar the compiler rejects | 400 |
A JSON schema nested more than 64 levels deep. Depth counts nested arrays and objects, the root included, the same way and to the same bound as vLLM; it covers response_format, structured_outputs.json and the schema a forced tool_choice builds from tools (csrc/server/grammar_compiler.cpp, GrammarCompilerService::compile) |
400, "the JSON schema is nested too deeply" |
A JSON schema whose objects together have more than 5,000 properties (OpenAI's limit), or too many optional properties: the sum over its objects of (optional properties)² is past 40,000, which is one object with 200 optional properties. A property is optional when it is not in its object's required (csrc/server/grammar_compiler.cpp, GrammarCompilerService::compile) |
400, "the JSON schema has N object properties" or "too many optional properties" |
A JSON schema that uses a keyword the grammar engine (XGrammar v0.2.9) compiles but does not enforce: allOf with two or more schemas; not; if/then/else; dependentRequired; dependentSchemas; multipleOf, except on "type":"integer" with an integer value up to 1,024 and either no bound or both bounds at most 10,000 apart; uniqueItems: true; contains, minContains, maxContains; a $ref that does not start with #; on a string, a format other than the 14 built-in ones (email, date, time, date-time, duration, ipv4, ipv6, hostname, uuid, uri, uri-reference, uri-template, json-pointer, relative-json-pointer), or minLength/maxLength with pattern or format; dependencies, $dynamicRef, $recursiveRef; a constraint beside $ref or beside anyOf/oneOf/allOf (a type the inner schema already implies is allowed), or two of anyOf/oneOf/allOf in one schema; a constraint other than type beside enum/const, or an enum/const value that is not of the declared type; a required name that properties does not list; a number, string, array or object constraint on a schema with no type and no properties/additionalProperties/items/prefixItems; a oneOf whose branches can accept the same value (XGrammar enforces oneOf as anyOf; branches of different types, with a const discriminator, or with a required key the other branch does not list are served). Annotations (title, description, default, examples, $defs, ...) are never refused (unenforced_schema_keyword, csrc/server/grammar_compiler.cpp) |
400, "the JSON schema uses KEYWORD ... at "/path"" |
A local $ref that points at nothing in the schema (a missing key, or an array index past the end) |
400, "the JSON schema uses $ref to "#/..." which points at nothing in this schema ..." |
A schema whose keyword check runs past its work budget (on the dev host, about 80 ms of checking; a oneOf of 1,500 closed objects told apart only by required is one such schema) |
400, "the JSON schema is too costly to check ..."; a large oneOf is cheapest with a const/enum discriminator property, or as anyOf |
response_format or structured_outputs on the chat route of a Harmony model (gpt-oss), or of a DeepSeek-V4 request in thinking mode: the grammar starts at the first token, and those replies open with channel markup or reasoning (check_structured_output_request, csrc/server/tool_calls.cpp) |
400 |
A request body nested more than 128 levels deep, or an assistant tool call's function.arguments string nested that deep (csrc/server/openai_schema.cpp, check_request_depth) |
400 |
Structured output with min_tokens above 0 |
400 |
A rank that cannot apply the token mask (csrc/server/serve_loop.cpp:495-528): it runs speculative decoding, tensor parallelism or expert parallelism; or the launcher stated no vocabulary size or no logits width (it states the width only when the token-mask kernel is loaded); or the model's logits width and its tokenizer disagree on the mask size |
400 |
The compile did not finish before the request's X-Request-Deadline-Ms |
503, "code":"grammar_compile_timeout", with Retry-After (csrc/server/http_server.cpp:291-299). Without that header the compile has no time limit: XGrammar cannot cancel a compile, so the depth and width bounds above are what keep it short. Compiles share a few slots sized from the host (GrammarCompilerOptions::derive), so one slow compile does not hold up the others. |
Responses¶
Non-streaming¶
- Chat:
object"chat.completion", one choice withmessage.role"assistant",message.contentandfinish_reason. A reply with tool calls addsmessage.tool_calls. - Completion:
object"text_completion", one choice withtext,finish_reasonand"logprobs": null. finish_reasonis"stop"(end-of-sequence token or a stop string),"length"(the token limit) or"tool_calls"(above).usageholdsprompt_tokens,completion_tokens,total_tokensand, when the server knows it,prompt_tokens_details.cached_tokens: the prompt tokens served from the prefix cache.
Streaming¶
Content-Type: text/event-stream. Each event is data: <json>. Chat chunks have object
"chat.completion.chunk" and carry new text in choices[0].delta.content. The last content chunk
has a finish_reason; its delta is empty, except that a tool request may carry its last text or
call there. The optional usage chunk follows, then data: [DONE].
Reasoning text¶
For gpt-oss (Harmony format) and for DeepSeek-V4 in thinking mode, the server splits the model's
reasoning from its answer. The reasoning goes in message.reasoning_content (non-streaming) or
delta.reasoning_content (streaming); the answer stays in content.
Status codes¶
| Code | When | Body |
|---|---|---|
200 |
Served | The response above |
400 |
Malformed JSON, a bad X-Request-Deadline-Ms, a bad priority, a message the chat renderer refuses, a tool or structured-output request the server cannot serve, or a bad level on /sleep |
{"error":{"message":...,"type":"invalid_request_error"}} |
403 |
A sleep route called by a peer that is not loopback, without --sleep-remote |
{"error":{...,"type":"forbidden"}} |
409, 500, 501 |
/sleep or /wake_up could not do it; see operations.md |
{"status":..., "error":{...}} |
499 |
The client closed the connection; the request is cancelled and its KV blocks freed | none |
500 |
An unexpected failure before the request was queued | cpp-httplib's default |
503 |
Queue full or deadline missed ("code":"queue_full", "queue_timeout" or "grammar_compile_timeout", with a Retry-After header); the rank is asleep, falling asleep or waking ("code":"engine_sleeping", with Retry-After); the engine is stopping ("engine unavailable"); or the forward ran out of GPU memory twice for this request (retry it) |
{"error":{...,"type":"service_unavailable"}} or "server_error" |
With an admission identity plugin loaded, that plugin sees every request on all 10 routes before the handler runs, and may refuse it with its own status (plugins.md). With none, no such check runs.
The queue cap and the drain on shutdown are described on operations.md.
Not on this server¶
/v1/embeddings(embeddings run through the PythonLLM.embed()API).- Several choices per request (
nabove 1). - Log probabilities in the response.
- The legacy
functionsandfunction_callfields. - Tool calls for a model whose chat template declares none of the three formats above.
- Authentication: every client that reaches the port is served (trusted-network.md).