Skip to main content
POST
Create Chat Completion
The Gateway API accepts the OpenAI Chat Completions schema, with a defined subset of parameters. Requests using an unsupported parameter fail with a 400 naming the parameter.
Honored: 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 use the OpenAI envelope:
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

Authorization
string
header
required

Your Perplexity API key.

Body

application/json
messages
(Developer message · object | System message · object | User message · object | Assistant message · object | Tool message · object | Function message · object)[]
required

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.

Minimum array length: 1
model
required

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.

Example:

"gpt-5.4"

metadata
object | null

Accepted for SDK compatibility; not forwarded to the model.

temperature
number | null
default:1

Sampling temperature, 0 to 2. Higher values produce more varied output. Adjust this or top_p, not both.

Required range: 0 <= x <= 2
Example:

1

top_p
number | null
default:1

Nucleus-sampling threshold, 0 to 1. Adjust this or temperature, not both.

Required range: 0 <= x <= 1
Example:

1

user
string
deprecated

Accepted for SDK compatibility; not forwarded to the model.

Example:

"user-1234"

safety_identifier
string | null

Accepted for SDK compatibility; not forwarded to the model.

Maximum string length: 64
Example:

"safety-identifier-1234"

prompt_cache_key
string | null

Stable key grouping related requests to improve prompt-cache hit rates.

Example:

"prompt-cache-key-1234"

service_tier
enum<string> | null
default:auto

Processing tier for the request. flex halves token rates on supported models; auto and default are equivalent.

Available options:
auto,
default,
flex,
scale,
priority
reasoning_effort
enum<string> | null
default:medium

How much reasoning the model performs before answering, on models that support it.

Available options:
none,
minimal,
low,
medium,
high,
xhigh,
max
max_completion_tokens
integer | null

Upper bound on generated tokens for this request, including reasoning tokens.

response_format
Text · object

Output format. Use type json_schema for structured output; schemas always run in strict mode.

stream
boolean | null
default:false

When true, tokens are sent as server-sent events as they are generated, terminated by data: [DONE].

stop
default:<|endoftext|>

Up to 4 sequences at which generation stops.

Example:

"\n"

max_tokens
integer | null
deprecated

Legacy alias of max_completion_tokens.

stream_options
object | null

Streaming options. Only allowed when stream is true.

tools
(Function tool · object | Custom tool · object)[]

Function tools the model may call. Every tool requires a description.

tool_choice

Controls whether the model may call a tool, and which one.

Available options:
none,
auto,
required
parallel_tool_calls
boolean
default:true

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.

id
string
required

Unique identifier for the completion.

choices
object[]
required

The completion. Contains exactly one choice.

created
integer<unixtime>
required

Unix timestamp of when the completion was created.

model
string
required

The model id you requested. Billing always uses this model's published rates.

object
enum<string>
required

Always "chat.completion".

Available options:
chat.completion
service_tier
enum<string> | null
default:auto

The processing tier that served the request.

Available options:
auto,
default,
flex,
scale,
priority
system_fingerprint
string
deprecated
usage
object

Token accounting for the request.

moderation
object