Skip to content

Chat

ChatCompletions

Create chat completion
client.chat.completions.create(ChatCompletionCreateParamsbody, RequestOptionsoptions?): ChatCompletion { id, choices, created, 5 more } | Stream<ChatCompletionChunk { id, choices, created, 5 more } >
POST/chat/completions
List Chat Completions
client.chat.completions.list(ChatCompletionListParams { after, limit, metadata, 2 more } query?, RequestOptionsoptions?): CursorPage<ChatCompletion { id, choices, created, 5 more } >
GET/chat/completions
Get chat completion
client.chat.completions.retrieve(stringcompletionID, RequestOptionsoptions?): ChatCompletion { id, choices, created, 5 more }
GET/chat/completions/{completion_id}
Update chat completion
client.chat.completions.update(stringcompletionID, ChatCompletionUpdateParams { metadata } body, RequestOptionsoptions?): ChatCompletion { id, choices, created, 5 more }
POST/chat/completions/{completion_id}
Delete chat completion
client.chat.completions.delete(stringcompletionID, RequestOptionsoptions?): ChatCompletionDeleted { id, deleted, object }
DELETE/chat/completions/{completion_id}
ModelsExpand Collapse
ChatCompletion { id, choices, created, 5 more }

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

id: string

A unique identifier for the chat completion.

choices: Array<Choice>

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

finish_reason: "stop" | "length" | "tool_calls" | 2 more

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:
"stop"
"length"
"tool_calls"
"content_filter"
"function_call"
index: number

The index of the choice in the list of choices.

logprobs: Logprobs | null

Log probability information for the choice.

content: Array<ChatCompletionTokenLogprob { token, bytes, logprob, top_logprobs } > | null

A list of message content tokens with log probability information.

token: string

The token.

bytes: Array<number> | null

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: number

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.

top_logprobs: Array<TopLogprob>

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: Array<number> | null

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: number

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.

refusal: Array<ChatCompletionTokenLogprob { token, bytes, logprob, top_logprobs } > | null

A list of message refusal tokens with log probability information.

token: string

The token.

bytes: Array<number> | null

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: number

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.

top_logprobs: Array<TopLogprob>

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: Array<number> | null

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: number

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.

message: ChatCompletionMessage { content, refusal, role, 4 more }

A chat completion message generated by the model.

created: number

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

model: string

The model used for the chat completion.

object: "chat.completion"

The object type, which is always chat.completion.

service_tier?: "auto" | "default" | "flex" | 2 more | null

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:
"auto"
"default"
"flex"
"scale"
"priority"
Deprecatedsystem_fingerprint?: string

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?: CompletionUsage { completion_tokens, prompt_tokens, total_tokens, 2 more }

Usage statistics for the completion request.

ChatCompletionAllowedToolChoice { allowed_tools, type }

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

allowed_tools: ChatCompletionAllowedTools { mode, tools }

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

type: "allowed_tools"

Allowed tool configuration type. Always allowed_tools.

ChatCompletionAssistantMessageParam { role, audio, content, 4 more }

Messages sent by the model in response to user messages.

role: "assistant"

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

audio?: Audio | null

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

id: string

Unique identifier for a previous audio response from the model.

content?: string | Array<ChatCompletionContentPartText { text, type } | ChatCompletionContentPartRefusal { refusal, type } > | null

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

Accepts one of the following:
string
Array<ChatCompletionContentPartText { text, type } | ChatCompletionContentPartRefusal { refusal, type } >
ChatCompletionContentPartText { text, type }

Learn about text inputs.

text: string

The text content.

type: "text"

The type of the content part.

ChatCompletionContentPartRefusal { refusal, type }
refusal: string

The refusal message generated by the model.

type: "refusal"

The type of the content part.

Deprecatedfunction_call?: FunctionCall | null

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?: string

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

refusal?: string | null

The refusal message by the assistant.

tool_calls?: Array<ChatCompletionMessageToolCall>

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

Accepts one of the following:
ChatCompletionMessageFunctionToolCall { id, function, type }

A call to a function tool created by the model.

id: string

The ID of the tool call.

function: Function { arguments, name }

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.

ChatCompletionMessageCustomToolCall { id, custom, type }

A call to a custom tool created by the model.

id: string

The ID of the tool call.

custom: Custom { input, name }

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.

ChatCompletionAudio { id, data, expires_at, transcript }

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.

expires_at: number

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.

ChatCompletionAudioParam { format, voice }

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

format: "wav" | "aac" | "mp3" | 3 more

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

Accepts one of the following:
"wav"
"aac"
"mp3"
"flac"
"opus"
"pcm16"
voice: (string & {}) | "alloy" | "ash" | "ballad" | 7 more

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 & {})
"alloy" | "ash" | "ballad" | 7 more
"alloy"
"ash"
"ballad"
"coral"
"echo"
"sage"
"shimmer"
"verse"
"marin"
"cedar"
ChatCompletionChunk { id, choices, created, 5 more }

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: Array<Choice>

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: Delta { content, function_call, refusal, 2 more }

A chat completion delta generated by streamed model responses.

content?: string | null

The contents of the chunk message.

Deprecatedfunction_call?: FunctionCall { arguments, name }

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.

refusal?: string | null

The refusal message generated by the model.

role?: "developer" | "system" | "user" | 2 more

The role of the author of this message.

Accepts one of the following:
"developer"
"system"
"user"
"assistant"
"tool"
tool_calls?: Array<ToolCall>
index: number
id?: string

The ID of the tool call.

function?: Function { arguments, name }
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.

finish_reason: "stop" | "length" | "tool_calls" | 2 more | null

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:
"stop"
"length"
"tool_calls"
"content_filter"
"function_call"
index: number

The index of the choice in the list of choices.

logprobs?: Logprobs | null

Log probability information for the choice.

content: Array<ChatCompletionTokenLogprob { token, bytes, logprob, top_logprobs } > | null

A list of message content tokens with log probability information.

token: string

The token.

bytes: Array<number> | null

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: number

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.

top_logprobs: Array<TopLogprob>

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: Array<number> | null

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: number

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.

refusal: Array<ChatCompletionTokenLogprob { token, bytes, logprob, top_logprobs } > | null

A list of message refusal tokens with log probability information.

token: string

The token.

bytes: Array<number> | null

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: number

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.

top_logprobs: Array<TopLogprob>

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: Array<number> | null

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: number

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: number

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: "chat.completion.chunk"

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

service_tier?: "auto" | "default" | "flex" | 2 more | null

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:
"auto"
"default"
"flex"
"scale"
"priority"
Deprecatedsystem_fingerprint?: string

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?: CompletionUsage { completion_tokens, prompt_tokens, total_tokens, 2 more } | null

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.

ChatCompletionContentPart = ChatCompletionContentPartText { text, type } | ChatCompletionContentPartImage { image_url, type } | ChatCompletionContentPartInputAudio { input_audio, type } | File { file, type }

Learn about text inputs.

Accepts one of the following:
ChatCompletionContentPartText { text, type }

Learn about text inputs.

text: string

The text content.

type: "text"

The type of the content part.

ChatCompletionContentPartImage { image_url, type }

Learn about image inputs.

image_url: ImageURL { url, detail }
url: string

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

formaturi
detail?: "auto" | "low" | "high"

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

Accepts one of the following:
"auto"
"low"
"high"
type: "image_url"

The type of the content part.

ChatCompletionContentPartInputAudio { input_audio, type }

Learn about audio inputs.

input_audio: InputAudio { data, format }
data: string

Base64 encoded audio data.

format: "wav" | "mp3"

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

Accepts one of the following:
"wav"
"mp3"
type: "input_audio"

The type of the content part. Always input_audio.

File { file, type }

Learn about file inputs for text generation.

file: File { file_data, file_id, filename }
file_data?: string

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

file_id?: string

The ID of an uploaded file to use as input.

filename?: string

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.

ChatCompletionContentPartImage { image_url, type }

Learn about image inputs.

image_url: ImageURL { url, detail }
url: string

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

formaturi
detail?: "auto" | "low" | "high"

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

Accepts one of the following:
"auto"
"low"
"high"
type: "image_url"

The type of the content part.

ChatCompletionContentPartInputAudio { input_audio, type }

Learn about audio inputs.

input_audio: InputAudio { data, format }
data: string

Base64 encoded audio data.

format: "wav" | "mp3"

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

Accepts one of the following:
"wav"
"mp3"
type: "input_audio"

The type of the content part. Always input_audio.

ChatCompletionContentPartRefusal { refusal, type }
refusal: string

The refusal message generated by the model.

type: "refusal"

The type of the content part.

ChatCompletionContentPartText { text, type }

Learn about text inputs.

text: string

The text content.

type: "text"

The type of the content part.

ChatCompletionCustomTool { custom, type }

A custom tool that processes input using a specified format.

custom: Custom { name, description, format }

Properties of the custom tool.

name: string

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

description?: string

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

format?: Text { type } | Grammar { grammar, type }

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

Accepts one of the following:
Text { type }

Unconstrained free-form text.

type: "text"

Unconstrained text format. Always text.

Grammar { grammar, type }

A grammar defined by the user.

grammar: Grammar { definition, syntax }

Your chosen grammar.

definition: string

The grammar definition.

syntax: "lark" | "regex"

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

Accepts one of the following:
"lark"
"regex"
type: "grammar"

Grammar format. Always grammar.

type: "custom"

The type of the custom tool. Always custom.

ChatCompletionDeleted { id, deleted, object }
id: string

The ID of the chat completion that was deleted.

deleted: boolean

Whether the chat completion was deleted.

object: "chat.completion.deleted"

The type of object being deleted.

ChatCompletionDeveloperMessageParam { content, role, name }

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: string | Array<ChatCompletionContentPartText { text, type } >

The contents of the developer message.

Accepts one of the following:
string
Array<ChatCompletionContentPartText { text, type } >
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?: string

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

ChatCompletionFunctionCallOption { name }

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

name: string

The name of the function to call.

ChatCompletionFunctionMessageParam { content, name, role }
content: string | null

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.

ChatCompletionFunctionTool { function, type }

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

function: FunctionDefinition { name, description, parameters, strict }
type: "function"

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

ChatCompletionMessage { content, refusal, role, 4 more }

A chat completion message generated by the model.

content: string | null

The contents of the message.

refusal: string | null

The refusal message generated by the model.

role: "assistant"

The role of the author of this message.

annotations?: Array<Annotation>

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

type: "url_citation"

The type of the URL citation. Always url_citation.

url_citation: URLCitation { end_index, start_index, title, url }

A URL citation when using web search.

end_index: number

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

start_index: number

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?: ChatCompletionAudio { id, data, expires_at, transcript } | null

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

Deprecatedfunction_call?: FunctionCall { arguments, name }

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.

tool_calls?: Array<ChatCompletionMessageToolCall>

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

Accepts one of the following:
ChatCompletionMessageFunctionToolCall { id, function, type }

A call to a function tool created by the model.

id: string

The ID of the tool call.

function: Function { arguments, name }

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.

ChatCompletionMessageCustomToolCall { id, custom, type }

A call to a custom tool created by the model.

id: string

The ID of the tool call.

custom: Custom { input, name }

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.

ChatCompletionMessageCustomToolCall { id, custom, type }

A call to a custom tool created by the model.

id: string

The ID of the tool call.

custom: Custom { input, name }

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.

ChatCompletionMessageFunctionToolCall { id, function, type }

A call to a function tool created by the model.

id: string

The ID of the tool call.

function: Function { arguments, name }

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.

ChatCompletionMessageParam = ChatCompletionDeveloperMessageParam { content, role, name } | ChatCompletionSystemMessageParam { content, role, name } | ChatCompletionUserMessageParam { content, role, name } | 3 more

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:
ChatCompletionDeveloperMessageParam { content, role, name }

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: string | Array<ChatCompletionContentPartText { text, type } >

The contents of the developer message.

Accepts one of the following:
string
Array<ChatCompletionContentPartText { text, type } >
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?: string

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

ChatCompletionSystemMessageParam { content, role, name }

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: string | Array<ChatCompletionContentPartText { text, type } >

The contents of the system message.

Accepts one of the following:
string
Array<ChatCompletionContentPartText { text, type } >
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?: string

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

ChatCompletionUserMessageParam { content, role, name }

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

content: string | Array<ChatCompletionContentPart>

The contents of the user message.

Accepts one of the following:
string
ChatCompletionContentPartText { text, type }

Learn about text inputs.

text: string

The text content.

type: "text"

The type of the content part.

ChatCompletionContentPartImage { image_url, type }

Learn about image inputs.

image_url: ImageURL { url, detail }
url: string

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

formaturi
detail?: "auto" | "low" | "high"

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

Accepts one of the following:
"auto"
"low"
"high"
type: "image_url"

The type of the content part.

ChatCompletionContentPartInputAudio { input_audio, type }

Learn about audio inputs.

input_audio: InputAudio { data, format }
data: string

Base64 encoded audio data.

format: "wav" | "mp3"

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

Accepts one of the following:
"wav"
"mp3"
type: "input_audio"

The type of the content part. Always input_audio.

File { file, type }

Learn about file inputs for text generation.

file: File { file_data, file_id, filename }
file_data?: string

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

file_id?: string

The ID of an uploaded file to use as input.

filename?: string

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?: string

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

ChatCompletionAssistantMessageParam { role, audio, content, 4 more }

Messages sent by the model in response to user messages.

role: "assistant"

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

audio?: Audio | null

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

id: string

Unique identifier for a previous audio response from the model.

content?: string | Array<ChatCompletionContentPartText { text, type } | ChatCompletionContentPartRefusal { refusal, type } > | null

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

Accepts one of the following:
string
Array<ChatCompletionContentPartText { text, type } | ChatCompletionContentPartRefusal { refusal, type } >
ChatCompletionContentPartText { text, type }

Learn about text inputs.

text: string

The text content.

type: "text"

The type of the content part.

ChatCompletionContentPartRefusal { refusal, type }
refusal: string

The refusal message generated by the model.

type: "refusal"

The type of the content part.

Deprecatedfunction_call?: FunctionCall | null

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?: string

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

refusal?: string | null

The refusal message by the assistant.

tool_calls?: Array<ChatCompletionMessageToolCall>

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

Accepts one of the following:
ChatCompletionMessageFunctionToolCall { id, function, type }

A call to a function tool created by the model.

id: string

The ID of the tool call.

function: Function { arguments, name }

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.

ChatCompletionMessageCustomToolCall { id, custom, type }

A call to a custom tool created by the model.

id: string

The ID of the tool call.

custom: Custom { input, name }

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.

ChatCompletionToolMessageParam { content, role, tool_call_id }
content: string | Array<ChatCompletionContentPartText { text, type } >

The contents of the tool message.

Accepts one of the following:
string
Array<ChatCompletionContentPartText { text, type } >
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.

tool_call_id: string

Tool call that this message is responding to.

ChatCompletionFunctionMessageParam { content, name, role }
content: string | null

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.

ChatCompletionMessageToolCall = ChatCompletionMessageFunctionToolCall { id, function, type } | ChatCompletionMessageCustomToolCall { id, custom, type }

A call to a function tool created by the model.

Accepts one of the following:
ChatCompletionMessageFunctionToolCall { id, function, type }

A call to a function tool created by the model.

id: string

The ID of the tool call.

function: Function { arguments, name }

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.

ChatCompletionMessageCustomToolCall { id, custom, type }

A call to a custom tool created by the model.

id: string

The ID of the tool call.

custom: Custom { input, name }

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.

ChatCompletionModality = "text" | "audio"
Accepts one of the following:
"text"
"audio"
ChatCompletionNamedToolChoice { function, type }

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

function: Function { name }
name: string

The name of the function to call.

type: "function"

For function calling, the type is always function.

ChatCompletionNamedToolChoiceCustom { custom, type }

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

custom: Custom { name }
name: string

The name of the custom tool to call.

type: "custom"

For custom tool calling, the type is always custom.

ChatCompletionPredictionContent { content, type }

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

content: string | Array<ChatCompletionContentPartText { text, type } >

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
Array<ChatCompletionContentPartText { text, type } >
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.

ChatCompletionRole = "developer" | "system" | "user" | 3 more

The role of the author of a message

Accepts one of the following:
"developer"
"system"
"user"
"assistant"
"tool"
"function"
ChatCompletionStoreMessage extends ChatCompletionMessage { content, refusal, role, 4 more } { id, content_parts }

A chat completion message generated by the model.

id: string

The identifier of the chat message.

content_parts?: Array<ChatCompletionContentPartText { text, type } | ChatCompletionContentPartImage { image_url, type } > | null

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

Accepts one of the following:
ChatCompletionContentPartText { text, type }

Learn about text inputs.

text: string

The text content.

type: "text"

The type of the content part.

ChatCompletionContentPartImage { image_url, type }

Learn about image inputs.

image_url: ImageURL { url, detail }
url: string

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

formaturi
detail?: "auto" | "low" | "high"

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

Accepts one of the following:
"auto"
"low"
"high"
type: "image_url"

The type of the content part.

ChatCompletionStreamOptions { include_obfuscation, include_usage }

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

include_obfuscation?: boolean

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.

include_usage?: boolean

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.

ChatCompletionSystemMessageParam { content, role, name }

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: string | Array<ChatCompletionContentPartText { text, type } >

The contents of the system message.

Accepts one of the following:
string
Array<ChatCompletionContentPartText { text, type } >
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?: string

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

ChatCompletionTokenLogprob { token, bytes, logprob, top_logprobs }
token: string

The token.

bytes: Array<number> | null

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: number

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.

top_logprobs: Array<TopLogprob>

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: Array<number> | null

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: number

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.

ChatCompletionTool = ChatCompletionFunctionTool { function, type } | ChatCompletionCustomTool { custom, type }

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

Accepts one of the following:
ChatCompletionFunctionTool { function, type }

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

function: FunctionDefinition { name, description, parameters, strict }
type: "function"

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

ChatCompletionCustomTool { custom, type }

A custom tool that processes input using a specified format.

custom: Custom { name, description, format }

Properties of the custom tool.

name: string

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

description?: string

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

format?: Text { type } | Grammar { grammar, type }

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

Accepts one of the following:
Text { type }

Unconstrained free-form text.

type: "text"

Unconstrained text format. Always text.

Grammar { grammar, type }

A grammar defined by the user.

grammar: Grammar { definition, syntax }

Your chosen grammar.

definition: string

The grammar definition.

syntax: "lark" | "regex"

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

Accepts one of the following:
"lark"
"regex"
type: "grammar"

Grammar format. Always grammar.

type: "custom"

The type of the custom tool. Always custom.

ChatCompletionToolChoiceOption = "none" | "auto" | "required" | ChatCompletionAllowedToolChoice { allowed_tools, type } | ChatCompletionNamedToolChoice { function, type } | ChatCompletionNamedToolChoiceCustom { custom, type }

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:
"none" | "auto" | "required"
"none"
"auto"
"required"
ChatCompletionAllowedToolChoice { allowed_tools, type }

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

allowed_tools: ChatCompletionAllowedTools { mode, tools }

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

type: "allowed_tools"

Allowed tool configuration type. Always allowed_tools.

ChatCompletionNamedToolChoice { function, type }

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

function: Function { name }
name: string

The name of the function to call.

type: "function"

For function calling, the type is always function.

ChatCompletionNamedToolChoiceCustom { custom, type }

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

custom: Custom { name }
name: string

The name of the custom tool to call.

type: "custom"

For custom tool calling, the type is always custom.

ChatCompletionToolMessageParam { content, role, tool_call_id }
content: string | Array<ChatCompletionContentPartText { text, type } >

The contents of the tool message.

Accepts one of the following:
string
Array<ChatCompletionContentPartText { text, type } >
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.

tool_call_id: string

Tool call that this message is responding to.

ChatCompletionUserMessageParam { content, role, name }

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

content: string | Array<ChatCompletionContentPart>

The contents of the user message.

Accepts one of the following:
string
ChatCompletionContentPartText { text, type }

Learn about text inputs.

text: string

The text content.

type: "text"

The type of the content part.

ChatCompletionContentPartImage { image_url, type }

Learn about image inputs.

image_url: ImageURL { url, detail }
url: string

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

formaturi
detail?: "auto" | "low" | "high"

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

Accepts one of the following:
"auto"
"low"
"high"
type: "image_url"

The type of the content part.

ChatCompletionContentPartInputAudio { input_audio, type }

Learn about audio inputs.

input_audio: InputAudio { data, format }
data: string

Base64 encoded audio data.

format: "wav" | "mp3"

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

Accepts one of the following:
"wav"
"mp3"
type: "input_audio"

The type of the content part. Always input_audio.

File { file, type }

Learn about file inputs for text generation.

file: File { file_data, file_id, filename }
file_data?: string

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

file_id?: string

The ID of an uploaded file to use as input.

filename?: string

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?: string

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

ChatCompletionAllowedTools { mode, tools }

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

mode: "auto" | "required"

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:
"auto"
"required"
tools: Array<Record<string, unknown>>

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(stringcompletionID, MessageListParams { after, limit, order } query?, RequestOptionsoptions?): CursorPage<ChatCompletionStoreMessage { id, content_parts } >
GET/chat/completions/{completion_id}/messages