Create Chat Completion
Send a conversation to any Router model using the OpenAI Chat Completions schema. Set stream: true to receive server-sent events; add stream_options: {"include_usage": true} to get token usage in the final chunk.
400 naming the parameter.Parameter support
Parameter support
model, messages, stream, stream_options.include_usage, max_completion_tokens, max_tokens, temperature, top_p, stop, reasoning_effort, service_tier (auto, default, flex, priority), response_format (text, json_schema, json_object), tools, tool_choice (including allowed_tools), parallel_tool_calls, prompt_cache_key, prompt_cache_options, prompt_cache_retention, and message-part prompt_cache_breakpoint fields.Accepted but not forwarded to the model: user, safety_identifier, metadata.Accepted only at their default values: n (1), logprobs (false), store (false), presence_penalty (0), frequency_penalty (0).Rejected with a 400: seed, logit_bias, top_logprobs, functions (use tools), function_call (use tool_choice), modalities, audio, prediction, web_search_options, moderation, verbosity, stream_options.include_obfuscation set to true, plus any unrecognized top-level field.Notes: When reasoning_effort is omitted, the provider’s default for that model applies; defaults vary by provider and model. response_format.json_schema always runs in strict mode. Assistant messages and streamed deltas can include reasoning_content; replay it in an assistant message to preserve reasoning context across requests. Function tools require a description.Errors
Errors
type is invalid_request_error for 4xx errors, rate_limit_error for 429 (rate limited or model overloaded — retry after the Retry-After interval), and server_error for 5xx. Requests that fail before producing output are not billed.Authorizations
Your Perplexity API key.
Body
The conversation so far, as an array of message objects with role and content. The leading system or developer message is applied as the system prompt.
1- Developer message
- System message
- User message
- Assistant message
- Tool message
- Function message
The model that will process the request, as a creator/model-name id from the catalog — for example perplexity/kimi-k3. Any cataloged model works with this endpoint.
"perplexity/kimi-k3"
Accepted for SDK compatibility; not forwarded to the model.
Sampling temperature, 0 to 2. Higher values produce more varied output. Adjust this or top_p, not both.
0 <= x <= 21
Nucleus-sampling threshold, 0 to 1. Adjust this or temperature, not both.
0 <= x <= 11
Accepted for SDK compatibility; not forwarded to the model.
"user-1234"
Accepted for SDK compatibility; not forwarded to the model.
64"safety-identifier-1234"
Stable key grouping related requests to improve prompt-cache hit rates.
"prompt-cache-key-1234"
Processing tier for the request. flex halves token rates on supported models; auto and default are equivalent.
auto, default, flex, scale, priority Deprecated cache-retention setting. Use prompt_cache_options.ttl for new integrations.
in_memory, 24h Prompt-cache settings. Set ttl to 5m, 1h, or 24h to control cache retention.
How much reasoning the model performs before answering, on models that support it. When omitted, the provider's default for that model applies; defaults vary by provider and model.
none, minimal, low, medium, high, xhigh, max Upper bound on generated tokens for this request, including reasoning tokens.
Output format. Use type json_schema for strict structured output or json_object for JSON mode.
- Text
- JSON schema
- JSON object
When true, tokens are sent as server-sent events as they are generated, terminated by data: [DONE].
Up to 4 sequences at which generation stops.
"\n"
Legacy alias of max_completion_tokens.
Streaming options. Only allowed when stream is true.
Function tools the model may call. Every tool requires a description.
- Function tool
- Custom tool
Controls whether the model may call tools, requires a specific tool, or limits selection with allowed_tools.
none, auto, required Whether the model may request more than one tool call in a single turn.
Response
Successful response. JSON for non-streaming requests; a text/event-stream of chat completion chunks terminated by data: [DONE] when stream is true.
Unique identifier for the completion.
The completion. Contains exactly one choice.
Unix timestamp of when the completion was created.
The model id you requested. Billing always uses this model's published rates.
Always "chat.completion".
chat.completion The processing tier that served the request.
auto, default, flex, scale, priority Token accounting for the request.