Skip to content

vllm.entrypoints.openai.completion.serving

Classes:

OpenAIServingCompletion

Bases: GenerateBaseServing

Methods:

_create_completion_logprobs(token_ids, top_logprobs, num_output_top_logprobs, tokenizer, logprob_token_ids=None, initial_text_offset=0, return_as_token_id=None)

Create logprobs for OpenAI Completion API.

create_completion(request, raw_request=None) async

Completion API similar to OpenAI's API.

See https://platform.openai.com/docs/api-reference/completions/create for the API specification. This API mimics the OpenAI Completion API.

NOTE: suffix is only supported by models that implement FIM rendering.

render_completion_request(request) async

Validate the model and preprocess a completion request.

Delegates preprocessing logic to OnlineRenderer, adding the engine-aware checks (LoRA model validation, engine health).

Returns:

  • list[EngineInput] | ErrorResponse –

    A list of engine_inputs on success, or an ErrorResponse on failure.

_delta_frame_template(request_id, created_time, model_name)

Split a probe chunk into the parts of a plain-delta SSE frame that are constant for a stream, so only index and text are rendered per chunk.

Taking them from the serializer keeps frames byte-identical to model_dump_json(exclude_unset=True) if the models gain fields.

Returns:

  • tuple[str, str, str] | None –

    (prefix, infix, suffix), or None if the sentinels are ambiguous.

_get_echoed_prompt_logprobs(prompt_token_ids, prompt_logprobs, echo_mask)

Select visible prompt IDs and logprobs without changing engine inputs.

_padded_prompt_logprobs(prompt_logprobs, num_prompt_tokens)

One entry per prompt token; a request aborted mid-prefill has logprobs only for the prompt tokens it processed, or none.