POST
/chat/completionsCreate a chat completion
Creates a model response for a given chat conversation. Supply a list of messages and a model identifier at minimum. Supports text, images, and audio modalities depending on the model. Returns a chat completion object or a stream of completion chunks if streaming is enabled. A 429 response indicates the request was rate-limited.
- IdempotentThe SDK sends
Idempotency-Key, so a retried request is only applied once.
Chat completion request configuration. messages and model are required.
metadataobjectoptional
Optional set of key-value pairs for storing additional information about the completion.
top_logprobsintegeroptional
An integer between 0 and 20 specifying the maximum number of most likely
tokens to return at each token position, each with an associated log
probability. In some cases, the number of returned tokens may be fewer than
requested.
`logprobs` must be set to `true` if this parameter is used.
temperaturenumberoptional
Sampling temperature controlling randomness. Higher values increase randomness.
top_pnumberoptional
Nucleus sampling parameter. Controls diversity via cumulative probability.
userstringdeprecatedoptional
This field is being replaced by `safety_identifier` and `prompt_cache_key`. Use `prompt_cache_key` instead to maintain caching optimizations.
A stable identifier for your end-users.
Used to boost cache hit rates by better bucketing similar requests and to help OpenAI detect and prevent abuse. [Learn more](/docs/guides/safety-best-practices#safety-identifiers).
safety_identifierstringoptional
Optional safety identifier for the request.
prompt_cache_keystringoptional
Optional key for prompt caching.
prompt_cache_retentionstringdeprecatedoptional
Optional retention policy for cached prompts.
prompt_cache_optionsobjectoptional
Options for prompt caching. Supported for `gpt-5.6` and later models. By default, OpenAI automatically chooses one implicit cache breakpoint. You can add explicit breakpoints to content blocks with `prompt_cache_breakpoint`. Each request can write up to four breakpoints. For cache matching, OpenAI considers up to the latest 80 breakpoints in the conversation, without a content-block lookback limit. Set `mode` to `explicit` to disable the implicit breakpoint. The `ttl` defaults to `30m`, which is currently the only supported value. See the [prompt caching guide](/docs/guides/prompt-caching) for current details.
messagesarray<DeveloperMessage>required
A list of messages comprising the conversation so far. Depending on the
[model](/docs/models) you use, different message types (modalities) are
supported, like [text](/docs/guides/text-generation),
[images](/docs/guides/vision), and [audio](/docs/guides/audio).
modelstringrequired
Model ID used to generate the response, like `gpt-5.6-sol` or `o3`. OpenAI
offers a wide range of models with different capabilities, performance
characteristics, and price points. Refer to the [model guide](/docs/models)
to browse and compare available models.
service_tierstringoptional
Optional service tier for the request. Defaults to auto if omitted.
modalitiesarray<string>optional
Optional list of output modalities, such as `text` or `audio`. Defaults to text if omitted.
verbositystringoptional
Optional verbosity level for reasoning models. Controls the detail of reasoning output.
reasoning_effortstringoptional
Optional reasoning effort level for reasoning models: `low`, `medium`, or `high`.
max_completion_tokensintegeroptional
An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and [reasoning tokens](/docs/guides/reasoning).
frequency_penaltynumberoptional
Number between -2.0 and 2.0. Positive values penalize new tokens based on
their existing frequency in the text so far, decreasing the model's
likelihood to repeat the same line verbatim.
presence_penaltynumberoptional
Number between -2.0 and 2.0. Positive values penalize new tokens based on
whether they appear in the text so far, increasing the model's likelihood
to talk about new topics.
web_search_optionsobjectoptional
This tool searches the web for relevant results to use in a response.
Learn more about the [web search tool](/docs/guides/tools-web-search?api-mode=chat).
response_formatobjectoptional
An object specifying the format that the model must output.
Setting to `{ "type": "json_schema", "json_schema": {...} }` enables
Structured Outputs which ensures the model will match your supplied JSON
schema. Learn more in the [Structured Outputs
guide](/docs/guides/structured-outputs).
Setting to `{ "type": "json_object" }` enables the older JSON mode, which
ensures the message the model generates is valid JSON. Using `json_schema`
is preferred for models that support it.
audioobjectoptional
Parameters for audio output. Required when audio output is requested with
`modalities: ["audio"]`. [Learn more](/docs/guides/audio).
storebooleanoptional
Whether or not to store the output of this chat completion request for
use in our [model distillation](/docs/guides/distillation) or
[evals](/docs/guides/evals) products.
Supports text and image inputs. Note: image inputs over 8MB will be dropped.
moderationobjectoptional
Optional moderation configuration for the request.
streambooleanoptional
If set to true, the model response data will be streamed to the client
as it is generated using [server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#Event_stream_format).
See the [Streaming section below](/docs/api-reference/chat/streaming)
for more information, along with the [streaming responses](/docs/guides/streaming-responses)
guide for more information on how to handle the streaming events.
stopstringoptional
Not supported with latest reasoning models `o3` and `o4-mini`.
Up to 4 sequences where the API will stop generating further tokens. The
returned text will not contain the stop sequence.
logit_biasobjectoptional
Modify the likelihood of specified tokens appearing in the completion.
Accepts a JSON object that maps tokens (specified by their token ID in the
tokenizer) to an associated bias value from -100 to 100. Mathematically,
the bias is added to the logits generated by the model prior to sampling.
The exact effect will vary per model, but values between -1 and 1 should
decrease or increase likelihood of selection; values like -100 or 100
should result in a ban or exclusive selection of the relevant token.
logprobsbooleanoptional
Whether to return log probabilities of the output tokens or not. If true,
returns the log probabilities of each output token returned in the
`content` of `message`.
max_tokensintegerdeprecatedoptional
The maximum number of [tokens](/tokenizer) that can be generated in the
chat completion. This value can be used to control
[costs](https://openai.com/api/pricing/) for text generated via API.
This value is now deprecated in favor of `max_completion_tokens`, and is
not compatible with [o-series models](/docs/guides/reasoning).
nintegeroptional
How many chat completion choices to generate for each input message. Note that you will be charged based on the number of generated tokens across all of the choices. Keep `n` as `1` to minimize costs.
predictionobjectoptional
Configuration for a [Predicted Output](/docs/guides/predicted-outputs),
which can greatly improve response times when large parts of the model
response are known ahead of time. This is most common when you are
regenerating a file with only minor changes to most of the content.
seedintegerdeprecatedoptional
This feature is in Beta.
If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same `seed` and parameters should return the same result.
Determinism is not guaranteed, and you should refer to the `system_fingerprint` response parameter to monitor changes in the backend.
stream_optionsobjectoptional
Options for streaming response. Only set this when you set `stream: true`.
toolsarray<FunctionTool>optional
A list of tools the model may call. You can provide either
[custom tools](/docs/guides/function-calling#custom-tools) or
[function tools](/docs/guides/function-calling).
tool_choicestringoptional
Controls which (if any) tool is called by the model.
`none` means the model will not call any tool and instead generates a message.
`auto` means the model can pick between generating a message or calling one or more tools.
`required` means the model must call one or more tools.
Specifying a particular tool via `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool.
`none` is the default when no tools are present. `auto` is the default if tools are present.
parallel_tool_callsbooleanoptional
Whether to enable [parallel function calling](/docs/guides/function-calling#configuring-parallel-function-calling) during tool use.
function_callstringdeprecatedoptional
Deprecated in favor of `tool_choice`.
Controls which (if any) function is called by the model.
`none` means the model will not call a function and instead generates a
message.
`auto` means the model can pick between generating a message or calling a
function.
Specifying a particular function via `{"name": "my_function"}` forces the
model to call that function.
`none` is the default when no functions are present. `auto` is the default
if functions are present.
functionsarray<object>deprecatedoptional
Deprecated in favor of `tools`.
A list of functions the model may generate JSON inputs for.
200Returns a chat completion object with the model's response, usage statistics, and metadata. If streaming is enabled, returns a stream of chat completion chunk objects.
idstringrequired
A unique identifier for the chat completion.
choicesarray<object>required
A list of chat completion choices. Can be more than one if `n` is greater than 1.
createdintegerrequired
The Unix timestamp (in seconds) of when the chat completion was created.
modelstringrequired
The model used for the chat completion.
metadataobjectoptional
Set of 16 key-value pairs that can be attached to an object. This can be
useful for storing additional information about the object in a structured
format, and querying for objects via API or the dashboard.
Keys are strings with a maximum length of 64 characters. Values are strings
with a maximum length of 512 characters.
service_tierstringoptional
Specifies the processing type used for serving the request.
- If set to 'auto', then the request will be processed with the service tier configured in the Project settings. Unless otherwise configured, the Project will use 'default'.
- If set to 'default', then the request will be processed with the standard pricing and performance for the selected model.
- If set to '[flex](/docs/guides/flex-processing)', then the request will be processed with the Flex Processing service tier.
- To opt-in to [Fast mode](/api/docs/guides/fast-mode) at the request level, include the `service_tier=fast` or `service_tier=priority` parameter for Responses or Chat Completions. The response will show `service_tier=priority` regardless of if you specify `service_tier=fast` or `priority` in your request.
- When not set, the default behavior is 'auto'.
When the `service_tier` parameter is set, the response body will include the `service_tier` value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.
system_fingerprintstringdeprecatedoptional
This fingerprint represents the backend configuration that the model runs with.
Can be used in conjunction with the `seed` request parameter to understand when backend changes have been made that might impact determinism.
objectstringrequired
The object type, which is always `chat.completion`.
usageobjectoptional
Usage statistics for the completion request.
moderationobjectoptional
Moderation results for the request input and generated output, if moderated
completions were requested.
429Returned when the request exceeds the rate limit. Retry after a delay.
errorobjectrequired
Error handling
messages and model are both required. messages must be a non-empty array. max_completion_tokens must be a positive integer if provided. frequency_penalty and presence_penalty must each be between -2.0 and 2.0. top_logprobs must be between 0 and 20 if provided. A 429 is returned when the request exceeds the rate limit — retry after a delay.