Skip to content

vllm.entrypoints.openai.chat_completion.protocol

Classes:

BatchChatCompletionRequest

Bases: OpenAIBaseModel

Request model for the /v1/chat/completions/batch endpoint.

Accepts the same fields as ChatCompletionRequest except that messages is a list of conversations (each conversation is a list[ChatCompletionMessageParam]). Each conversation is processed independently and the response contains one choice per conversation, indexed 0, 1, ..., N-1.

Current limitations compared to the single-conversation endpoint: - Streaming is not supported (stream must be False or omitted). - Tool use is not supported (tools must be omitted). - Beam search is not supported (use_beam_search must be False or omitted). - The n parameter must be 1 (or omitted).

Methods:

to_chat_completion_request(messages)

Build a single-conversation ChatCompletionRequest from one conversation.

ChatCompletionRequest

Bases: OpenAIBaseModel

Methods:

_grammar_from_parser = PrivateAttr(default=False) class-attribute instance-attribute

CAUTION: Should only be set by the parser-engine adapter's adjust_request.

_materialize_tool_calls_after()

Convert Pydantic ValidatorIterator wrappers back to lists.

Even after the "before" validator converts iterables to lists, Pydantic re-wraps them in a ValidatorIterator when validating against ChatCompletionAssistantMessageParam's Iterable[...] type. This "after" pass materialises those wrappers so downstream code (tokenizers, model_dump_json) always sees plain lists.

_normalize_messages_before(data) classmethod

Pre-process message dicts before Pydantic field validation.

Performs two normalizations in a single pass: - Converts tool_calls generators/iterators to lists so one-shot generators are not consumed during union type matching. - Renames the deprecated reasoning_content field to reasoning so downstream code only needs to check one field.

check_system_message_content_type(data) classmethod

Warn if system messages contain non-text content.

According to OpenAI API spec, system messages can only be of type 'text'. We log a warning instead of rejecting to avoid breaking users who intentionally send multimodal system messages. See: https://platform.openai.com/docs/api-reference/chat/create#chat_create-messages-system_message

extract_structured_outputs()

Normalize request constraints into StructuredOutputsParams.

resolve_reasoning_ended(parser, prompt_token_ids)

Resolve the engine's reasoning_ended for structured outputs.

Call after adjust_request, which may set _grammar_from_parser. True constrains from the first generated token; None lets the engine check the prompt with its own reasoning parser.

_coerce_tool_calls_to_list(tool_calls)

Materialize one-shot tool_calls iterators without crashing on bad types.

Generators must be converted to lists before union-type matching, but list() on a non-iterable scalar (for example tool_calls: 1) raises TypeError, which escapes Pydantic as an HTTP 500. Non-iterable scalars are surfaced so field validation can reject them (400). Strings and mappings are left to field validation, and handling of empty string/object — normalized to [] — is unchanged by this patch.