Tokens In <> Tokens Out API¶
POST /inference/v1/generate is the token-in/token-out (TITO) HTTP endpoint: it takes prompt token IDs and returns generated token IDs, logprobs keyed by integer token ID, and finish_reason/stop_reason, with no detokenization. Use it when the caller does its own tokenization and chat templating, such as an RL rollout worker. It is also the generation step of the render → generate → derender pipeline used in disaggregated serving (see the Renderer APIs and Derenderer APIs).
Enabling the endpoint (--enable-scale-out, --tokens-only)¶
--enable-scale-outregisters it, with/render,/derenderand/inference/v1/abort_requests.--tokens-onlyalways registers it, skips loading the tokenizer and forcesdetokenize=False. Stop strings (sampling_params.stop) are then rejected with a 400; usestop_token_ids.VLLM_SERVER_DEV_MODE=1turns--enable-scale-outon unless--disable-scale-outis passed.- With neither flag, it returns 403
Scale-out endpoints are disabled. Restart vllm serve with --enable-scale-out to enable them.
vllm serve Qwen/Qwen3-0.6B --enable-scale-out
curl -X POST http://localhost:8000/inference/v1/generate \
-H "Content-Type: application/json" \
-d '{"token_ids": [151644, 872, 198], "sampling_params": {"max_tokens": 32, "logprobs": 1}}'
A full client is in examples/scale_out/token_generation_client.py.
Request fields¶
| Field | Notes |
|---|---|
token_ids |
Required list[int]: the already-templated prompt. Non-empty, no negative IDs. |
sampling_params |
Required. Any SamplingParams field, e.g. max_tokens, temperature, logprobs, stop_token_ids. Without max_tokens, the server applies its own default (as on the OpenAI endpoints), not 16. bad_words needs a tokenizer: a server without one (--tokens-only or --skip-tokenizer-init) rejects it with a 400. |
output_mode |
"tokens" (default) or "text", see Output modes. |
stream, stream_options |
SSE chunks ending with data: [DONE]. |
return_token_ids |
Echo the final prompt IDs as prompt_token_ids. |
features / content_parts |
Multimodal input, mutually exclusive. |
request_id, model, cache_salt, priority, kv_transfer_params, ec_transfer_params |
Optional. |
Response fields¶
choices[i] field |
Notes |
|---|---|
token_ids |
Generated token IDs. |
finish_reason |
stop, length or abort. |
stop_reason |
Stop token ID or string; null on EOS, length and abort. |
logprobs |
{"content": [{"token_id", "logprob", "rank", "top_logprobs": [...]}]}, one entry per token, sampled token first. token_id is an integer, not the older "token_id:<id>" string. Needs sampling_params.logprobs. |
weight_versions, routed_experts, sampling_mask |
Optional, see Weight versions; the last two need --enable-return-routed-experts / --return-sampling-mask. |
The top level adds request_id, usage, prompt_token_ids and prompt_logprobs. Stream chunks carry the same per-choice fields for the new tokens.
Targeting a data-parallel rank (X-data-parallel-rank)¶
Send the header X-data-parallel-rank: <int> to pin a request to one data-parallel (DP) engine rank; there is no body field. Without the header, or with a non-integer value, the request is load balanced. A rank outside [0, data_parallel_size) is rejected.
Request priority (X-Vllm-Priority)¶
Send the header X-Vllm-Priority: <int> to set the request's priority. It overrides the body priority; a non-integer value is ignored. A header value or body priority outside [-2**31, 2**31 - 1] is rejected. Non-zero priorities require the server to use priority scheduling (--scheduling-policy priority).
Output modes¶
The request field output_mode selects how much of the postprocessing the server does for the caller.
output_mode |
Response adds | Server needs |
|---|---|---|
tokens (default) |
nothing, token IDs only | nothing |
text |
text on every choice and decoded tokens with bytes in logprobs |
a tokenizer |
derender |
the parsed assistant message (content, reasoning, tool_calls) on every choice, plus logprobs shaped like coupled chat's |
a tokenizer and the parser flags you'd give vllm serve |
text returns text and token IDs in a single call, without a separate derender hop per chunk. This suits latency sensitive streaming, where the derender hop lands on every output token.
Every response and every stream chunk echoes output_mode. Servers that predate the field ignore it and return token IDs only with a 200, so check that the output_mode in the response matches the one you sent. Older servers don't return it.
import httpx
response = httpx.post(
"http://localhost:8000/inference/v1/generate",
json={
"token_ids": [151644, 872, 198],
"sampling_params": {"max_tokens": 32},
"output_mode": "text",
},
).json()
assert response["output_mode"] == "text"
print(response["choices"][0]["text"])
print(response["choices"][0]["token_ids"])
Text¶
textcomes from the request's own detokenizer, soskip_special_tokens,spaces_between_special_tokens,stopandinclude_stop_str_in_outputbehave as they do on/v1/completions.- A matched stop string is cut from
textunlessinclude_stop_str_in_outputis set.token_idskeeps every generated token, so decodingtoken_idsyourself brings the stop string back. /derenderonly acceptsoutput_mode: "tokens"responses and returns a 400 for text responses which are already detokenized.- With
stream: true, each choice'stextis the delta since the previous chunk. A chunk is sent whenever the engine output carries new text or afinish_reason, even with no new token IDs. That covers text held back for stop string matching and the final output after an abort.
Derender¶
derender returns the assistant message a coupled /v1/chat/completions would, without a separate derender call. /v1/chat/completions/render and /v1/messages/render return parse_context on the GenerateRequest. Send it back with output_mode: "derender". It carries the tools, tool_choice, include_reasoning, return_tokens_as_token_ids, resolved JSON only chat_template_kwargs and the history tool call count. A parse_context field this server doesn't know fails a derender request and is ignored at the other levels.
- The parser reads the engine's
text, so it sees the stop string cut and the postadjust_requestdecode flags. That makes it match coupled chat for parsers whoseadjust_requestchanges decoding which/derendercan't. - A server with a tool or reasoning parser needs
parse_context. Without a parser,message.contentis the plain text. parse_contextis ignored at other levels, so a rendered request can go to a prefill leg unchanged.logprobsfollow coupled chat.top_logprobsis cut tosampling_params.logprobs,logprob_token_idsis honored. When a parser hides the reasoning withinclude_reasoning: false,logprobs,token_idsandsampling_maskare dropped so they don't expose it.finish_reasonfollows coupled chat too. It'stool_callswhen the message has tool calls except with a namedtool_choiceor alengthcut.- With a reasoning parser,
usage.completion_tokens_details.reasoning_tokensis the reasoning parser's count summed over the choices, as on coupled chat, also withinclude_reasoning: false. In a stream it's on the final usage chunk, not on per-chunkcontinuous_usage_statsusage. - With
stream: true, each choice carries a chatdelta(role,content,reasoning,tool_calls) instead oftext, andfinish_reasonfollows coupled chat.roleis set on the first chunk of each choice,n > 1is supported, andnullfields are left out ofdelta. A chunk is sent whenever the engine output carries a parsed delta, visible token IDs, logprobs or afinish_reason. Parsing runs on the API server event loop, so--api-server-countscales it. - The message
roleis the generate server's--response-role.parse_contextdoesn't carrymessages,add_generation_promptorecho, so the last message's role andechoaren't applied. Use/derenderfor those. - Cohere grounding citations aren't returned. The parser strips the citation spans from
content, and the document map can't go over JSON inparse_context.
A streamed tool call looks like this, with the usage chunk and data: [DONE] framed as at the other levels:
data: {"request_id": "...", "output_mode": "derender", "choices": [{"index": 0, "token_ids": [151657], "delta": {"role": "assistant", "tool_calls": [{"index": 0, "id": "chatcmpl-tool-...", "type": "function", "function": {"name": "get_weather", "arguments": ""}}]}, "finish_reason": null, ...}]}
data: {"request_id": "...", "output_mode": "derender", "choices": [{"index": 0, "token_ids": [], "delta": {}, "finish_reason": "tool_calls", ...}]}
Logprobs¶
With output_mode: "tokens", logprobs are GenerateLogProbs with an integer token_id and rank per entry and no token or bytes (see Generate Output Logprobs). With output_mode: "text", they are ChatCompletionLogProbs carrying the decoded token strings and their UTF-8 bytes for the sampled token and every entry in top_logprobs; a server started with --return-tokens-as-token-ids returns token_id:N placeholders there instead, as /v1/completions does.
With output_mode: "derender", parse_context.return_tokens_as_token_ids overrides the generate server's --return-tokens-as-token-ids when it is not null: true returns token_id:N placeholders with bytes: null, and false returns decoded tokens and UTF-8 bytes even when the server flag is enabled. An omitted or null value uses the generate server's flag. /render preserves explicit true and false without applying the render server's flag, and omits the context field when the request value is omitted or null. This setting affects logprobs only; the assistant message is still parsed from text.
Upgrade generate nodes before using explicit request overrides: older generate nodes reject parse_context.return_tokens_as_token_ids with a 400 in derender mode. Requests with an omitted or null override remain compatible because /render leaves that field out. Unknown parse-context fields remain ignored in tokens and text modes.
Errors¶
The server returns a 400 for:
output_mode: "text"or"derender"on a server without a tokenizer (--tokens-onlyor--skip-tokenizer-init).output_mode: "text"or"derender"withsampling_params.detokenize: false.output_mode: "derender"withoutparse_contexton a server with a tool or reasoning parser or with a namedtool_choiceinparse_contextthat matches none of itstools. This is checked before generating.- An unsupported
output_modevalue.
For using output_mode with separate prefill and decode pools, see Disaggregated Prefilling.
Weight versions¶
The final output of every choice carries weight_versions, the label of the weights that sampled each range of its output tokens. Ranges are half-open over output-token indexes (prompt excluded), contiguous and in generation order, so a request that crossed one weight update gets two:
"weight_versions": [
{"version": "v7", "start": 0, "end": 57},
{"version": "v8", "start": 57, "end": 128}
]
- With
stream: true, only the last chunk of each choice carries the list, including the last chunk after an abort. Its offsets cover the whole output. Earlier chunks carrynullor omit the field. - An output with no tokens, such as a request aborted before its first token, gets
[]. - The labels are the ones you set with
/update_weight_versionor/finish_weight_update, see Async Reinforcement Learning. vLLM doesn't order or check them, and the label is"default"until you set one.
Multimodal inputs¶
A request can carry media in two ways, and can use both at once:
content_parts: raw media (image_url,audio_urlorvideo_url, each with an optionaluuid).token_idsholds one placeholder token per item, and the server expands it.features: items whose placeholders are already expanded intoken_ids, at the ranges given inmm_placeholders. Pass the processed tensors inkwargs_data, or omit them to look the items up in the processor cache bymm_hashes.
When both are set, every content_parts placeholder must come after the last features range. Only the tokens after that range are processed, so the expanded runs before it are left as they are. Models that insert media at the start of the prompt (such as PaliGemma, BLIP-2 and Molmo) would place a new item right after that range without an error, so don't combine the two fields for them.
This fits multi-turn rollouts. Each turn resends the previous prompt with its images already expanded, adds the new turn with one placeholder per new image, and sends the earlier images as features:
import httpx
url = "http://localhost:8000/inference/v1/generate"
# Turn 1: turn1_ids holds one <|image_pad|> for image A.
turn1 = httpx.post(url, json={
"token_ids": turn1_ids,
"content_parts": [{"type": "image_url", "url": url_a}],
"sampling_params": {"max_tokens": 256},
"return_token_ids": True,
}).json()
# Turn 2: image A is expanded in turn1["prompt_token_ids"];
# turn2_ids appends one <|image_pad|> for image B.
turn2 = httpx.post(url, json={
"token_ids": (
turn1["prompt_token_ids"] + turn1["choices"][0]["token_ids"] + turn2_ids
),
"features": {
"mm_hashes": turn1["mm_hashes"],
"mm_placeholders": turn1["mm_placeholders"],
},
"content_parts": [{"type": "image_url", "url": url_b, "uuid": "img-b"}],
"sampling_params": {"max_tokens": 256},
"return_token_ids": True,
}).json()
With return_token_ids, the response carries mm_hashes next to mm_placeholders: the processor cache key of each item, in the same order. Pass them back unchanged rather than building keys yourself because the key format depends on the server's options and on whether the item was sent with a uuid. Send the item with kwargs_data instead in three cases:
- The item has been evicted from the cache, so a request by key fails.
- The processor cache is disabled (
--mm-processor-cache-gb 0), so the returned keys can't be reused. - The server runs the Rust frontend (
VLLM_USE_RUST_FRONTEND=1) which doesn't support omittingkwargs_datayet. It still returnsmm_hashes.
Processed tensors in object storage¶
A client that already has an item's processed tensors, such as an RL trainer on another node, can upload them to an S3-compatible store and send a reference in features.kwargs_refs instead of inlining them in kwargs_data. The tensors then skip the request body and any gateway in front of vLLM. The server downloads each object, checks its size and SHA-256 digest, and rebuilds the model's field metadata before it submits the request to the engine.
Each object holds one item, saved with safetensors.torch.save. Its tensors are the ones this server's multimodal processor produces for that item, under the same names and dtypes and with their batch dimension, so the same tensors that /render returns in kwargs_data. The client doesn't need vLLM, but the tensors can differ from what the model's Hugging Face processor returns. For example, Qwen3-VL with the default mm_device_do_normalize normalizes on the GPU, so its object holds a uint8 pixel_values and an image_grid_thw of shape [1, 3]:
import hashlib
import boto3
from safetensors.torch import save
payload = save({"pixel_values": pixel_values, "image_grid_thw": image_grid_thw})
key = f"rollouts/{request_id}/image-0"
boto3.client("s3").put_object(Bucket="mm-tensors", Key=key, Body=payload)
features = {
"mm_hashes": {"image": [image_hash]},
"mm_placeholders": {"image": [{"offset": 15, "length": 64}]},
"kwargs_refs": {
"image": [{
"uri": f"s3://mm-tensors/{key}",
"format": "safetensors-v1",
"nbytes": len(payload),
"digest": hashlib.sha256(payload).hexdigest(),
}]
},
}
Like kwargs_data, each kwargs_refs list is parallel to mm_hashes, and a null entry falls back to kwargs_data or the processor cache. An item can't set both. mm_metadata for a referenced item may only repeat fields of its object with the same values. The mm_hashes entry stays the cache key, so give different content different hashes.
kwargs_refs are off by default. Enable them at startup with --mm-tensor-refs-config; a server started without it rejects them with a 400:
vllm serve Qwen/Qwen3-VL-2B-Instruct --enable-scale-out \
--mm-tensor-refs-config '{"s3_allowed_uri_prefix": "s3://mm-tensors/rollouts"}'
The config's fields are:
s3_allowed_uri_prefix: thes3://bucket/prefixthat every reference must be under. Required.max_object_bytes: the largest object the server downloads. Default: 1 GiB.max_request_bytes: the largest total size of the objects one request references. A request over it fails with a 400 before anything is downloaded. Default: 1 GiB.max_reserved_bytes: the memory one API server reserves for referenced tensors. Each request reserves twice the declared size of its objects, for the downloaded bytes and the decoded tensors, and keeps the reservation until it finishes, even if the client disconnects. Requests wait in arrival order until their reservation fits. It must be at least twicemax_request_bytes. Default: 8 GiB.max_concurrent_reads: how many requests per API server can download references at once. Default: 32.
The endpoint and credentials come from the server's environment, never from the request: S3_ENDPOINT_URL if set, otherwise the standard boto3 configuration (for example AWS_ENDPOINT_URL_S3, or addressing_style in the AWS config file). The server needs boto3 installed, creates its S3 client at startup, and never deletes objects, so expire them on the client side, for example with a bucket lifecycle rule. Only the Python frontend accepts kwargs_refs.
Like kwargs_data, kwargs_refs is meant for clients in one trust domain:
- The server reads objects with its own credentials, so every caller of the endpoint can reference every object the server can read under the allowed prefix. Don't share a prefix between callers that shouldn't see each other's objects.
- A missing, inaccessible or mismatched object (wrong size or digest) returns the same 422, so a caller can't probe objects it doesn't know. The details are in the server log.
- The server checks each object's size, digest and fields, but tensors with a shape the model doesn't expect, such as
pixel_valuesrows of the wrong width, can still fail inside the engine.
Aborting requests¶
POST /inference/v1/abort_requests aborts in-flight requests. It is registered wherever /inference/v1/generate is and requires the API key when --api-key is set, like /inference/v1/generate.
curl -X POST http://localhost:8000/inference/v1/abort_requests \
-H "Authorization: Bearer $VLLM_API_KEY" \
-H "Content-Type: application/json" \
-d '{"request_ids": ["generate-tokens-42"]}'
The request ID is the request_id the server returned: the X-Request-Id header or body request_id you sent, prefixed with generate-tokens-. A missing request_ids returns a 400. The response is empty and the abort finishes in the background.
With --tokens-only, the same handler is also served at POST /abort_requests for existing deployments. That path doesn't require the API key, even when --api-key is set. See Security.
Rust frontend with a remote generation worker¶
Set --remote-generation-url to the worker’s gRPC address. This requires --max-model-len to be the worker’s effective context limit in tokens. Use the same model on both sides. The frontend and worker can use different --served-model-name aliases for that model.