/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
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".array
required
An array of message objects representing the conversation. Each object must have
role ("system", "user", or "assistant") and content (string).integer
Maximum number of tokens to generate. Defaults vary by model.
number
Sampling temperature between 0 and 2. Higher values produce more random output. Default: 1.
boolean
If
true, the response is returned as a stream of server-sent events (SSE). Default: false.number
Nucleus sampling — only tokens in the top
top_p probability mass are considered. Default: 1.string | array
One or more sequences where the model stops generating. Can be a string or an array of strings.
array
A list of tool definitions for function calling. Each tool must have
type: "function" and a function object with name, description, and parameters.string | object
Controls tool selection:
"none", "auto", "required", or a specific tool {"type": "function", "function": {"name": "..."}}.Example request
Response
Response fields
string
Unique identifier for the completion.
array
Array of generated completion choices.
object
Token counts for billing.
Streaming
Setstream: 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