Skip to content

Chat

ChatCompletions

Create chat completion
client.Chat.Completions.New(ctx, body) (*ChatCompletion, error)
POST/chat/completions
List Chat Completions
client.Chat.Completions.List(ctx, query) (*CursorPage[ChatCompletion], error)
GET/chat/completions
Get chat completion
client.Chat.Completions.Get(ctx, completionID) (*ChatCompletion, error)
GET/chat/completions/{completion_id}
Update chat completion
client.Chat.Completions.Update(ctx, completionID, body) (*ChatCompletion, error)
POST/chat/completions/{completion_id}
Delete chat completion
client.Chat.Completions.Delete(ctx, completionID) (*ChatCompletionDeleted, error)
DELETE/chat/completions/{completion_id}
ModelsExpand Collapse
type ChatCompletion struct{…}

Represents a chat completion response returned by model, based on the provided input.

ID string

A unique identifier for the chat completion.

Choices []ChatCompletionChoice

A list of chat completion choices. Can be more than one if n is greater than 1.

FinishReason string

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.

Accepts one of the following:
const ChatCompletionChoiceFinishReasonStop ChatCompletionChoiceFinishReason = "stop"
const ChatCompletionChoiceFinishReasonLength ChatCompletionChoiceFinishReason = "length"
const ChatCompletionChoiceFinishReasonToolCalls ChatCompletionChoiceFinishReason = "tool_calls"
const ChatCompletionChoiceFinishReasonContentFilter ChatCompletionChoiceFinishReason = "content_filter"
const ChatCompletionChoiceFinishReasonFunctionCall ChatCompletionChoiceFinishReason = "function_call"
Index int64

The index of the choice in the list of choices.

Logprobs ChatCompletionChoiceLogprobs

Log probability information for the choice.

A list of message content tokens with log probability information.

Token string

The token.

Bytes []int64

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.

Logprob float64

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 []ChatCompletionTokenLogprobTopLogprob

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.

Token string

The token.

Bytes []int64

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.

Logprob float64

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.

A list of message refusal tokens with log probability information.

Token string

The token.

Bytes []int64

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.

Logprob float64

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 []ChatCompletionTokenLogprobTopLogprob

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.

Token string

The token.

Bytes []int64

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.

Logprob float64

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.

A chat completion message generated by the model.

Created int64

The Unix timestamp (in seconds) of when the chat completion was created.

Model string

The model used for the chat completion.

Object ChatCompletion

The object type, which is always chat.completion.

ServiceTier ChatCompletionServiceTieroptional

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.

Accepts one of the following:
const ChatCompletionServiceTierAuto ChatCompletionServiceTier = "auto"
const ChatCompletionServiceTierDefault ChatCompletionServiceTier = "default"
const ChatCompletionServiceTierFlex ChatCompletionServiceTier = "flex"
const ChatCompletionServiceTierScale ChatCompletionServiceTier = "scale"
const ChatCompletionServiceTierPriority ChatCompletionServiceTier = "priority"
DeprecatedSystemFingerprint stringoptional

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.

Usage CompletionUsageoptional

Usage statistics for the completion request.

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.

Type AllowedTools

Allowed tool configuration type. Always allowed_tools.

type ChatCompletionAssistantMessageParamResp struct{…}

Messages sent by the model in response to user messages.

Role Assistant

The role of the messages author, in this case assistant.

Audio ChatCompletionAssistantMessageParamAudioRespoptional

Data about a previous audio response from the model. Learn more.

ID string

Unique identifier for a previous audio response from the model.

Content ChatCompletionAssistantMessageParamContentUnionRespoptional

The contents of the assistant message. Required unless tool_calls or function_call is specified.

Accepts one of the following:
string
[]ChatCompletionAssistantMessageParamContentArrayOfContentPartUnionResp
Accepts one of the following:
type ChatCompletionContentPartText struct{…}

Learn about text inputs.

Text string

The text content.

Type Text

The type of the content part.

type ChatCompletionContentPartRefusal struct{…}
Refusal string

The refusal message generated by the model.

Type Refusal

The type of the content part.

DeprecatedFunctionCall ChatCompletionAssistantMessageParamFunctionCallRespoptional

Deprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.

Arguments string

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.

Name string

The name of the function to call.

Name stringoptional

An optional name for the participant. Provides the model information to differentiate between participants of the same role.

Refusal stringoptional

The refusal message by the assistant.

The tool calls generated by the model, such as function calls.

Accepts one of the following:
type ChatCompletionMessageFunctionToolCall struct{…}

A call to a function tool created by the model.

ID string

The ID of the tool call.

Function ChatCompletionMessageFunctionToolCallFunction

The function that the model called.

Arguments string

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.

Name string

The name of the function to call.

Type Function

The type of the tool. Currently, only function is supported.

type ChatCompletionMessageCustomToolCall struct{…}

A call to a custom tool created by the model.

ID string

The ID of the tool call.

Custom ChatCompletionMessageCustomToolCallCustom

The custom tool that the model called.

Input string

The input for the custom tool call generated by the model.

Name string

The name of the custom tool to call.

Type Custom

The type of the tool. Always custom.

type ChatCompletionAudio struct{…}

If the audio output modality is requested, this object contains data about the audio response from the model. Learn more.

ID string

Unique identifier for this audio response.

Data string

Base64 encoded audio bytes generated by the model, in the format specified in the request.

ExpiresAt int64

The Unix timestamp (in seconds) for when this audio response will no longer be accessible on the server for use in multi-turn conversations.

Transcript string

Transcript of the audio generated by the model.

type ChatCompletionAudioParamResp struct{…}

Parameters for audio output. Required when audio output is requested with modalities: ["audio"]. Learn more.

Format ChatCompletionAudioParamFormat

Specifies the output audio format. Must be one of wav, mp3, flac, opus, or pcm16.

Accepts one of the following:
const ChatCompletionAudioParamFormatWAV ChatCompletionAudioParamFormat = "wav"
const ChatCompletionAudioParamFormatAAC ChatCompletionAudioParamFormat = "aac"
const ChatCompletionAudioParamFormatMP3 ChatCompletionAudioParamFormat = "mp3"
const ChatCompletionAudioParamFormatFLAC ChatCompletionAudioParamFormat = "flac"
const ChatCompletionAudioParamFormatOpus ChatCompletionAudioParamFormat = "opus"
const ChatCompletionAudioParamFormatPcm16 ChatCompletionAudioParamFormat = "pcm16"
Voice ChatCompletionAudioParamVoice

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.

Accepts one of the following:
string
ChatCompletionAudioParamVoice
Accepts one of the following:
const ChatCompletionAudioParamVoiceAlloy ChatCompletionAudioParamVoice = "alloy"
const ChatCompletionAudioParamVoiceAsh ChatCompletionAudioParamVoice = "ash"
const ChatCompletionAudioParamVoiceBallad ChatCompletionAudioParamVoice = "ballad"
const ChatCompletionAudioParamVoiceCoral ChatCompletionAudioParamVoice = "coral"
const ChatCompletionAudioParamVoiceEcho ChatCompletionAudioParamVoice = "echo"
const ChatCompletionAudioParamVoiceSage ChatCompletionAudioParamVoice = "sage"
const ChatCompletionAudioParamVoiceShimmer ChatCompletionAudioParamVoice = "shimmer"
const ChatCompletionAudioParamVoiceVerse ChatCompletionAudioParamVoice = "verse"
const ChatCompletionAudioParamVoiceMarin ChatCompletionAudioParamVoice = "marin"
const ChatCompletionAudioParamVoiceCedar ChatCompletionAudioParamVoice = "cedar"
type ChatCompletionChunk struct{…}

Represents a streamed chunk of a chat completion response returned by the model, based on the provided input. Learn more.

ID string

A unique identifier for the chat completion. Each chunk has the same ID.

Choices []ChatCompletionChunkChoice

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 ChatCompletionChunkChoiceDelta

A chat completion delta generated by streamed model responses.

Content stringoptional

The contents of the chunk message.

DeprecatedFunctionCall ChatCompletionChunkChoiceDeltaFunctionCalloptional

Deprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.

Arguments stringoptional

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.

Name stringoptional

The name of the function to call.

Refusal stringoptional

The refusal message generated by the model.

Role stringoptional

The role of the author of this message.

Accepts one of the following:
const ChatCompletionChunkChoiceDeltaRoleDeveloper ChatCompletionChunkChoiceDeltaRole = "developer"
const ChatCompletionChunkChoiceDeltaRoleSystem ChatCompletionChunkChoiceDeltaRole = "system"
const ChatCompletionChunkChoiceDeltaRoleUser ChatCompletionChunkChoiceDeltaRole = "user"
const ChatCompletionChunkChoiceDeltaRoleAssistant ChatCompletionChunkChoiceDeltaRole = "assistant"
const ChatCompletionChunkChoiceDeltaRoleTool ChatCompletionChunkChoiceDeltaRole = "tool"
ToolCalls []ChatCompletionChunkChoiceDeltaToolCalloptional
Index int64
ID stringoptional

The ID of the tool call.

Function ChatCompletionChunkChoiceDeltaToolCallFunctionoptional
Arguments stringoptional

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.

Name stringoptional

The name of the function to call.

Type stringoptional

The type of the tool. Currently, only function is supported.

FinishReason string

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.

Accepts one of the following:
const ChatCompletionChunkChoiceFinishReasonStop ChatCompletionChunkChoiceFinishReason = "stop"
const ChatCompletionChunkChoiceFinishReasonLength ChatCompletionChunkChoiceFinishReason = "length"
const ChatCompletionChunkChoiceFinishReasonToolCalls ChatCompletionChunkChoiceFinishReason = "tool_calls"
const ChatCompletionChunkChoiceFinishReasonContentFilter ChatCompletionChunkChoiceFinishReason = "content_filter"
const ChatCompletionChunkChoiceFinishReasonFunctionCall ChatCompletionChunkChoiceFinishReason = "function_call"
Index int64

The index of the choice in the list of choices.

Logprobs ChatCompletionChunkChoiceLogprobsoptional

Log probability information for the choice.

A list of message content tokens with log probability information.

Token string

The token.

Bytes []int64

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.

Logprob float64

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 []ChatCompletionTokenLogprobTopLogprob

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.

Token string

The token.

Bytes []int64

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.

Logprob float64

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.

A list of message refusal tokens with log probability information.

Token string

The token.

Bytes []int64

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.

Logprob float64

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 []ChatCompletionTokenLogprobTopLogprob

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.

Token string

The token.

Bytes []int64

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.

Logprob float64

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.

Created int64

The Unix timestamp (in seconds) of when the chat completion was created. Each chunk has the same timestamp.

Model string

The model to generate the completion.

Object ChatCompletionChunk

The object type, which is always chat.completion.chunk.

ServiceTier ChatCompletionChunkServiceTieroptional

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.

Accepts one of the following:
const ChatCompletionChunkServiceTierAuto ChatCompletionChunkServiceTier = "auto"
const ChatCompletionChunkServiceTierDefault ChatCompletionChunkServiceTier = "default"
const ChatCompletionChunkServiceTierFlex ChatCompletionChunkServiceTier = "flex"
const ChatCompletionChunkServiceTierScale ChatCompletionChunkServiceTier = "scale"
const ChatCompletionChunkServiceTierPriority ChatCompletionChunkServiceTier = "priority"
DeprecatedSystemFingerprint stringoptional

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.

Usage CompletionUsageoptional

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.

Accepts one of the following:
type ChatCompletionContentPartText struct{…}

Learn about text inputs.

Text string

The text content.

Type Text

The type of the content part.

type ChatCompletionContentPartImage struct{…}

Learn about image inputs.

ImageURL ChatCompletionContentPartImageImageURL
URL string

Either a URL of the image or the base64 encoded image data.

formaturi
Detail stringoptional

Specifies the detail level of the image. Learn more in the Vision guide.

Accepts one of the following:
const ChatCompletionContentPartImageImageURLDetailAuto ChatCompletionContentPartImageImageURLDetail = "auto"
const ChatCompletionContentPartImageImageURLDetailLow ChatCompletionContentPartImageImageURLDetail = "low"
const ChatCompletionContentPartImageImageURLDetailHigh ChatCompletionContentPartImageImageURLDetail = "high"
Type ImageURL

The type of the content part.

type ChatCompletionContentPartInputAudio struct{…}

Learn about audio inputs.

InputAudio ChatCompletionContentPartInputAudioInputAudio
Data string

Base64 encoded audio data.

Format string

The format of the encoded audio data. Currently supports "wav" and "mp3".

Accepts one of the following:
const ChatCompletionContentPartInputAudioInputAudioFormatWAV ChatCompletionContentPartInputAudioInputAudioFormat = "wav"
const ChatCompletionContentPartInputAudioInputAudioFormatMP3 ChatCompletionContentPartInputAudioInputAudioFormat = "mp3"
Type InputAudio

The type of the content part. Always input_audio.

ChatCompletionContentPartFile
File ChatCompletionContentPartFileFile
FileData stringoptional

The base64 encoded file data, used when passing the file to the model as a string.

FileID stringoptional

The ID of an uploaded file to use as input.

Filename stringoptional

The name of the file, used when passing the file to the model as a string.

Type File

The type of the content part. Always file.

type ChatCompletionContentPartImage struct{…}

Learn about image inputs.

ImageURL ChatCompletionContentPartImageImageURL
URL string

Either a URL of the image or the base64 encoded image data.

formaturi
Detail stringoptional

Specifies the detail level of the image. Learn more in the Vision guide.

Accepts one of the following:
const ChatCompletionContentPartImageImageURLDetailAuto ChatCompletionContentPartImageImageURLDetail = "auto"
const ChatCompletionContentPartImageImageURLDetailLow ChatCompletionContentPartImageImageURLDetail = "low"
const ChatCompletionContentPartImageImageURLDetailHigh ChatCompletionContentPartImageImageURLDetail = "high"
Type ImageURL

The type of the content part.

type ChatCompletionContentPartInputAudio struct{…}

Learn about audio inputs.

InputAudio ChatCompletionContentPartInputAudioInputAudio
Data string

Base64 encoded audio data.

Format string

The format of the encoded audio data. Currently supports "wav" and "mp3".

Accepts one of the following:
const ChatCompletionContentPartInputAudioInputAudioFormatWAV ChatCompletionContentPartInputAudioInputAudioFormat = "wav"
const ChatCompletionContentPartInputAudioInputAudioFormatMP3 ChatCompletionContentPartInputAudioInputAudioFormat = "mp3"
Type InputAudio

The type of the content part. Always input_audio.

type ChatCompletionContentPartRefusal struct{…}
Refusal string

The refusal message generated by the model.

Type Refusal

The type of the content part.

type ChatCompletionContentPartText struct{…}

Learn about text inputs.

Text string

The text content.

Type Text

The type of the content part.

type ChatCompletionCustomTool struct{…}

A custom tool that processes input using a specified format.

Custom ChatCompletionCustomToolCustom

Properties of the custom tool.

Name string

The name of the custom tool, used to identify it in tool calls.

Description stringoptional

Optional description of the custom tool, used to provide more context.

Format ChatCompletionCustomToolCustomFormatUnionoptional

The input format for the custom tool. Default is unconstrained text.

Accepts one of the following:
ChatCompletionCustomToolCustomFormatText
Type Text

Unconstrained text format. Always text.

ChatCompletionCustomToolCustomFormatGrammar
Grammar ChatCompletionCustomToolCustomFormatGrammarGrammar

Your chosen grammar.

Definition string

The grammar definition.

Syntax string

The syntax of the grammar definition. One of lark or regex.

Accepts one of the following:
const ChatCompletionCustomToolCustomFormatGrammarGrammarSyntaxLark ChatCompletionCustomToolCustomFormatGrammarGrammarSyntax = "lark"
const ChatCompletionCustomToolCustomFormatGrammarGrammarSyntaxRegex ChatCompletionCustomToolCustomFormatGrammarGrammarSyntax = "regex"
Type Grammar

Grammar format. Always grammar.

Type Custom

The type of the custom tool. Always custom.

type ChatCompletionDeleted struct{…}
ID string

The ID of the chat completion that was deleted.

Deleted bool

Whether the chat completion was deleted.

Object ChatCompletionDeleted

The type of object being deleted.

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.

Content ChatCompletionDeveloperMessageParamContentUnionResp

The contents of the developer message.

Accepts one of the following:
string
Text string

The text content.

Type Text

The type of the content part.

Role Developer

The role of the messages author, in this case developer.

Name stringoptional

An optional name for the participant. Provides the model information to differentiate between participants of the same role.

type ChatCompletionFunctionCallOption struct{…}

Specifying a particular function via {"name": "my_function"} forces the model to call that function.

Name string

The name of the function to call.

type ChatCompletionFunctionMessageParamResp struct{…}
Content string

The contents of the function message.

Name string

The name of the function to call.

Role Function

The role of the messages author, in this case function.

type ChatCompletionFunctionTool struct{…}

A function tool that can be used to generate a response.

Type Function

The type of the tool. Currently, only function is supported.

type ChatCompletionMessage struct{…}

A chat completion message generated by the model.

Content string

The contents of the message.

Refusal string

The refusal message generated by the model.

Role Assistant

The role of the author of this message.

Annotations []ChatCompletionMessageAnnotationoptional

Annotations for the message, when applicable, as when using the web search tool.

Type URLCitation

The type of the URL citation. Always url_citation.

URLCitation ChatCompletionMessageAnnotationURLCitation

A URL citation when using web search.

EndIndex int64

The index of the last character of the URL citation in the message.

StartIndex int64

The index of the first character of the URL citation in the message.

Title string

The title of the web resource.

URL string

The URL of the web resource.

Audio ChatCompletionAudiooptional

If the audio output modality is requested, this object contains data about the audio response from the model. Learn more.

DeprecatedFunctionCall ChatCompletionMessageFunctionCalloptional

Deprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.

Arguments string

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.

Name string

The name of the function to call.

The tool calls generated by the model, such as function calls.

Accepts one of the following:
type ChatCompletionMessageFunctionToolCall struct{…}

A call to a function tool created by the model.

ID string

The ID of the tool call.

Function ChatCompletionMessageFunctionToolCallFunction

The function that the model called.

Arguments string

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.

Name string

The name of the function to call.

Type Function

The type of the tool. Currently, only function is supported.

type ChatCompletionMessageCustomToolCall struct{…}

A call to a custom tool created by the model.

ID string

The ID of the tool call.

Custom ChatCompletionMessageCustomToolCallCustom

The custom tool that the model called.

Input string

The input for the custom tool call generated by the model.

Name string

The name of the custom tool to call.

Type Custom

The type of the tool. Always custom.

type ChatCompletionMessageCustomToolCall struct{…}

A call to a custom tool created by the model.

ID string

The ID of the tool call.

Custom ChatCompletionMessageCustomToolCallCustom

The custom tool that the model called.

Input string

The input for the custom tool call generated by the model.

Name string

The name of the custom tool to call.

Type Custom

The type of the tool. Always custom.

type ChatCompletionMessageFunctionToolCall struct{…}

A call to a function tool created by the model.

ID string

The ID of the tool call.

Function ChatCompletionMessageFunctionToolCallFunction

The function that the model called.

Arguments string

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.

Name string

The name of the function to call.

Type Function

The type of the tool. Currently, only function is supported.

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.

Accepts one of the following:
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.

Content ChatCompletionDeveloperMessageParamContentUnionResp

The contents of the developer message.

Accepts one of the following:
string
Text string

The text content.

Type Text

The type of the content part.

Role Developer

The role of the messages author, in this case developer.

Name stringoptional

An optional name for the participant. Provides the model information to differentiate between participants of the same role.

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.

Content ChatCompletionSystemMessageParamContentUnionResp

The contents of the system message.

Accepts one of the following:
string
Text string

The text content.

Type Text

The type of the content part.

Role System

The role of the messages author, in this case system.

Name stringoptional

An optional name for the participant. Provides the model information to differentiate between participants of the same role.

type ChatCompletionUserMessageParamResp struct{…}

Messages sent by an end user, containing prompts or additional context information.

Content ChatCompletionUserMessageParamContentUnionResp

The contents of the user message.

Accepts one of the following:
string
Accepts one of the following:
type ChatCompletionContentPartText struct{…}

Learn about text inputs.

Text string

The text content.

Type Text

The type of the content part.

type ChatCompletionContentPartImage struct{…}

Learn about image inputs.

ImageURL ChatCompletionContentPartImageImageURL
URL string

Either a URL of the image or the base64 encoded image data.

formaturi
Detail stringoptional

Specifies the detail level of the image. Learn more in the Vision guide.

Accepts one of the following:
const ChatCompletionContentPartImageImageURLDetailAuto ChatCompletionContentPartImageImageURLDetail = "auto"
const ChatCompletionContentPartImageImageURLDetailLow ChatCompletionContentPartImageImageURLDetail = "low"
const ChatCompletionContentPartImageImageURLDetailHigh ChatCompletionContentPartImageImageURLDetail = "high"
Type ImageURL

The type of the content part.

type ChatCompletionContentPartInputAudio struct{…}

Learn about audio inputs.

InputAudio ChatCompletionContentPartInputAudioInputAudio
Data string

Base64 encoded audio data.

Format string

The format of the encoded audio data. Currently supports "wav" and "mp3".

Accepts one of the following:
const ChatCompletionContentPartInputAudioInputAudioFormatWAV ChatCompletionContentPartInputAudioInputAudioFormat = "wav"
const ChatCompletionContentPartInputAudioInputAudioFormatMP3 ChatCompletionContentPartInputAudioInputAudioFormat = "mp3"
Type InputAudio

The type of the content part. Always input_audio.

ChatCompletionContentPartFile
File ChatCompletionContentPartFileFile
FileData stringoptional

The base64 encoded file data, used when passing the file to the model as a string.

FileID stringoptional

The ID of an uploaded file to use as input.

Filename stringoptional

The name of the file, used when passing the file to the model as a string.

Type File

The type of the content part. Always file.

Role User

The role of the messages author, in this case user.

Name stringoptional

An optional name for the participant. Provides the model information to differentiate between participants of the same role.

type ChatCompletionAssistantMessageParamResp struct{…}

Messages sent by the model in response to user messages.

Role Assistant

The role of the messages author, in this case assistant.

Audio ChatCompletionAssistantMessageParamAudioRespoptional

Data about a previous audio response from the model. Learn more.

ID string

Unique identifier for a previous audio response from the model.

Content ChatCompletionAssistantMessageParamContentUnionRespoptional

The contents of the assistant message. Required unless tool_calls or function_call is specified.

Accepts one of the following:
string
[]ChatCompletionAssistantMessageParamContentArrayOfContentPartUnionResp
Accepts one of the following:
type ChatCompletionContentPartText struct{…}

Learn about text inputs.

Text string

The text content.

Type Text

The type of the content part.

type ChatCompletionContentPartRefusal struct{…}
Refusal string

The refusal message generated by the model.

Type Refusal

The type of the content part.

DeprecatedFunctionCall ChatCompletionAssistantMessageParamFunctionCallRespoptional

Deprecated and replaced by tool_calls. The name and arguments of a function that should be called, as generated by the model.

Arguments string

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.

Name string

The name of the function to call.

Name stringoptional

An optional name for the participant. Provides the model information to differentiate between participants of the same role.

Refusal stringoptional

The refusal message by the assistant.

The tool calls generated by the model, such as function calls.

Accepts one of the following:
type ChatCompletionMessageFunctionToolCall struct{…}

A call to a function tool created by the model.

ID string

The ID of the tool call.

Function ChatCompletionMessageFunctionToolCallFunction

The function that the model called.

Arguments string

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.

Name string

The name of the function to call.

Type Function

The type of the tool. Currently, only function is supported.

type ChatCompletionMessageCustomToolCall struct{…}

A call to a custom tool created by the model.

ID string

The ID of the tool call.

Custom ChatCompletionMessageCustomToolCallCustom

The custom tool that the model called.

Input string

The input for the custom tool call generated by the model.

Name string

The name of the custom tool to call.

Type Custom

The type of the tool. Always custom.

type ChatCompletionToolMessageParamResp struct{…}
Content ChatCompletionToolMessageParamContentUnionResp

The contents of the tool message.

Accepts one of the following:
string
Text string

The text content.

Type Text

The type of the content part.

Role Tool

The role of the messages author, in this case tool.

ToolCallID string

Tool call that this message is responding to.

type ChatCompletionFunctionMessageParamResp struct{…}
Content string

The contents of the function message.

Name string

The name of the function to call.

Role Function

The role of the messages author, in this case function.

type ChatCompletionMessageToolCallUnion interface{…}

A call to a function tool created by the model.

Accepts one of the following:
type ChatCompletionMessageFunctionToolCall struct{…}

A call to a function tool created by the model.

ID string

The ID of the tool call.

Function ChatCompletionMessageFunctionToolCallFunction

The function that the model called.

Arguments string

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.

Name string

The name of the function to call.

Type Function

The type of the tool. Currently, only function is supported.

type ChatCompletionMessageCustomToolCall struct{…}

A call to a custom tool created by the model.

ID string

The ID of the tool call.

Custom ChatCompletionMessageCustomToolCallCustom

The custom tool that the model called.

Input string

The input for the custom tool call generated by the model.

Name string

The name of the custom tool to call.

Type Custom

The type of the tool. Always custom.

type ChatCompletionModality string
Accepts one of the following:
const ChatCompletionModalityText ChatCompletionModality = "text"
const ChatCompletionModalityAudio ChatCompletionModality = "audio"
type ChatCompletionNamedToolChoice struct{…}

Specifies a tool the model should use. Use to force the model to call a specific function.

Function ChatCompletionNamedToolChoiceFunction
Name string

The name of the function to call.

Type Function

For function calling, the type is always function.

type ChatCompletionNamedToolChoiceCustom struct{…}

Specifies a tool the model should use. Use to force the model to call a specific custom tool.

Custom ChatCompletionNamedToolChoiceCustomCustom
Name string

The name of the custom tool to call.

Type Custom

For custom tool calling, the type is always custom.

type ChatCompletionPredictionContent struct{…}

Static predicted output content, such as the content of a text file that is being regenerated.

Content ChatCompletionPredictionContentContentUnion

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.

Accepts one of the following:
string
Text string

The text content.

Type Text

The type of the content part.

Type Content

The type of the predicted content you want to provide. This type is currently always content.

type ChatCompletionRole string

The role of the author of a message

Accepts one of the following:
const ChatCompletionRoleDeveloper ChatCompletionRole = "developer"
const ChatCompletionRoleSystem ChatCompletionRole = "system"
const ChatCompletionRoleUser ChatCompletionRole = "user"
const ChatCompletionRoleAssistant ChatCompletionRole = "assistant"
const ChatCompletionRoleTool ChatCompletionRole = "tool"
const ChatCompletionRoleFunction ChatCompletionRole = "function"
type ChatCompletionStoreMessage struct{…}

A chat completion message generated by the model.

ID string

The identifier of the chat message.

ContentParts []ChatCompletionStoreMessageContentPartUnionoptional

If a content parts array was provided, this is an array of text and image_url parts. Otherwise, null.

Accepts one of the following:
type ChatCompletionContentPartText struct{…}

Learn about text inputs.

Text string

The text content.

Type Text

The type of the content part.

type ChatCompletionContentPartImage struct{…}

Learn about image inputs.

ImageURL ChatCompletionContentPartImageImageURL
URL string

Either a URL of the image or the base64 encoded image data.

formaturi
Detail stringoptional

Specifies the detail level of the image. Learn more in the Vision guide.

Accepts one of the following:
const ChatCompletionContentPartImageImageURLDetailAuto ChatCompletionContentPartImageImageURLDetail = "auto"
const ChatCompletionContentPartImageImageURLDetailLow ChatCompletionContentPartImageImageURLDetail = "low"
const ChatCompletionContentPartImageImageURLDetailHigh ChatCompletionContentPartImageImageURLDetail = "high"
Type ImageURL

The type of the content part.

type ChatCompletionStreamOptions struct{…}

Options for streaming response. Only set this when you set stream: true.

IncludeObfuscation booloptional

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.

IncludeUsage booloptional

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.

Content ChatCompletionSystemMessageParamContentUnionResp

The contents of the system message.

Accepts one of the following:
string
Text string

The text content.

Type Text

The type of the content part.

Role System

The role of the messages author, in this case system.

Name stringoptional

An optional name for the participant. Provides the model information to differentiate between participants of the same role.

type ChatCompletionTokenLogprob struct{…}
Token string

The token.

Bytes []int64

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.

Logprob float64

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 []ChatCompletionTokenLogprobTopLogprob

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.

Token string

The token.

Bytes []int64

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.

Logprob float64

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.

type ChatCompletionToolUnion interface{…}

A function tool that can be used to generate a response.

Accepts one of the following:
type ChatCompletionFunctionTool struct{…}

A function tool that can be used to generate a response.

Type Function

The type of the tool. Currently, only function is supported.

type ChatCompletionCustomTool struct{…}

A custom tool that processes input using a specified format.

Custom ChatCompletionCustomToolCustom

Properties of the custom tool.

Name string

The name of the custom tool, used to identify it in tool calls.

Description stringoptional

Optional description of the custom tool, used to provide more context.

Format ChatCompletionCustomToolCustomFormatUnionoptional

The input format for the custom tool. Default is unconstrained text.

Accepts one of the following:
ChatCompletionCustomToolCustomFormatText
Type Text

Unconstrained text format. Always text.

ChatCompletionCustomToolCustomFormatGrammar
Grammar ChatCompletionCustomToolCustomFormatGrammarGrammar

Your chosen grammar.

Definition string

The grammar definition.

Syntax string

The syntax of the grammar definition. One of lark or regex.

Accepts one of the following:
const ChatCompletionCustomToolCustomFormatGrammarGrammarSyntaxLark ChatCompletionCustomToolCustomFormatGrammarGrammarSyntax = "lark"
const ChatCompletionCustomToolCustomFormatGrammarGrammarSyntaxRegex ChatCompletionCustomToolCustomFormatGrammarGrammarSyntax = "regex"
Type Grammar

Grammar format. Always grammar.

Type Custom

The type of the custom tool. Always custom.

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.

Accepts one of the following:
string
Accepts one of the following:
const ChatCompletionToolChoiceOptionAutoNone ChatCompletionToolChoiceOptionAuto = "none"
const ChatCompletionToolChoiceOptionAutoAuto ChatCompletionToolChoiceOptionAuto = "auto"
const ChatCompletionToolChoiceOptionAutoRequired ChatCompletionToolChoiceOptionAuto = "required"
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.

Type AllowedTools

Allowed tool configuration type. Always allowed_tools.

type ChatCompletionNamedToolChoice struct{…}

Specifies a tool the model should use. Use to force the model to call a specific function.

Function ChatCompletionNamedToolChoiceFunction
Name string

The name of the function to call.

Type Function

For function calling, the type is always function.

type ChatCompletionNamedToolChoiceCustom struct{…}

Specifies a tool the model should use. Use to force the model to call a specific custom tool.

Custom ChatCompletionNamedToolChoiceCustomCustom
Name string

The name of the custom tool to call.

Type Custom

For custom tool calling, the type is always custom.

type ChatCompletionToolMessageParamResp struct{…}
Content ChatCompletionToolMessageParamContentUnionResp

The contents of the tool message.

Accepts one of the following:
string
Text string

The text content.

Type Text

The type of the content part.

Role Tool

The role of the messages author, in this case tool.

ToolCallID string

Tool call that this message is responding to.

type ChatCompletionUserMessageParamResp struct{…}

Messages sent by an end user, containing prompts or additional context information.

Content ChatCompletionUserMessageParamContentUnionResp

The contents of the user message.

Accepts one of the following:
string
Accepts one of the following:
type ChatCompletionContentPartText struct{…}

Learn about text inputs.

Text string

The text content.

Type Text

The type of the content part.

type ChatCompletionContentPartImage struct{…}

Learn about image inputs.

ImageURL ChatCompletionContentPartImageImageURL
URL string

Either a URL of the image or the base64 encoded image data.

formaturi
Detail stringoptional

Specifies the detail level of the image. Learn more in the Vision guide.

Accepts one of the following:
const ChatCompletionContentPartImageImageURLDetailAuto ChatCompletionContentPartImageImageURLDetail = "auto"
const ChatCompletionContentPartImageImageURLDetailLow ChatCompletionContentPartImageImageURLDetail = "low"
const ChatCompletionContentPartImageImageURLDetailHigh ChatCompletionContentPartImageImageURLDetail = "high"
Type ImageURL

The type of the content part.

type ChatCompletionContentPartInputAudio struct{…}

Learn about audio inputs.

InputAudio ChatCompletionContentPartInputAudioInputAudio
Data string

Base64 encoded audio data.

Format string

The format of the encoded audio data. Currently supports "wav" and "mp3".

Accepts one of the following:
const ChatCompletionContentPartInputAudioInputAudioFormatWAV ChatCompletionContentPartInputAudioInputAudioFormat = "wav"
const ChatCompletionContentPartInputAudioInputAudioFormatMP3 ChatCompletionContentPartInputAudioInputAudioFormat = "mp3"
Type InputAudio

The type of the content part. Always input_audio.

ChatCompletionContentPartFile
File ChatCompletionContentPartFileFile
FileData stringoptional

The base64 encoded file data, used when passing the file to the model as a string.

FileID stringoptional

The ID of an uploaded file to use as input.

Filename stringoptional

The name of the file, used when passing the file to the model as a string.

Type File

The type of the content part. Always file.

Role User

The role of the messages author, in this case user.

Name stringoptional

An optional name for the participant. Provides the model information to differentiate between participants of the same role.

type ChatCompletionAllowedTools struct{…}

Constrains the tools available to the model to a pre-defined set.

Mode ChatCompletionAllowedToolsMode

Constrains the tools available to the model to a pre-defined set.

auto allows the model to pick from among the allowed tools and generate a message.

required requires the model to call one or more of the allowed tools.

Accepts one of the following:
const ChatCompletionAllowedToolsModeAuto ChatCompletionAllowedToolsMode = "auto"
const ChatCompletionAllowedToolsModeRequired ChatCompletionAllowedToolsMode = "required"
Tools []map[string, any]

A list of tool definitions that the model should be allowed to call.

For the Chat Completions API, the list of tool definitions might look like:

[
  { "type": "function", "function": { "name": "get_weather" } },
  { "type": "function", "function": { "name": "get_time" } }
]

ChatCompletionsMessages

Get chat messages
client.Chat.Completions.Messages.List(ctx, completionID, query) (*CursorPage[ChatCompletionStoreMessage], error)
GET/chat/completions/{completion_id}/messages