Skip to main content
The /v1/chat/completions endpoint generates a text completion based on a list of messages. It is the primary endpoint for chat, instruction-following, and text generation tasks. The request format is identical to the OpenAI Chat Completions API, so any OpenAI-compatible SDK works without modification.

Endpoint

Request

Headers

Body parameters

model
string
required
The model ID to use. See the Model Directory for all valid values. Example: "gpt-4o", "claude-sonnet-4-5", "gemini-2.5-flash".
messages
array
required
An array of message objects representing the conversation. Each object must have role ("system", "user", or "assistant") and content (string).
max_tokens
integer
Maximum number of tokens to generate. Defaults vary by model.
temperature
number
Sampling temperature between 0 and 2. Higher values produce more random output. Default: 1.
stream
boolean
If true, the response is returned as a stream of server-sent events (SSE). Default: false.
top_p
number
Nucleus sampling — only tokens in the top top_p probability mass are considered. Default: 1.
stop
string | array
One or more sequences where the model stops generating. Can be a string or an array of strings.
tools
array
A list of tool definitions for function calling. Each tool must have type: "function" and a function object with name, description, and parameters.
tool_choice
string | object
Controls tool selection: "none", "auto", "required", or a specific tool {"type": "function", "function": {"name": "..."}}.

Example request

Response

Response fields

id
string
Unique identifier for the completion.
choices
array
Array of generated completion choices.
usage
object
Token counts for billing.

Streaming

Set stream: true to receive a stream of SSE chunks. Each chunk has the same structure but with partial delta content instead of a full message:
python