Skip to main content

Chat Completions

The chat completions endpoint generates responses in a conversational format. This endpoint is compatible with OpenAI’s /v1/chat/completions API.

Request

Parameters

Required

array
required
Array of message objects in the conversation.
string
required
Role of the message sender: system, user, assistant, tool, function, or developer.
string | array
required
Message content. Can be:
  • A string for text-only messages
  • An array of content parts for multimodal messages:
    • {"type": "text", "text": "..."}
    • {"type": "image_url", "image_url": {"url": "..."}}
    • {"type": "video_url", "video_url": {"url": "..."}}
    • {"type": "audio_url", "audio_url": {"url": "..."}}
string
Name of the message sender.
array
Tool calls made by the assistant (for assistant messages).
string
ID of the tool call this message is responding to (for tool messages).
string
required
Model name. Supports LoRA adapters via base-model:adapter-name syntax.

Sampling Parameters

integer
Maximum number of tokens to generate. Replaces deprecated max_tokens.
integer
Deprecated: Use max_completion_tokens instead.
number
default:"1.0"
Sampling temperature between 0 and 2. Higher values make output more random.
number
default:"1.0"
Nucleus sampling threshold.
integer
Only sample from the top K tokens.
number
Minimum probability threshold for sampling.
integer
default:"1"
Number of chat completion choices to generate.
integer
Random seed for deterministic generation.
string | array
Stop sequences.
array
Stop token IDs.

Penalization

number
default:"0.0"
Penalizes tokens based on frequency. Range: [-2.0, 2.0].
number
default:"0.0"
Penalizes tokens based on presence. Range: [-2.0, 2.0].
number
default:"1.0"
Penalizes repeated tokens.

Structured Output

object
Format of the response:
  • {"type": "text"} - Plain text (default)
  • {"type": "json_object"} - Valid JSON object
  • {"type": "json_schema", "json_schema": {...}} - JSON matching schema
string
Regular expression for constrained generation.
string
EBNF grammar for constrained generation.

Tools & Function Calling

array
List of tools available to the model.
string
Always "function".
object
Function definition.
string
Function name.
string
Function description.
object
JSON schema for function parameters.
boolean
default:"false"
Whether to enforce strict schema validation.
string | object
default:"auto"
Controls tool usage:
  • auto: Model decides whether to call tools
  • none: Model will not call tools
  • required: Model must call at least one tool
  • {"type": "function", "function": {"name": "..."}}: Force specific tool

Logging & Debugging

boolean
default:"false"
Whether to return log probabilities.
integer
Number of top log probabilities to return (requires logprobs=true).
object
Bias certain tokens. Maps token IDs to bias values between -100 and 100.

Streaming

boolean
default:"false"
Whether to stream the response.
object
Streaming options:
  • include_usage: Include usage statistics in final chunk
  • continuous_usage_stats: Include usage stats in each chunk

Multimodal

integer
Maximum number of dynamic patches for vision models.
integer
Minimum number of dynamic patches for vision models.

Reasoning Models

string
default:"medium"
Constrains reasoning effort for reasoning models:
  • low: Least effort, faster responses
  • medium: Balanced effort
  • high: Most effort, more thorough reasoning
Currently only supported for OpenAI models in harmony path (GPT-OSS models).
boolean
default:"true"
Separate reasoning content from final response.
boolean
default:"true"
Stream reasoning tokens during generation.

SGLang Extensions

boolean
default:"false"
Continue generation even after EOS token.
boolean
default:"true"
Whether to skip special tokens in output.
boolean
default:"false"
Do not trim stop sequences from output.
string | array
Regular expression(s) to use as stop conditions.
integer
default:"0"
Minimum number of tokens to generate.
boolean
default:"false"
Continue from the last assistant message.
string
Path to LoRA adapter weights.
object
Additional kwargs to pass to the chat template.
string
Custom logit processor for advanced sampling control.
boolean
default:"false"
Return hidden states from the model.
boolean
default:"false"
Return expert routing information for MoE models.
boolean
default:"false"
Return detailed cache hit information.

Response

string
Unique identifier for the chat completion.
string
Always "chat.completion".
integer
Unix timestamp of creation time.
string
Model used for generation.
array
Array of chat completion choices.
integer
Choice index.
object
The generated message.
string
Role of the message (usually "assistant").
string | null
Message content.
string | null
Reasoning content for reasoning models.
array | null
Tool calls made by the model.
string
Tool call ID.
string
Always "function".
object
string
Function name.
string
Function arguments as JSON string.
object | null
Log probability information.
array
Log probabilities for each token.
string
The token.
number
Log probability of the token.
array
UTF-8 bytes of the token.
array
Top alternative tokens and their log probabilities.
string
Reason for completion end:
  • stop: Natural stop or stop sequence
  • length: Max tokens reached
  • tool_calls: Model called a tool
  • content_filter: Content filtering
  • abort: Request aborted
integer | string | null
The stop sequence that was matched.
object
Token usage statistics.
integer
Tokens in the prompt.
integer
Tokens in the completion.
integer
Total tokens used.
object
integer
Number of cached tokens.
integer
Tokens used for reasoning (reasoning models).
object
SGLang-specific extensions.
string
Expert routing information for MoE models.
object
Detailed cache information.
integer
Tokens from GPU cache.
integer
Tokens from CPU cache.
integer
Tokens from storage backend.
string
Storage backend type.

Streaming Response

When stream=true, responses are sent as Server-Sent Events:

Examples

Basic Chat

Streaming Chat

Function Calling

JSON Output

Multimodal (Vision)

See Also