Skip to main content
The /v1/chat/completions endpoint generates a response for a conversation. It supports streaming via SSE, tool/function calls, and structured JSON output. It is the primary endpoint for all chat-based interactions and the recommended choice for new integrations.

Endpoint

Request Body

string
required
Model slug to use for the request, e.g. llama-3.3-70b-instruct. See Models for all available slugs.
array
required
Array of message objects that make up the conversation. Each object contains:
  • role"system", "user", or "assistant"
  • content — the message text as a string
boolean
When true, responses are streamed as server-sent events (SSE). The stream ends with data: [DONE]. Default: false.
number
Sampling temperature between 0 and 2. Lower values produce more deterministic output; higher values increase creativity. Default: 1.
integer
Maximum number of tokens to generate in the response. If omitted, the model generates until it reaches a natural stopping point or its context limit.
number
Nucleus sampling probability mass. Only tokens comprising the top top_p probability are considered. Default: 1.
string | array
One or more sequences at which generation stops. The model halts as soon as any sequence in the list is encountered.
array
List of tools the model may call. Each entry has type: "function" and a function object containing name, description, and a JSON Schema parameters object.
string | object
Controls whether and how tools are used. Accepts "auto" (model decides), "none" (no tool calls), or an object targeting a specific function:
object
Set to {"type": "json_object"} to enable JSON mode. The model is constrained to emit valid JSON.
integer
Number of completion choices to generate. Default: 1.

Example Request

Example Response

string
Unique identifier for the completion. Use this for logging and tracing.
string
The generated text from the assistant for this choice.
string
Reason generation stopped. Common values: "stop" (natural end or stop sequence hit), "length" (max_tokens reached), "tool_calls" (model invoked a tool).
integer
Number of tokens in the input messages.
integer
Number of tokens generated in the response.

Streaming

Set "stream": true to receive the response as a sequence of server-sent events. Each chunk contains a partial delta, and the stream terminates with data: [DONE].
Each server-sent event looks like:
Concatenate the delta.content values from each chunk to reconstruct the full response.