Create chat completion
Starting a new project? We recommend trying Responses to take advantage of the latest OpenAI platform features. Compare Chat Completions with Responses.
Creates a model response for the given chat conversation. Learn more in the text generation, vision, and audio guides.
Parameter support can differ depending on the model used to generate the response, particularly for newer reasoning models. Parameters that are only supported for reasoning models are noted below. For the current state of unsupported parameters in reasoning models, refer to the reasoning guide.
Request body
metadataobject or null
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.temperaturenumber or nullDefaults: 1
What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or
top_pbut not both.top_pnumber or nullDefaults: 1
An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered.
We generally recommend altering this or
temperaturebut not both.userstring
A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. Learn more.
service_tierstring or nullDefaults: auto
Specifies the latency tier to use for processing the request. This parameter is relevant for customers subscribed to the scale tier service:
- If set to 'auto', and the Project is Scale tier enabled, the system will utilize scale tier credits until they are exhausted.
- If set to 'auto', and the Project is not Scale tier enabled, the request will be processed using the default service tier with a lower uptime SLA and no latency guarentee.
- If set to 'default', the request will be processed using the default service tier with a lower uptime SLA and no latency guarentee.
- If set to 'flex', the request will be processed with the Flex Processing service tier. Learn more.
- When not set, the default behavior is 'auto'.
When this parameter is set, the response body will include the
service_tierutilized.autostring
defaultstring
flexstring
messagesarrayRequired
A list of messages comprising the conversation so far. Depending on the model you use, different message types (modalities) are supported, like text, images, and audio.
Developer messageobject
Developer-provided instructions that the model should follow, regardless of messages sent by the user. With o1 models and newer,
developermessages replace the previoussystemmessages.contentstring or array
The contents of the developer message.Text contentstringRequired
The contents of the developer message.Array of content partsarrayRequired
An array of content parts with a defined type. For developer messages, only type
textis supported.itemsobject
Learn about text inputs.
typestringRequired
The type of the content part.textstring
textstringRequired
The text content.
rolestringRequired
The role of the messages author, in this case
developer.developerstring
namestring
An optional name for the participant. Provides the model information to differentiate between participants of the same role.
System messageobject
Developer-provided instructions that the model should follow, regardless of messages sent by the user. With o1 models and newer, use
developermessages for this purpose instead.contentstring or array
The contents of the system message.Text contentstringRequired
The contents of the system message.Array of content partsarrayRequired
An array of content parts with a defined type. For system messages, only type
textis supported.Text content partobject
Learn about text inputs.
typestringRequired
The type of the content part.textstring
textstringRequired
The text content.
rolestringRequired
The role of the messages author, in this case
system.systemstring
namestring
An optional name for the participant. Provides the model information to differentiate between participants of the same role.
User messageobject
Messages sent by an end user, containing prompts or additional context information.contentstring or array
The contents of the user message.Text contentstringRequired
The text contents of the message.Array of content partsarrayRequired
An array of content parts with a defined type. Supported options differ based on the model being used to generate the response. Can contain text, image, or audio inputs.
Text content partobject
Learn about text inputs.
typestringRequired
The type of the content part.textstring
textstringRequired
The text content.
Image content partobject
Learn about image inputs.
typestringRequired
The type of the content part.image_urlstring
image_urlobjectRequired
urlstringRequired
Either a URL of the image or the base64 encoded image data.detailstringDefaults: auto
Specifies the detail level of the image. Learn more in the Vision guide.
autostring
lowstring
highstring
Audio content partobject
Learn about audio inputs.
typestringRequired
The type of the content part. Always
input_audio.input_audiostring
input_audioobjectRequired
datastringRequired
Base64 encoded audio data.formatstringRequired
The format of the encoded audio data. Currently supports "wav" and "mp3".wavstring
mp3string
File content partobject
Learn about file inputs for text generation.
typestringRequired
The type of the content part. Always
file.filestring
fileobjectRequired
filenamestring
The name of the file, used when passing the file to the model as a string.file_datastring
The base64 encoded file data, used when passing the file to the model as a string.file_idstring
The ID of an uploaded file to use as input.
rolestringRequired
The role of the messages author, in this case
user.userstring
namestring
An optional name for the participant. Provides the model information to differentiate between participants of the same role.
Assistant messageobject
Messages sent by the model in response to user messages.contentstring or array
The contents of the assistant message. Required unless
tool_callsorfunction_callis specified.Text contentstring
The contents of the assistant message.Array of content partsarray
An array of content parts with a defined type. Can be one or more of type
text, or exactly one of typerefusal.Text content partobject
Learn about text inputs.
typestringRequired
The type of the content part.textstring
textstringRequired
The text content.
Refusal content partobject
typestringRequired
The type of the content part.refusalstring
refusalstringRequired
The refusal message generated by the model.
refusalstring or null
The refusal message by the assistant.rolestringRequired
The role of the messages author, in this case
assistant.assistantstring
namestring
An optional name for the participant. Provides the model information to differentiate between participants of the same role.audioobject or null
Data about a previous audio response from the model. Learn more.
idstringRequired
Unique identifier for a previous audio response from the model.
tool_callsarray
The tool calls generated by the model, such as function calls.itemsobject
idstringRequired
The ID of the tool call.typestringRequired
The type of the tool. Currently, only
functionis supported.functionstring
functionobjectRequired
The function that the model called.namestringRequired
The name of the function to call.argumentsstringRequired
The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.
function_callobject or nullDeprecated
Deprecated and replaced by
tool_calls. The name and arguments of a function that should be called, as generated by the model.argumentsstringRequired
The arguments to call the function with, as generated by the model in JSON format. Note that the model does not always generate valid JSON, and may hallucinate parameters not defined by your function schema. Validate the arguments in your code before calling your function.namestringRequired
The name of the function to call.
Tool messageobject
rolestringRequired
The role of the messages author, in this case
tool.toolstring
contentstring or array
The contents of the tool message.Text contentstringRequired
The contents of the tool message.Array of content partsarrayRequired
An array of content parts with a defined type. For tool messages, only type
textis supported.Text content partobject
Learn about text inputs.
typestringRequired
The type of the content part.textstring
textstringRequired
The text content.
tool_call_idstringRequired
Tool call that this message is responding to.
Function messageobjectDeprecated
rolestringRequired
The role of the messages author, in this case
function.functionstring
contentstring or nullRequired
The contents of the function message.namestringRequired
The name of the function to call.
modelstring
Model ID used to generate the response, like
gpt-4ooro3. OpenAI offers a wide range of models with different capabilities, performance characteristics, and price points. Refer to the model guide to browse and compare available models.modelstringRequired
modelstringRequired
gpt-4.1string
gpt-4.1-ministring
gpt-4.1-nanostring
gpt-4.1-2025-04-14string
gpt-4.1-mini-2025-04-14string
gpt-4.1-nano-2025-04-14string
o4-ministring
o4-mini-2025-04-16string
o3string
o3-2025-04-16string
o3-ministring
o3-mini-2025-01-31string
o1string
o1-2024-12-17string
o1-previewstring
o1-preview-2024-09-12string
o1-ministring
o1-mini-2024-09-12string
gpt-4ostring
gpt-4o-2024-11-20string
gpt-4o-2024-08-06string
gpt-4o-2024-05-13string
gpt-4o-audio-previewstring
gpt-4o-audio-preview-2024-10-01string
gpt-4o-audio-preview-2024-12-17string
gpt-4o-mini-audio-previewstring
gpt-4o-mini-audio-preview-2024-12-17string
gpt-4o-search-previewstring
gpt-4o-mini-search-previewstring
gpt-4o-search-preview-2025-03-11string
gpt-4o-mini-search-preview-2025-03-11string
chatgpt-4o-lateststring
gpt-4o-ministring
gpt-4o-mini-2024-07-18string
gpt-4-turbostring
gpt-4-turbo-2024-04-09string
gpt-4-0125-previewstring
gpt-4-turbo-previewstring
gpt-4-1106-previewstring
gpt-4-vision-previewstring
gpt-4string
gpt-4-0314string
gpt-4-0613string
gpt-4-32kstring
gpt-4-32k-0314string
gpt-4-32k-0613string
gpt-3.5-turbostring
gpt-3.5-turbo-16kstring
gpt-3.5-turbo-0301string
gpt-3.5-turbo-0613string
gpt-3.5-turbo-1106string
gpt-3.5-turbo-0125string
gpt-3.5-turbo-16k-0613string
modalitiesarray or null
Output types that you would like the model to generate. Most models are capable of generating text, which is the default:
["text"]The
gpt-4o-audio-previewmodel can also be used to generate audio. To request that this model generate both text and audio responses, you can use:["text", "audio"]itemsstring
textstring
audiostring
reasoning_effortstring or nullDefaults: medium
o-series models only
Constrains effort on reasoning for reasoning models. Currently supported values are
low,medium, andhigh. Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning in a response.lowstring
mediumstring
highstring
max_completion_tokensinteger or null
An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.
frequency_penaltynumber or nullDefaults: 0
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_penaltynumber or nullDefaults: 0
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_optionsobject
This tool searches the web for relevant results to use in a response. Learn more about the web search tool.
user_locationobject or null
Approximate location parameters for the search.typestringRequired
The type of location approximation. Always
approximate.approximatestring
approximateobjectRequired
Approximate location parameters for the search.countrystring
The two-letter ISO country code of the user, e.g.
US.regionstring
Free text input for the region of the user, e.g.
California.citystring
Free text input for the city of the user, e.g.
San Francisco.timezonestring
The IANA timezone of the user, e.g.
America/Los_Angeles.
search_context_sizestringDefaults: medium
High level guidance for the amount of context window space to use for the search. One of
low,medium, orhigh.mediumis the default.lowstring
mediumstring
highstring
top_logprobsinteger or null
An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, each with an associated log probability.
logprobsmust be set totrueif this parameter is used.response_formatobject
An object specifying the format that the model must output.
Setting to
enables Structured Outputs which ensures the model will match your supplied JSON schema. Learn more in the Structured Outputs guide.Setting to
enables the older JSON mode, which ensures the message the model generates is valid JSON. Usingjson_schemais preferred for models that support it.Textobject
Default response format. Used to generate text responses.typestringRequired
The type of response format being defined. Always
text.textstring
JSON schemaobject
JSON Schema response format. Used to generate structured JSON responses. Learn more about Structured Outputs.
typestringRequired
The type of response format being defined. Always
json_schema.json_schemastring
json_schemaobjectRequired
Structured Outputs configuration options, including a JSON Schema.descriptionstring
A description of what the response format is for, used by the model to determine how to respond in the format.namestringRequired
The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.schemaobject
The schema for the response format, described as a JSON Schema object. Learn how to build JSON schemas here.
strictboolean or nullDefaults: false
Whether to enable strict schema adherence when generating the output. If set to true, the model will always follow the exact schema defined in the
schemafield. Only a subset of JSON Schema is supported whenstrictistrue. To learn more, read the Structured Outputs guide.
JSON objectobject
JSON object response format. An older method of generating JSON responses. Using
json_schemais recommended for models that support it. Note that the model will not generate JSON without a system or user message instructing it to do so.typestringRequired
The type of response format being defined. Always
json_object.json_objectstring
audioobject or null
Parameters for audio output. Required when audio output is requested with
modalities: ["audio"]. Learn more.voicestring
The voice the model uses to respond. Supported voices are
alloy,ash,ballad,coral,echo,fable,nova,onyx,sage, andshimmer.voicestringRequired
voicestringRequired
alloystring
ashstring
balladstring
coralstring
echostring
fablestring
onyxstring
novastring
sagestring
shimmerstring
versestring
formatstringRequired
Specifies the output audio format. Must be one of
wav,mp3,flac,opus, orpcm16.wavstring
aacstring
mp3string
flacstring
opusstring
pcm16string
storeboolean or nullDefaults: false
Whether or not to store the output of this chat completion request for use in our model distillation or evals products.
streamboolean or nullDefaults: false
If set to true, the model response data will be streamed to the client as it is generated using server-sent events. See the Streaming section below for more information, along with the streaming responses guide for more information on how to handle the streaming events.
stopstring or array
Not supported with latest reasoning models
o3ando4-mini.Up to 4 sequences where the API will stop generating further tokens. The returned text will not contain the stop sequence.
stopstring or nullDefaults: <|endoftext|>
stoparray
itemsstring
logit_biasobject or nullDefaults: null
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.logprobsboolean or nullDefaults: false
Whether to return log probabilities of the output tokens or not. If true, returns the log probabilities of each output token returned in the
contentofmessage.max_tokensinteger or nullDeprecated
The maximum number of tokens that can be generated in the chat completion. This value can be used to control costs for text generated via API.
This value is now deprecated in favor of
max_completion_tokens, and is not compatible with o-series models.ninteger or nullDefaults: 1
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
nas1to minimize costs.predictionobject
Configuration for a Predicted Output, 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.
Static Contentobject
Static predicted output content, such as the content of a text file that is being regenerated.typestringRequired
The type of the predicted content you want to provide. This type is currently always
content.contentstring
contentstring or array
The content that should be matched when generating a model response. If generated tokens would match this content, the entire model response can be returned much more quickly.Text contentstringRequired
The content used for a Predicted Output. This is often the text of a file you are regenerating with minor changes.Array of content partsarrayRequired
An array of content parts with a defined type. Supported options differ based on the model being used to generate the response. Can contain text inputs.
itemsobject
Learn about text inputs.
typestringRequired
The type of the content part.textstring
textstringRequired
The text content.
seedinteger or null
This feature is in Beta. If specified, our system will make a best effort to sample deterministically, such that repeated requests with the same
seedand parameters should return the same result. Determinism is not guaranteed, and you should refer to thesystem_fingerprintresponse parameter to monitor changes in the backend.stream_optionsobject or nullDefaults: null
Options for streaming response. Only set this when you set
stream: true.include_usageboolean
If set, an additional chunk will be streamed before the
data: [DONE]message. Theusagefield on this chunk shows the token usage statistics for the entire request, and thechoicesfield will always be an empty array.All other chunks will also include a
usagefield, but with a null value. NOTE: If the stream is interrupted, you may not receive the final usage chunk which contains the total token usage for the request.
toolsarray
A list of tools the model may call. Currently, only functions are supported as a tool. Use this to provide a list of functions the model may generate JSON inputs for. A max of 128 functions are supported.itemsobject
typestringRequired
The type of the tool. Currently, only
functionis supported.functionstring
functionobjectRequired
descriptionstring
A description of what the function does, used by the model to choose when and how to call the function.namestringRequired
The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.parametersobject
The parameters the functions accepts, described as a JSON Schema object. See the guide for examples, and the JSON Schema reference for documentation about the format.
Omitting
parametersdefines a function with an empty parameter list.strictboolean or nullDefaults: false
Whether to enable strict schema adherence when generating the function call. If set to true, the model will follow the exact schema defined in the
parametersfield. Only a subset of JSON Schema is supported whenstrictistrue. Learn more about Structured Outputs in the .
tool_choicestring or object
Controls which (if any) tool is called by the model.
nonemeans the model will not call any tool and instead generates a message.automeans the model can pick between generating a message or calling one or more tools.requiredmeans the model must call one or more tools. Specifying a particular tool viaforces the model to call that tool.noneis the default when no tools are present.autois the default if tools are present.tool_choicestring
nonemeans the model will not call any tool and instead generates a message.automeans the model can pick between generating a message or calling one or more tools.requiredmeans the model must call one or more tools.nonestring
autostring
requiredstring
tool_choiceobject
Specifies a tool the model should use. Use to force the model to call a specific function.typestringRequired
The type of the tool. Currently, only
functionis supported.functionstring
functionobjectRequired
namestringRequired
The name of the function to call.
parallel_tool_callsbooleanDefaults: true
Whether to enable parallel function calling during tool use.
function_callstring or object
Deprecated in favor of
tool_choice.Controls which (if any) function is called by the model.
nonemeans the model will not call a function and instead generates a message.automeans the model can pick between generating a message or calling a function.Specifying a particular function via
forces the model to call that function.noneis the default when no functions are present.autois the default if functions are present.function_callstring
nonemeans the model will not call a function and instead generates a message.automeans the model can pick between generating a message or calling a function.nonestring
autostring
function_callobject
Specifying a particular function via
forces the model to call that function.namestringRequired
The name of the function to call.
functionsarrayDeprecated
Deprecated in favor of
tools.A list of functions the model may generate JSON inputs for.
itemsobjectDeprecated
descriptionstring
A description of what the function does, used by the model to choose when and how to call the function.namestringRequired
The name of the function to be called. Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64.parametersobject
The parameters the functions accepts, described as a JSON Schema object. See the guide for examples, and the JSON Schema reference for documentation about the format.
Omitting
parametersdefines a function with an empty parameter list.
Response
Returns a chat completion object, or a streamed sequence of chat completion chunk objects if the request is streamed.
1 curl https://api.openai.com/v1/chat/completions \2 -H "Content-Type: application/json" \3 -H "Authorization: Bearer $OPENAI_API_KEY" \4 -d '{5 "model": "VAR_chat_model_id",6 "messages": [7 {8 "role": "developer",9 "content": "You are a helpful assistant."10 },11 {12 "role": "user",13 "content": "Hello!"14 }15 ]16 }'
1 {2 "id": "chatcmpl-B9MBs8CjcvOU2jLn4n570S5qMJKcT",3 "object": "chat.completion",4 "created": 1741569952,5 "model": "gpt-4.1-2025-04-14",6 "choices": [7 {8 "index": 0,9 "message": {10 "role": "assistant",11 "content": "Hello! How can I assist you today?",12 "refusal": null,13 "annotations": []14 },15 "logprobs": null,16 "finish_reason": "stop"17 }18 ],19 "usage": {20 "prompt_tokens": 19,21 "completion_tokens": 10,22 "total_tokens": 29,23 "prompt_tokens_details": {24 "cached_tokens": 0,25 "audio_tokens": 026 },27 "completion_tokens_details": {28 "reasoning_tokens": 0,29 "audio_tokens": 0,30 "accepted_prediction_tokens": 0,31 "rejected_prediction_tokens": 032 }33 },34 "service_tier": "default"35 }