Skip to content

API surface ​

Use this reference to configure HTTP binding, model naming, streaming, and logprob responses. For weight lifecycle operations, see Weight updates.

API parameters ​

The following table lists parameters that control the API surface and weight updates:

ParameterPurpose
--hostHTTP bind host.
--portHTTP bind port.
--served-model-nameThe model's name in metric labels. Under ts serve, requests may also name the model by it; the OpenAI-compatible API lists the model path.
--api-keySMG gateway API key for authorization with upstream workers.
--chat-templateBuilt-in chat template name or template file path (handled by the SMG gateway).
--stream-intervalStreaming buffer size in generated tokens. The server streams the first step's tokens at once, then whenever at least this many tokens are unsent. Smaller values stream more often.
--weight-versionInitial model-weight version, the L3 cache's namespace (see Weight versions). Defaults to default.
--model-update-configJSON object handed to the Model Updater SDK for the Mooncake weight update. Requires --model-update-sdk-module, --model-update-engine-type, and --model-update-draft-weights; see Mooncake weight updates.
--model-update-sdk-moduleImport path of the Model Updater SDK module. Imported in the scheduler process on the first Mooncake update, not at startup. Required with --model-update-config.
--model-update-engine-typeSDK EngineType member name for this engine, resolved as EngineType[value.upper()]. Required with --model-update-config.
--model-update-draft-weightsretain or refresh: whether a Mooncake update also streams the speculative draft model's weights. Required with --model-update-config.

Stop token limit ​

A request can end on at most 16 stop token IDs. The limit counts the union of the request's stop_token_ids and the model's and tokenizer's EOS and additional stop token IDs. A request that exceeds it is rejected with HTTP status 400; the error message states how many other stop_token_ids the request can pass. With ignore_eos, the request has no stop token IDs, including its own stop_token_ids. Stop strings don't count toward the limit.

NPU top-p sampling ​

The HF model config boolean npu_sampling_top_p_top_k_cap is false by default. Enable NPU sampling candidate truncation at startup with:

bash
--hf-overrides '{"npu_sampling_top_p_top_k_cap": true}'

On ascend_full, a request with top_p < 1 and omitted top_k (or top_k=-1) then uses an effective top_k=4096: select the top 4096 candidates, normalize their probabilities, then apply top-p filtering. This limits the candidate set and can change the distribution compared with whole-vocabulary top-p sampling. Set the field to false for whole-vocabulary top-p; the override affects the loaded configuration, without editing the checkpoint's config.json.

The option does not affect GPU sampling backends, top_p=1, greedy requests, or explicit finite top-k values. Existing ascend_full behavior still caps explicit finite top-k above 4096 at 4096. The same per-request policy applies in eager execution, graph replay, and chain verification.

Logprobs ​

The following table lists the server parameters that control logprob collection and memory use:

ParameterPurpose
--enable-output-logprobsGate for every logprob request. Off by default; the sampler gathers logprobs only when on, and a request asking for them on a server without the flag is rejected.
--full-vocab-top-k KEnable fixed-width binary head/tail scoring for requests with return_full_vocab_topk=true; 0 disables it. Requires output logprobs, a blockwise logprob order, and request top_logprobs_num=K (1–128). See binary output.
--full-vocab-top-k-solution SOLUTIONExplicit block-sum-exp provider for binary full-vocabulary scoring; required when K is nonzero. Choose the provider matching the deployment's numerical contract.
--input-logprob-chunk-tokensPrompt rows pushed through the LM head per chunk when a request asks for prompt (input) logprobs. Defaults to 256. A sizing knob only: the transient per-chunk cost is about chunk × vocab × (2 + 2 + 4) bytes (the bf16 logits shard, the bf16 TP-gathered logits, the fp32 log-softmax), so the default costs about 256 MiB at a 128K vocabulary, and the value never changes a result (log-softmax is row-local).

Request and response fields ​

A request asks for logprobs with return_logprob. Its output frames carry the sampled tokens' logprobs with their ids (output_token_logprobs_val and _idx) and, with logprob_start_len, prompt (input) logprobs (input_token_logprobs_val and _idx):

  • logprob_start_len=-1 (the default) returns the single entry (null, input_ids[-1]) and computes nothing extra.
  • logprob_start_len=s with 0 <= s < len(input_ids) returns len(input_ids) - s entries: (null, input_ids[s]) first, then the logprob of each following prompt token given its prefix. If s >= len(input_ids), the server returns an HTTP 400 Bad Request status code.

ts serve's gateway (SMG's direct lane) carries the sampled tokens' logprobs, the prompt logprobs, and the top candidates the engine computes; which of its routes renders them is the gateway's (/generate returns the prompt logprobs, chat completions the candidates).

Prompt logprob computation ​

The engine computes prompt logprobs with the same fp32 log-softmax as the output logprobs (see Logprob numerics), accumulates them across chunked-prefill chunks, and ships them once, on the first frame after the prompt finished. A request that returns them from position s skips the prefix cache for positions >= s, so the engine recomputes those positions and always has logits for them. Positions before s reuse the cache as usual. Mixed prefill/decode batches (--enable-mixed-batch) are supported where the selected parallelism configuration permits them. A NaN or infinite prompt logprob terminates the request with a NumericalError exactly like NaN logits on a sampled token (--enable-nan-detection). The response never carries a non-finite value.

The ingress returns an HTTP 400 Bad Request status code for any request with logprob_start_len >= 0 that asks for at least one prompt logprob when the engine cannot score every prompt position: models that narrow their prefill rows (DeepSeek V4.1's CED decoder keeps only each prompt's last window for the LM head). The data plane reports this capability at startup and the host's ingress checks it before admitting the request, so the data plane never has to. The ingress also refuses multimodal prompts (their media positions carry content-hash ids, not tokens) and any prompt whose client-supplied input_ids fall outside the vocabulary. logprob_start_len=-1 is always accepted.

Parallel and disaggregated deployments ​

Under pipeline parallelism (--pipeline-parallel-size > 1) the last stage scores the prompt rows and the commit path carries both logprob vectors to the other stages with the sampled tokens. Under query context parallelism (--query-context-parallel-size N) the prompt rows of a chunk live on the rank whose shard holds them. Because the LM head is vocab-sharded over the same ranks, the ranks gather the planned rows' activations to the group and every rank scores the whole plan, so each rank's --input-logprob-chunk-tokens chunks cover the chunk's planned rows exactly as without sharding (the per-chunk transient described for --input-logprob-chunk-tokens is the same), and the result is identical on every rank. The ranks gather the sampled rows only after scoring the prompt rows.

In a disaggregated deployment the prefill node and the decode node each return their own frames, exactly as SGLang's do: the prefill node's finished frame carries input_token_logprobs (and the bootstrap token under output_token_logprobs), while the decode node's frames carry output_token_logprobs only and never input_token_logprobs. The prefill node forwards the bootstrap token's logprob to the decode node, so the decode node's output_token_logprobs covers every generated token. Merging the two into one response is the router's job: it joins the prefill node's prompt logprobs with the decode node's output, just as it does for SGLang.

Top logprob candidates ​

top_logprobs_num=k (1 to 20) adds each position's k most likely tokens, most likely first, as (logprob, token_id) pairs: input_top_logprobs beside the prompt logprobs (null for the first position, like its value) and output_top_logprobs beside the sampled token. They come from the same fp32 log-softmax as the values. The engine computes them where the forward runs eagerly, so the ingress takes top_logprobs_num only for a request whose every token is sampled in its prefill (max_new_tokens 0 or 1, as an echo scoring request sends) and with --logprob-order torch. The ingress returns an HTTP 400 Bad Request status code for requests with longer generation, pipeline parallelism, or disaggregated prefill and decode. token_ids_logprob is not supported yet.

Scheduler compatibility ​

This runtime requires a tokenspeed-scheduler build that has RequestSpec.max_cached_prefix_tokens (the admission-probe bound; see section 1 of Scheduler design): every admission sets it, so an older scheduler fails at the first request, not only at the first prompt-logprob request.

TokenSpeed documentation