Create Chat Completion
Send a conversation to any Gateway 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), tools, tool_choice, parallel_tool_calls, prompt_cache_key.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, prompt_cache_options, prompt_cache_retention, stream_options.include_obfuscation set to true, plus any unrecognized top-level field.Notes: response_format.json_schema always runs in strict mode; json_object is not supported — use json_schema. 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 anthropic/claude-sonnet-5. Any cataloged model works with this endpoint.
"gpt-5.4"
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 How much reasoning the model performs before answering, on models that support it.
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 structured output; schemas always run in strict 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 a tool, and which one.
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.