Skip to content

vllm.entrypoints.scale_out.token_in_token_out.protocol

Classes:

Functions:

AbortRequestsRequest

Bases: BaseModel

Request for the /inference/v1/abort_requests endpoint.

DerenderChatRequest

Bases: BaseModel

Request for the /v1/chat/completions/derender endpoint (non-streaming).

Wraps a complete GenerateResponse and caller supplied metadata needed to produce a fully formed ChatCompletionResponse without a GPU.

Attributes:

  • chat_request (ChatCompletionRequest | None) –

    The original (post-adjust_request) ChatCompletionRequest from /render.

  • generate_response (GenerateTokensResponse) –

    The complete token-in / token-out engine response to derender.

  • model (str | None) –

    Served model name. Defaults to the server's served model name.

  • prompt_token_ids (list[NonNegativeInt] | None) –

    Prompt token IDs (GenerateRequest.token_ids from /render). Seeds

  • prompt_tokens (int | None) –

    Prompt token count for usage. If omitted, falls back to

chat_request = None class-attribute instance-attribute

The original (post-adjust_request) ChatCompletionRequest from /render.

Required by the parsing so that tool/reasoning parsers can receive the full request context they expect (request.tools, request.tool_choice, request._grammar_from_parser, etc.).

generate_response instance-attribute

The complete token-in / token-out engine response to derender.

Only output_mode="tokens" responses are accepted. Other modes are already detokenized and re-decoding their token_ids would undo the engine's stop string truncation.

model = None class-attribute instance-attribute

Served model name. Defaults to the server's served model name.

prompt_token_ids = None class-attribute instance-attribute

Prompt token IDs (GenerateRequest.token_ids from /render). Seeds detokenization from the prompt tail so the first output token keeps its leading space on SentencePiece tokenizers. Falls back to generate_response.prompt_token_ids, then to unseeded decoding.

With a tool or reasoning parser configured, the parser also reads these IDs when generate_response.prompt_token_ids is unset, so send the full list: parsers look back to the last reasoning marker, which can be anywhere in the prompt. Without a parser, only the last few IDs are read, so a suffix is enough.

prompt_tokens = None class-attribute instance-attribute

Prompt token count for usage. If omitted, falls back to generate_response.usage.prompt_tokens, then to 0.

DerenderChatStreamRequest

Bases: BaseModel

One chunk streaming derender request for /v1/chat/completions/derender.

The client sends one request per SSE chunk received from /inference/v1/generate. Each request carries the generate chunk plus the stream_state returned by the previous call (None on the first call). The response contains the derendered chunk and the updated state to be passed to the next call.

This implements stateless no server side session. All mutable state lives in the client carried stream_state.

Attributes:

chat_request = None class-attribute instance-attribute

The original (post adjust_request) ChatCompletionRequest from /render.

generate_chunk instance-attribute

One output_mode="tokens" SSE chunk from /inference/v1/generate (stream=True).

prompt_token_ids = None class-attribute instance-attribute

Prompt token IDs. Required by the parser path's parse_delta to settle its initial reasoning state (e.g. chat templates that pre-open <think>). prompt_tokens is a usage count and cannot serve this purpose. Sourced from GenerateRequest.token_ids at the render step.

Rejected with a 400 (by ServingDerender) when a tool or reasoning parser is configured and this is omitted. Without it, parse_delta cannot tell whether the prompt left reasoning open and would silently misclassify reasoning content as plain content. On all paths it also seeds detokenization on the first chunk, falling back to generate_chunk.prompt_token_ids when omitted (see DerenderChatRequest.prompt_token_ids).

With a parser configured, send the full list. Parsers look back to the last reasoning marker which can be anywhere in the prompt, so a suffix can flip the initial reasoning state. Without a parser, a suffix is enough.

prompt_tokens = None class-attribute instance-attribute

Prompt token count for usage. Forwarded from the render step.

stream_state = None class-attribute instance-attribute

Client carried detok state from the previous call. None on first.

DerenderChatStreamResponse

Bases: BaseModel

Response for one streaming chat derender chunk.

Pairs the derendered SSE chunk with the updated client carried state to pass to the next call.

DerenderCompletionRequest

Bases: BaseModel

Request for the /v1/completions/derender endpoint (non-streaming).

Parallel to DerenderChatRequest but handles the multi-prompt completions case: one GenerateResponse per prompt, mirroring the list[GenerateRequest] returned by /v1/completions/render.

Attributes:

  • completion_request (CompletionRequest | None) –

    The original (post-adjust_request) CompletionRequest from /render.

  • generate_responses (list[GenerateTokensResponse]) –

    One output_mode="tokens" response per prompt, parallel to the

  • model (str | None) –

    Served model name. Defaults to the server's served model name.

  • prompt_token_ids (list[list[NonNegativeInt] | None] | None) –

    One prompt token ID list per response, used to seed detokenization.

  • prompt_tokens (list[int] | None) –

    One prompt token count per response. If omitted, each falls back to

completion_request = None class-attribute instance-attribute

The original (post-adjust_request) CompletionRequest from /render.

Mirrors chat_request on DerenderChatRequest. Required by the parsing so parsers receive the full request context.

generate_responses instance-attribute

One output_mode="tokens" response per prompt, parallel to the list[GenerateRequest] returned by /v1/completions/render.

model = None class-attribute instance-attribute

Served model name. Defaults to the server's served model name.

prompt_token_ids = None class-attribute instance-attribute

One prompt token ID list per response, used to seed detokenization. See DerenderChatRequest.prompt_token_ids.

If provided, len(prompt_token_ids) must equal len(generate_responses). A None entry falls back to generate_responses[i].prompt_token_ids.

prompt_tokens = None class-attribute instance-attribute

One prompt token count per response. If omitted, each falls back to that response's usage.prompt_tokens, then to 0.

If provided, len(prompt_tokens) must equal len(generate_responses).

DerenderCompletionStreamRequest

Bases: BaseModel

One chunk streaming derender request for /v1/completions/derender.

Parallel to DerenderChatStreamRequest for the completions endpoint. Each call processes one SSE chunk (one output sequence's delta) and returns the derendered chunk plus updated state.

Attributes:

completion_request = None class-attribute instance-attribute

The original (post adjust_request) CompletionRequest from /render.

generate_chunk instance-attribute

One output_mode="tokens" SSE chunk from /inference/v1/generate.

prompt_token_ids = None class-attribute instance-attribute

Prompt token IDs, used on the first chunk to seed detokenization. Falls back to generate_chunk.prompt_token_ids. See DerenderChatRequest.prompt_token_ids.

prompt_tokens = None class-attribute instance-attribute

Prompt token count for usage.

stream_state = None class-attribute instance-attribute

Client-carried detok state. None on the first call.

DerenderCompletionStreamResponse

Bases: BaseModel

Response for one streaming completions derender chunk.

Parallel to DerenderChatStreamResponse for the completions endpoint.

DerenderStreamState

Bases: BaseModel

Per sequence state for stateless streaming derender.

The client carries this between successive per chunk HTTP calls to the streaming derender endpoint. All fields are plain JSON serializable data. No opaque tokenizer or parser internals are stored here.

Two separate sets of fields support two different streaming modes:

  • For plain streaming (no parser configured including the completions path): prev_token_ids, prefix_offset and read_offset maintain a bounded incremental decoding window. This requires O(window) transport and O(delta) computation per chunk.
  • For parser enabled chat streaming: output_token_ids, output_chunk_lens, tools_streamed and last_tool_call_ids are used to replay parse_delta() from scratch on every chunk because parser state cannot be serialized. This incurs O(n) transport per chunk (O(n²) per generation) and O(n²) parse_delta() calls per generation. Since many parsers re-scan the entire accumulated text on each invocation, parse_delta() itself is O(n) yielding a true worst case compute cost of O(n³) per generation. No caching is performed. Work is bounded by max_model_len. See OnlineDerenderer._derender_chat_stream_parsed.

The detokenization strategy carries the incremental decode offsets directly rather than re-sending the whole token history each chunk. detokenize_incrementally only ever reads the trailing token window from prefix_offset, so we carry just that tail, as ids because pieces may be raw bytes, plus the two offsets. Each chunk resumes exactly where the last one stopped, including any partially processed multi-byte character (tracked by read_offset), then trims and rebases the window so it never grows with generation length.

Performance: - Compute per chunk is O(delta). One detokenize_incrementally call per new token, independent of how many tokens preceded it. - Transport per chunk is O(window). The carried tail is bounded by the incremental detokenization offset, so cumulative bytes over the wire are O(n) rather than the O(n^2) a full history round trip would incur.

Attributes:

last_tool_call_ids = Field(default_factory=list) class-attribute instance-attribute

Stable tool call IDs, assigned once when each call first appears.

Indexed by tool call index. Parser path only. Prevents ID regeneration when replay reprocesses a tool call that already has a pinned ID.

logprob_context_token_ids = Field(default_factory=list, max_length=4) class-attribute instance-attribute

Trailing sampled token IDs carried across chunks so byte-fallback (U+FFFD) correction during logprob placeholder resolution has context at chunk boundaries. Bounded to the 4-token window that _correct_decoded_token reads.

logprob_text_offset = Field(default=0, ge=0) class-attribute instance-attribute

Cumulative length of reported logprob tokens, including special tokens. Seeds text_offset for completion streaming logprobs so offsets stay absolute across chunks, mirroring initial_text_offset in the generate streaming path.

output_chunk_lens = Field(default_factory=list) class-attribute instance-attribute

Token count of each chunk in output_token_ids. Parser path only.

Replay uses these to reproduce the original parse_delta call boundaries. Must sum to len(output_token_ids).

output_token_ids = Field(default_factory=list) class-attribute instance-attribute

All output tokens seen so far. Parser path only.

Replay buffer: each chunk rebuilds a fresh parser and replays every token in here through parse_delta (discarding the result) before processing the current chunk's tokens since parser internal state cannot be serialized into this stateless model. Unavoidably O(n) bounded by max_model_len (enforced server side, not by a field validator here since the bound is model dependent).

prefix_offset = Field(default=0, ge=0) class-attribute instance-attribute

Prefix offset into prev_token_ids for incremental detokenization.

prev_token_ids = Field(default_factory=list) class-attribute instance-attribute

Trailing decode window. Token ids from prefix_offset onward, excluding ids that skip_special_tokens drops.

Bounded, trimmed and rebased each chunk to the tail detokenize_incrementally still reads, so it does not grow with the number of chunks.

read_offset = Field(default=0, ge=0) class-attribute instance-attribute

Read offset into prev_token_ids for incremental detokenization.

role_sent = False class-attribute instance-attribute

True once the initial role delta (and any echo text) has been emitted.

Prevents re-emitting the role on subsequent chunks even when the detok window is transiently empty (e.g. usage only final chunk).

tools_streamed = False class-attribute instance-attribute

True once a tool call delta has been emitted. Parser path only.

Drives the finish_reason -> "tool_calls" rewrite on the final chunk mirroring the generate streaming path.

GenerateChoiceBase

Bases: BaseModel

Fields shared by every output_mode of a non-streaming choice.

GenerateDerenderChoice

Bases: GenerateChoiceBase

Attributes:

  • logprobs (ChatCompletionLogProbs | None) –

    Logprobs with decoded token strings and bytes. None when reasoning

  • message (ChatMessage) –

    Assistant message parsed from the output text.

logprobs = None class-attribute instance-attribute

Logprobs with decoded token strings and bytes. None when reasoning is hidden by include_reasoning=false.

message instance-attribute

Assistant message parsed from the output text.

GenerateDerenderStreamChoice

Bases: GenerateStreamChoiceBase

Attributes:

  • delta (DeltaMessage) –

    Parsed delta since the previous chunk of this choice.

  • logprobs (ChatCompletionLogProbs | None) –

    Logprobs with decoded token strings and bytes. None when reasoning

delta instance-attribute

Parsed delta since the previous chunk of this choice.

logprobs = None class-attribute instance-attribute

Logprobs with decoded token strings and bytes. None when reasoning is hidden by include_reasoning=false.

GenerateLogProb

Bases: BaseModel

A single (token, logprob) candidate on the generate wire protocol.

Unlike the OpenAI logprob shapes this carries the integer token id: the generate server has no tokenizer, so decoding to a string belongs in derender (or the coupled chat/completions path), not here.

GenerateLogProbs

Bases: BaseModel

Output logprobs for one choice.

content holds one entry per generated token.

GenerateLogProbsContent

Bases: GenerateLogProb

The sampled token at one position, plus its top-k candidates.

top_logprobs is a list, not a dict: JSON turns dict keys into strings and the order would be implicit. It is in the engine's order: the sampled token first, then the remaining candidates in rank order.

GenerateRequest

Bases: BaseModel

Methods:

Attributes:

content_parts = None class-attribute instance-attribute

Raw multimodal input; server resolves media and expands its placeholders. With features, these placeholders must follow the last features range, which is left as is.

features = None class-attribute instance-attribute

Multimodal hashes and placeholder positions (populated for MM inputs).

reasoning_ended = None class-attribute instance-attribute

Whether reasoning has ended before the first generated token, as resolved by /render. True applies structured outputs from the first token; None lets the engine check the prompt with its reasoning parser.

reasoning_parser_kwargs = None class-attribute instance-attribute

Set by /render when it has a reasoning parser, so the engine-side parser agrees with the frontend on flags such as enable_thinking.

sampling_params instance-attribute

The sampling parameters for the model.

token_ids = Field(min_length=1) class-attribute instance-attribute

The token ids to generate text from.

token_offsets = None class-attribute instance-attribute

Char-level (start, end) offsets per token, relative to the tokenized source string. Present only when the request set return_token_offsets=True and the renderer was able to compute them (Fast tokenizer, text input, no multimodal data). List length equals token_ids length when present. None otherwise.

_check_parse_context_fields()

Fail on fields from a newer /render only where they are read.

is_sampling_param_provided(name)

Whether the caller explicitly set sampling_params.<name>.

For requests parsed from a JSON body, this reflects the raw input dict. For requests constructed with a pre-built SamplingParams instance, all fields are considered provided so server-side defaults do not clobber values already resolved upstream.

GenerateResponseBase

Bases: BaseModel

Attributes:

mm_hashes = None class-attribute instance-attribute

Per-modality processor cache keys, parallel to mm_placeholders. Pass back with mm_placeholders as features to reuse the items without kwargs_data.

GenerateStreamChoiceBase

Bases: BaseModel

Fields shared by every output_mode of a streaming choice.

GenerateStreamResponseBase

Bases: BaseModel

Attributes:

mm_hashes = None class-attribute instance-attribute

Per-modality processor cache keys, parallel to mm_placeholders. Pass back with mm_placeholders as features to reuse the items without kwargs_data.

GenerateTextChoice

Bases: GenerateChoiceBase

Attributes:

  • logprobs (ChatCompletionLogProbs | None) –

    Logprobs with decoded token strings and bytes.

  • text (str) –

    Detokenized output. Excludes a matched stop string unless

logprobs = None class-attribute instance-attribute

Logprobs with decoded token strings and bytes.

text instance-attribute

Detokenized output. Excludes a matched stop string unless include_stop_str_in_output is set, while token_ids keeps every generated token.

GenerateTextStreamChoice

Bases: GenerateStreamChoiceBase

Attributes:

  • text (str) –

    Text delta since the previous chunk of this choice.

text instance-attribute

Text delta since the previous chunk of this choice.

GenerateTokensChoice

Bases: GenerateChoiceBase

Attributes:

logprobs = None class-attribute instance-attribute

Logprobs with integer token ids (no tokenizer on the generate server).

MultiModalFeatures

Bases: BaseModel

Lightweight multimodal metadata produced by the render step.

Carries hashes (for cache lookup / identification) and placeholder positions so the downstream /generate service knows where in the token sequence each multimodal item lives.

Methods:

Attributes:

kwargs_data = None class-attribute instance-attribute

Per-modality serialized tensor data.

Each value is a list parallel to mm_hashes[modality]. A str entry is a base64-encoded MultiModalKwargsItem; None means the item should be resolved from cache. The entire field is None for metadata-only (cache-hit) responses.

kwargs_refs = None class-attribute instance-attribute

Per-modality references to processed tensors in external storage.

Each value is a list parallel to mm_hashes[modality]. The server downloads each referenced SafeTensors object before engine submission. An item can set kwargs_data or kwargs_refs, but not both.

mm_hashes instance-attribute

Per-modality item hashes, e.g. {"image": ["abc", "def"]}.

mm_metadata = None class-attribute instance-attribute

Per-modality serialized metadata for disaggregated prefill.

Each value is a list parallel to mm_hashes[modality]. A str entry is a base64-encoded MultiModalKwargsItem containing only placeholder-metadata and keep_on_cpu fields. None means that the metadata is unavailable for that item. When neither kwargs_data nor kwargs_refs supplies tensors, the item needs EC transfer parameters for prefill or remote prefill KV transfer parameters for decode.

mm_placeholders instance-attribute

Per-modality placeholder ranges in the token sequence.

metadata_only_indices()

Identify layout-only items without inline or referenced tensors.

ParseContext

Bases: BaseModel

Chat request context the generate server needs to parse output.

Built by /render from the post-adjust_request chat request and read only when output_mode="derender". Unknown fields from a newer /render are kept so GenerateRequest can reject them only in that mode.

Methods:

  • to_chat_request –

    Build the message less chat request the parser reads.

Attributes:

chat_template_kwargs = Field(default_factory=dict) class-attribute instance-attribute

Template kwargs with the render server's defaults already applied, without the API server only entries a handler keeps out of the engine.

history_tool_call_cnt = Field(default=0, ge=0) class-attribute instance-attribute

Tool calls already in the rendered conversation, for sequential IDs.

to_chat_request()

Build the message less chat request the parser reads.

Built without the chat request validators: the Anthropic converter assigns tool fields that they would reject (e.g. tools: []) and the coupled path serves those as is.

Raises:

PlaceholderRangeInfo

Bases: BaseModel

Serializable placeholder location for a single multi-modal item.

Attributes:

  • is_embed (list[bool] | None) –

    Positions in the span that receive embeddings; None means all.

  • length (int) –

    Number of placeholder tokens.

  • offset (int) –

    Start index of the placeholder tokens in the prompt.

is_embed = None class-attribute instance-attribute

Positions in the span that receive embeddings; None means all.

length = Field(gt=0) class-attribute instance-attribute

Number of placeholder tokens.

offset = Field(ge=0) class-attribute instance-attribute

Start index of the placeholder tokens in the prompt.

ReasoningParserKwargs

Bases: BaseModel

Kwargs for the engine-side reasoning parser that gates structured outputs. Typed so clients cannot pass arbitrary constructor kwargs.

Attributes:

chat_template_kwargs = Field(default_factory=dict) class-attribute instance-attribute

The effective chat template kwargs the prompt was rendered with.

RenderedGenerateRequest

Bases: GenerateRequest

A GenerateRequest produced by /render.

Transfer parameters are supplied after rendering by the encode or prefill response, so a render with mm_payload="metadata" cannot have them yet. /inference/v1/generate still validates the request it receives as a GenerateRequest.

RenderedGenerateResponse dataclass

The JSON of a non-streaming GenerateResponse, as parts to send without joining them into one copy.

output_mode_or_tokens(value)

Discriminator for GenerateResponse and GenerateStreamResponse.

A missing output_mode means tokens. Existing clients and servers that predate the field never send it.