Skip to content
  • Auto
  • Light
  • Dark
Log in to API

Chat

Chat

Chat

Completion Message
CompletionMessageclass

A message containing the model's (assistant) response in a chat conversation.

ShowShow
roleliteral
Literal["assistant"]

Must be "assistant" to identify this as the model's response

Hide ParametersShow Parameters
"assistant"
contentContentUnionMember0strContent
optional

The content of the model's response.

Hide ParametersShow Parameters
ContentUnionMember0type
str
textstrtypeliteralMessageTextContentItem
stop_reasonliteral
optional
Optional[Literal["stop", "tool_calls", "length"]]

The reason why we stopped. Options are: - "stop": The model reached a natural stopping point. - "tool_calls": The model finished generating and invoked a tool call. - "length": The model reached the maxinum number of tokens specified in the request.

Hide ParametersShow Parameters
"stop"
"tool_calls"
"length"
tool_callslist
optional
Optional[List[ToolCall]]

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

Hide ParametersShow Parameters
idstr

The ID of the tool call.

functionargumentsstrnamestrToolCallFunction

The function that the model called.

Hide ParametersShow Parameters
argumentsstr

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.

namestr

The name of the function to call.

Create Chat Completion Response
CreateChatCompletionResponseclass

Response from a chat completion request.

ShowShow
completion_messageroleliteralcontentContentstop_reasonliteraltool_callslistCompletionMessage

The complete response message

idstr
optional

The unique identifier of the chat completion request.

metricslist
optional
Optional[List[Metric]]
Hide ParametersShow Parameters
metricstr
valuefloat
unitstr
optional
Create Chat Completion Response Stream Chunk
CreateChatCompletionResponseStreamChunkclass

A chunk of a streamed chat completion response.

ShowShow
eventdeltaEventDeltaevent_typeliteralmetricsliststop_reasonliteralEvent

The event containing the new content

Hide ParametersShow Parameters

Content generated since last event. This can be one or more tokens, or a tool call.

Hide ParametersShow Parameters
EventDeltaTextDeltaclass
Hide ParametersShow Parameters
textstr
typeliteral
Literal["text"]
Hide ParametersShow Parameters
"text"
EventDeltaToolCallDeltaclass
Hide ParametersShow Parameters
functionargumentsstrnamestrEventDeltaToolCallDeltaFunction
Hide ParametersShow Parameters
argumentsstr
optional

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.

namestr
optional

The name of the function to call.

typeliteral
Literal["tool_call"]
Hide ParametersShow Parameters
"tool_call"
idstr
optional

The ID of the tool call.

event_typeliteral
Literal["start", "complete", "progress", "metrics"]

Type of the event

Hide ParametersShow Parameters
"start"
"complete"
"progress"
"metrics"
metricslist
optional
Optional[List[EventMetric]]
Hide ParametersShow Parameters
metricstr
valuefloat
unitstr
optional
stop_reasonliteral
optional
Optional[Literal["stop", "tool_calls", "length"]]

The reason why we stopped. Options are: - "stop": The model reached a natural stopping point. - "tool_calls": The model finished generating and invoked a tool call. - "length": The model reached the maxinum number of tokens specified in the request.

Hide ParametersShow Parameters
"stop"
"tool_calls"
"length"
idstr
optional

The unique identifier of the chat completion request.

Message
Messagetype

A message from the user in a chat conversation.

ShowShow
contentunionroleliteralUserMessage
contentunionroleliteralSystemMessage
contentunionroleliteraltool_call_idstrToolResponseMessage
roleliteralcontentContentstop_reasonliteraltool_callslistCompletionMessage
Message Image Content Item
MessageImageContentItemclass

A image content item

ShowShow
image_urlurlstrImageURL

Contains either an image URL or a data URL for a base64 encoded image.

Hide ParametersShow Parameters
urlstr

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

formaturi
typeliteral
Literal["image_url"]

Discriminator type of the content item. Always "image"

Hide ParametersShow Parameters
"image_url"
Message Text Content Item
MessageTextContentItemclass

A text content item

ShowShow
textstr

Text content

typeliteral
Literal["text"]

Discriminator type of the content item. Always "text"

Hide ParametersShow Parameters
"text"
System Message
SystemMessageclass

A system message providing instructions or context to the model.

ShowShow
contentunion
Union[str, List[textstrtypeliteralMessageTextContentItem]]

The content of the system message.

Hide ParametersShow Parameters
ContentTextContenttype
str

The text contents of the message.

ContentArrayOfContentItemstype
List[textstrtypeliteralMessageTextContentItem]

A list of content items, which can include text and other media. Supported content types differ based on model.

Hide ParametersShow Parameters
textstr

Text content

typeliteral
Literal["text"]

Discriminator type of the content item. Always "text"

Hide ParametersShow Parameters
"text"
roleliteral
Literal["system"]

Must be "system" to identify this as a system message

Hide ParametersShow Parameters
"system"
Tool Response Message
ToolResponseMessageclass

A message representing the result of a tool invocation.

ShowShow
contentunion
Union[str, List[textstrtypeliteralMessageTextContentItem]]

The content of the user message, which can include text and other media.

Hide ParametersShow Parameters
ContentTextContenttype
str

The text contents of the message.

ContentArrayOfContentItemstype
List[textstrtypeliteralMessageTextContentItem]

A list of content items, which can include text and other media. Supported content types differ based on model.

Hide ParametersShow Parameters
textstr

Text content

typeliteral
Literal["text"]

Discriminator type of the content item. Always "text"

Hide ParametersShow Parameters
"text"
roleliteral
Literal["tool"]

Must be "tool" to identify this as a tool response

Hide ParametersShow Parameters
"tool"
tool_call_idstr

Unique identifier for the tool call this response is for

User Message
UserMessageclass

A message from the user in a chat conversation.

ShowShow
contentunion
Union[str, List[ContentArrayOfContentItem]]

The content of the user message, which can include text and other media.

Hide ParametersShow Parameters
ContentTextContenttype
str

The text contents of the message.

ContentArrayOfContentItemstype

A list of content items, which can include text and other media. Supported content types differ based on model.

Hide ParametersShow Parameters
textstrtypeliteralMessageTextContentItem
roleliteral
Literal["user"]

Must be "user" to identify this as a user message.

Hide ParametersShow Parameters
"user"

ChatCompletions

Create
chat.completions.create(CompletionCreateParams**kwargs) -> completion_messageCompletionMessageidstrmetricslistCreateChatCompletionResponse
post/chat/completions