Chat
ChatCompletions
Given a list of messages comprising a conversation, the model will return a response.
Create chat completion
List Chat Completions
Get chat completion
Update chat completion
Delete chat completion
ModelsExpand Collapse
type ChatCompletion struct{…}Represents a chat completion response returned by model, based on the provided input.
Represents a chat completion response returned by model, based on the provided input.
Choices []ChatCompletionChoiceA list of chat completion choices. Can be more than one if n is greater than 1.
A list of chat completion choices. Can be more than one if n is greater than 1.
FinishReason stringThe reason the model stopped generating tokens. This will be stop if the model hit a natural stop point or a provided stop sequence,
length if the maximum number of tokens specified in the request was reached,
content_filter if content was omitted due to a flag from our content filters,
tool_calls if the model called a tool, or function_call (deprecated) if the model called a function.
The reason the model stopped generating tokens. This will be stop if the model hit a natural stop point or a provided stop sequence,
length if the maximum number of tokens specified in the request was reached,
content_filter if content was omitted due to a flag from our content filters,
tool_calls if the model called a tool, or function_call (deprecated) if the model called a function.
Logprobs ChatCompletionChoiceLogprobsLog probability information for the choice.
Log probability information for the choice.
Content []ChatCompletionTokenLogprobA list of message content tokens with log probability information.
A list of message content tokens with log probability information.
A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
TopLogprobs []ChatCompletionTokenLogprobTopLogprobList of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
Refusal []ChatCompletionTokenLogprobA list of message refusal tokens with log probability information.
A list of message refusal tokens with log probability information.
A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
TopLogprobs []ChatCompletionTokenLogprobTopLogprobList of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
A chat completion message generated by the model.
ServiceTier ChatCompletionServiceTieroptionalSpecifies 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' or 'priority', then the request will be processed with the corresponding service tier.
- 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.
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' or 'priority', then the request will be processed with the corresponding service tier.
- 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.
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.
type ChatCompletionAllowedToolChoice struct{…}Constrains the tools available to the model to a pre-defined set.
Constrains the tools available to the model to a pre-defined set.
Constrains the tools available to the model to a pre-defined set.
type ChatCompletionAssistantMessageParamResp struct{…}Messages sent by the model in response to user messages.
Messages sent by the model in response to user messages.
Audio ChatCompletionAssistantMessageParamAudioRespoptionalData about a previous audio response from the model.
Learn more.
Data about a previous audio response from the model. Learn more.
Content ChatCompletionAssistantMessageParamContentUnionRespoptionalThe contents of the assistant message. Required unless tool_calls or function_call is specified.
The contents of the assistant message. Required unless tool_calls or function_call is specified.
[]ChatCompletionAssistantMessageParamContentArrayOfContentPartUnionResp
type ChatCompletionContentPartText struct{…}Learn about text inputs.
Learn about text inputs.
DeprecatedFunctionCall ChatCompletionAssistantMessageParamFunctionCallRespoptionalDeprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.
Deprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.
An optional name for the participant. Provides the model information to differentiate between participants of the same role.
The tool calls generated by the model, such as function calls.
The tool calls generated by the model, such as function calls.
type ChatCompletionMessageFunctionToolCall struct{…}A call to a function tool created by the model.
A call to a function tool created by the model.
Function ChatCompletionMessageFunctionToolCallFunctionThe function that the model called.
The function that the model called.
type ChatCompletionAudio struct{…}If the audio output modality is requested, this object contains data
about the audio response from the model. Learn more.
If the audio output modality is requested, this object contains data about the audio response from the model. Learn more.
type ChatCompletionAudioParamResp struct{…}Parameters for audio output. Required when audio output is requested with
modalities: ["audio"]. Learn more.
Parameters for audio output. Required when audio output is requested with
modalities: ["audio"]. Learn more.
Format ChatCompletionAudioParamFormatSpecifies the output audio format. Must be one of wav, mp3, flac,
opus, or pcm16.
Specifies the output audio format. Must be one of wav, mp3, flac,
opus, or pcm16.
Voice ChatCompletionAudioParamVoiceUnionRespThe voice the model uses to respond. Supported built-in voices are
alloy, ash, ballad, coral, echo, fable, nova, onyx,
sage, shimmer, marin, and cedar. You may also provide a
custom voice object with an id, for example { "id": "voice_1234" }.
The voice the model uses to respond. Supported built-in voices are
alloy, ash, ballad, coral, echo, fable, nova, onyx,
sage, shimmer, marin, and cedar. You may also provide a
custom voice object with an id, for example { "id": "voice_1234" }.
type ChatCompletionChunk struct{…}Represents a streamed chunk of a chat completion response returned
by the model, based on the provided input.
Learn more.
Represents a streamed chunk of a chat completion response returned by the model, based on the provided input. Learn more.
Choices []ChatCompletionChunkChoiceA list of chat completion choices. Can contain more than one elements if n is greater than 1. Can also be empty for the
last chunk if you set stream_options: {"include_usage": true}.
A list of chat completion choices. Can contain more than one elements if n is greater than 1. Can also be empty for the
last chunk if you set stream_options: {"include_usage": true}.
Delta ChatCompletionChunkChoiceDeltaA chat completion delta generated by streamed model responses.
A chat completion delta generated by streamed model responses.
DeprecatedFunctionCall ChatCompletionChunkChoiceDeltaFunctionCalloptionalDeprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.
Deprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.
ToolCalls []ChatCompletionChunkChoiceDeltaToolCalloptional
Function ChatCompletionChunkChoiceDeltaToolCallFunctionoptional
FinishReason stringThe reason the model stopped generating tokens. This will be stop if the model hit a natural stop point or a provided stop sequence,
length if the maximum number of tokens specified in the request was reached,
content_filter if content was omitted due to a flag from our content filters,
tool_calls if the model called a tool, or function_call (deprecated) if the model called a function.
The reason the model stopped generating tokens. This will be stop if the model hit a natural stop point or a provided stop sequence,
length if the maximum number of tokens specified in the request was reached,
content_filter if content was omitted due to a flag from our content filters,
tool_calls if the model called a tool, or function_call (deprecated) if the model called a function.
Logprobs ChatCompletionChunkChoiceLogprobsoptionalLog probability information for the choice.
Log probability information for the choice.
Content []ChatCompletionTokenLogprobA list of message content tokens with log probability information.
A list of message content tokens with log probability information.
A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
TopLogprobs []ChatCompletionTokenLogprobTopLogprobList of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
Refusal []ChatCompletionTokenLogprobA list of message refusal tokens with log probability information.
A list of message refusal tokens with log probability information.
A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
TopLogprobs []ChatCompletionTokenLogprobTopLogprobList of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
The Unix timestamp (in seconds) of when the chat completion was created. Each chunk has the same timestamp.
ServiceTier ChatCompletionChunkServiceTieroptionalSpecifies 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' or 'priority', then the request will be processed with the corresponding service tier.
- 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.
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' or 'priority', then the request will be processed with the corresponding service tier.
- 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.
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.
An optional field that will only be present when you set
stream_options: {"include_usage": true} in your request. When present, it
contains a null value except for the last chunk which contains the
token usage statistics for the entire request.
NOTE: If the stream is interrupted or cancelled, you may not receive the final usage chunk which contains the total token usage for the request.
type ChatCompletionContentPartUnion interface{…}Learn about text inputs.
Learn about text inputs.
type ChatCompletionContentPartText struct{…}Learn about text inputs.
Learn about text inputs.
type ChatCompletionContentPartImage struct{…}Learn about image inputs.
Learn about image inputs.
ImageURL ChatCompletionContentPartImageImageURL
Detail stringoptionalSpecifies the detail level of the image. Learn more in the Vision guide.
Specifies the detail level of the image. Learn more in the Vision guide.
type ChatCompletionContentPartInputAudio struct{…}Learn about audio inputs.
Learn about audio inputs.
type ChatCompletionContentPartImage struct{…}Learn about image inputs.
Learn about image inputs.
ImageURL ChatCompletionContentPartImageImageURL
Detail stringoptionalSpecifies the detail level of the image. Learn more in the Vision guide.
Specifies the detail level of the image. Learn more in the Vision guide.
type ChatCompletionContentPartInputAudio struct{…}Learn about audio inputs.
Learn about audio inputs.
type ChatCompletionContentPartText struct{…}Learn about text inputs.
Learn about text inputs.
type ChatCompletionCustomTool struct{…}A custom tool that processes input using a specified format.
A custom tool that processes input using a specified format.
Custom ChatCompletionCustomToolCustomProperties of the custom tool.
Properties of the custom tool.
Format ChatCompletionCustomToolCustomFormatUnionoptionalThe input format for the custom tool. Default is unconstrained text.
The input format for the custom tool. Default is unconstrained text.
type ChatCompletionDeveloperMessageParamResp struct{…}Developer-provided instructions that the model should follow, regardless of
messages sent by the user. With o1 models and newer, developer messages
replace the previous system messages.
Developer-provided instructions that the model should follow, regardless of
messages sent by the user. With o1 models and newer, developer messages
replace the previous system messages.
type ChatCompletionFunctionTool struct{…}A function tool that can be used to generate a response.
A function tool that can be used to generate a response.
type ChatCompletionMessage struct{…}A chat completion message generated by the model.
A chat completion message generated by the model.
Annotations []ChatCompletionMessageAnnotationoptionalAnnotations for the message, when applicable, as when using the
web search tool.
Annotations for the message, when applicable, as when using the web search tool.
If the audio output modality is requested, this object contains data about the audio response from the model. Learn more.
DeprecatedFunctionCall ChatCompletionMessageFunctionCalloptionalDeprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.
Deprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.
The tool calls generated by the model, such as function calls.
The tool calls generated by the model, such as function calls.
type ChatCompletionMessageFunctionToolCall struct{…}A call to a function tool created by the model.
A call to a function tool created by the model.
Function ChatCompletionMessageFunctionToolCallFunctionThe function that the model called.
The function that the model called.
type ChatCompletionMessageFunctionToolCall struct{…}A call to a function tool created by the model.
A call to a function tool created by the model.
Function ChatCompletionMessageFunctionToolCallFunctionThe function that the model called.
The function that the model called.
type ChatCompletionMessageParamUnionResp interface{…}Developer-provided instructions that the model should follow, regardless of
messages sent by the user. With o1 models and newer, developer messages
replace the previous system messages.
Developer-provided instructions that the model should follow, regardless of
messages sent by the user. With o1 models and newer, developer messages
replace the previous system messages.
type ChatCompletionDeveloperMessageParamResp struct{…}Developer-provided instructions that the model should follow, regardless of
messages sent by the user. With o1 models and newer, developer messages
replace the previous system messages.
Developer-provided instructions that the model should follow, regardless of
messages sent by the user. With o1 models and newer, developer messages
replace the previous system messages.
type ChatCompletionSystemMessageParamResp struct{…}Developer-provided instructions that the model should follow, regardless of
messages sent by the user. With o1 models and newer, use developer messages
for this purpose instead.
Developer-provided instructions that the model should follow, regardless of
messages sent by the user. With o1 models and newer, use developer messages
for this purpose instead.
type ChatCompletionUserMessageParamResp struct{…}Messages sent by an end user, containing prompts or additional context
information.
Messages sent by an end user, containing prompts or additional context information.
Content ChatCompletionUserMessageParamContentUnionRespThe contents of the user message.
The contents of the user message.
type ChatCompletionContentPartText struct{…}Learn about text inputs.
Learn about text inputs.
type ChatCompletionContentPartImage struct{…}Learn about image inputs.
Learn about image inputs.
ImageURL ChatCompletionContentPartImageImageURL
Detail stringoptionalSpecifies the detail level of the image. Learn more in the Vision guide.
Specifies the detail level of the image. Learn more in the Vision guide.
type ChatCompletionContentPartInputAudio struct{…}Learn about audio inputs.
Learn about audio inputs.
type ChatCompletionAssistantMessageParamResp struct{…}Messages sent by the model in response to user messages.
Messages sent by the model in response to user messages.
Audio ChatCompletionAssistantMessageParamAudioRespoptionalData about a previous audio response from the model.
Learn more.
Data about a previous audio response from the model. Learn more.
Content ChatCompletionAssistantMessageParamContentUnionRespoptionalThe contents of the assistant message. Required unless tool_calls or function_call is specified.
The contents of the assistant message. Required unless tool_calls or function_call is specified.
[]ChatCompletionAssistantMessageParamContentArrayOfContentPartUnionResp
type ChatCompletionContentPartText struct{…}Learn about text inputs.
Learn about text inputs.
DeprecatedFunctionCall ChatCompletionAssistantMessageParamFunctionCallRespoptionalDeprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.
Deprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.
An optional name for the participant. Provides the model information to differentiate between participants of the same role.
The tool calls generated by the model, such as function calls.
The tool calls generated by the model, such as function calls.
type ChatCompletionMessageFunctionToolCall struct{…}A call to a function tool created by the model.
A call to a function tool created by the model.
Function ChatCompletionMessageFunctionToolCallFunctionThe function that the model called.
The function that the model called.
type ChatCompletionMessageToolCallUnion interface{…}A call to a function tool created by the model.
A call to a function tool created by the model.
type ChatCompletionMessageFunctionToolCall struct{…}A call to a function tool created by the model.
A call to a function tool created by the model.
Function ChatCompletionMessageFunctionToolCallFunctionThe function that the model called.
The function that the model called.
type ChatCompletionPredictionContent struct{…}Static predicted output content, such as the content of a text file that is
being regenerated.
Static predicted output content, such as the content of a text file that is being regenerated.
type ChatCompletionStoreMessage struct{…}A chat completion message generated by the model.
A chat completion message generated by the model.
ContentParts []ChatCompletionStoreMessageContentPartUnionoptionalIf a content parts array was provided, this is an array of text and image_url parts.
Otherwise, null.
If a content parts array was provided, this is an array of text and image_url parts.
Otherwise, null.
type ChatCompletionContentPartText struct{…}Learn about text inputs.
Learn about text inputs.
type ChatCompletionContentPartImage struct{…}Learn about image inputs.
Learn about image inputs.
ImageURL ChatCompletionContentPartImageImageURL
Detail stringoptionalSpecifies the detail level of the image. Learn more in the Vision guide.
Specifies the detail level of the image. Learn more in the Vision guide.
type ChatCompletionStreamOptions struct{…}Options for streaming response. Only set this when you set stream: true.
Options for streaming response. Only set this when you set stream: true.
When true, stream obfuscation will be enabled. Stream obfuscation adds
random characters to an obfuscation field on streaming delta events to
normalize payload sizes as a mitigation to certain side-channel attacks.
These obfuscation fields are included by default, but add a small amount
of overhead to the data stream. You can set include_obfuscation to
false to optimize for bandwidth if you trust the network links between
your application and the OpenAI API.
If set, an additional chunk will be streamed before the data: [DONE]
message. The usage field on this chunk shows the token usage statistics
for the entire request, and the choices field will always be an empty
array.
All other chunks will also include a usage field, 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.
type ChatCompletionSystemMessageParamResp struct{…}Developer-provided instructions that the model should follow, regardless of
messages sent by the user. With o1 models and newer, use developer messages
for this purpose instead.
Developer-provided instructions that the model should follow, regardless of
messages sent by the user. With o1 models and newer, use developer messages
for this purpose instead.
type ChatCompletionTokenLogprob struct{…}
A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
The log probability of this token, if it is within the top 20 most likely tokens. Otherwise, the value -9999.0 is used to signify that the token is very unlikely.
TopLogprobs []ChatCompletionTokenLogprobTopLogprobList of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
List of the most likely tokens and their log probability, at this token position. In rare cases, there may be fewer than the number of requested top_logprobs returned.
A list of integers representing the UTF-8 bytes representation of the token. Useful in instances where characters are represented by multiple tokens and their byte representations must be combined to generate the correct text representation. Can be null if there is no bytes representation for the token.
type ChatCompletionToolUnion interface{…}A function tool that can be used to generate a response.
A function tool that can be used to generate a response.
type ChatCompletionFunctionTool struct{…}A function tool that can be used to generate a response.
A function tool that can be used to generate a response.
type ChatCompletionCustomTool struct{…}A custom tool that processes input using a specified format.
A custom tool that processes input using a specified format.
Custom ChatCompletionCustomToolCustomProperties of the custom tool.
Properties of the custom tool.
Format ChatCompletionCustomToolCustomFormatUnionoptionalThe input format for the custom tool. Default is unconstrained text.
The input format for the custom tool. Default is unconstrained text.
type ChatCompletionToolChoiceOptionUnion interface{…}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.
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.
type ChatCompletionAllowedToolChoice struct{…}Constrains the tools available to the model to a pre-defined set.
Constrains the tools available to the model to a pre-defined set.
Constrains the tools available to the model to a pre-defined set.
type ChatCompletionNamedToolChoice struct{…}Specifies a tool the model should use. Use to force the model to call a specific function.
Specifies a tool the model should use. Use to force the model to call a specific function.
type ChatCompletionUserMessageParamResp struct{…}Messages sent by an end user, containing prompts or additional context
information.
Messages sent by an end user, containing prompts or additional context information.
Content ChatCompletionUserMessageParamContentUnionRespThe contents of the user message.
The contents of the user message.
type ChatCompletionContentPartText struct{…}Learn about text inputs.
Learn about text inputs.
type ChatCompletionContentPartImage struct{…}Learn about image inputs.
Learn about image inputs.
ImageURL ChatCompletionContentPartImageImageURL
Detail stringoptionalSpecifies the detail level of the image. Learn more in the Vision guide.
Specifies the detail level of the image. Learn more in the Vision guide.
type ChatCompletionContentPartInputAudio struct{…}Learn about audio inputs.
Learn about audio inputs.
type ChatCompletionAllowedTools struct{…}Constrains the tools available to the model to a pre-defined set.
Constrains the tools available to the model to a pre-defined set.
ChatCompletionsMessages
Given a list of messages comprising a conversation, the model will return a response.