Chat Completions
POST/v1/chat/completions
Follows the exact same API spec as OpenAI's Chat API https://platform.openai.com/docs/api-reference/chat
Request
- application/json
Body
required
Array [
- User message
- Assistant message
- System message
- Tool message
- Function message
- Developer message
- MOD1
- MOD2
Array [
- Text content
- Image content
]
Array [
]
]
- MOD1
- MOD2
Array [
]
Array [
]
- MOD1
- MOD2
ID of the model to use
messages
object[]
required
A list of messages comprising the conversation so far
oneOf
The role of the message author
Possible values: [user]
content
object
required
The contents of the message
anyOf
The text contents of the message
string
An array of content parts
oneOf
Possible values: [text]
Possible values: [image_url]
image_url
object
required
Either a URL of the image or the base64 encoded image data
Possible values: [auto, low, high]
autoAn optional name for the participant
The role of the message author
Possible values: [assistant]
The contents of the message
An optional name for the participant
tool_calls
object[]
The tool calls generated by the model
The ID of the tool call
The type of the tool
Possible values: [function]
function
object
required
The name of the function to call
The arguments to call the function with, as generated by the model in JSON format
function_call
object
deprecated
Deprecated and replaced by tool_calls
The name of the function to call
The arguments to call the function with
The role of the message author
Possible values: [system]
The contents of the system message
An optional name for the participant
The role of the message author
Possible values: [tool]
The contents of the tool message
The ID of the tool call that this message is responding to.
The role of the message author
Possible values: [function]
The contents of the function message
The name of the function to call
The role of the message author
Possible values: [developer]
The contents of the developer message
An optional name for the participant
Number between -2.0 and 2.0. Positive values penalize new tokens based on their existing frequency in the text so far
Possible values: >= -2 and <= 2
0logit_bias
object
nullable
Modify the likelihood of specified tokens appearing in the completion
Whether to return log probabilities of the output tokens (must be paired with top_logprobs set and viceversa)
falseAn integer between 0 and 20 specifying the number of most likely tokens to return at each token position (must be paired with logprobs set to true and viceversa)
Possible values: <= 20
The maximum number of tokens that can be generated in the chat completion
16How many chat completion choices to generate for each input message
Possible values: >= 1 and <= 128
1Number between -2.0 and 2.0. Positive values penalize new tokens based on whether they appear in the text so far
Possible values: >= -2 and <= 2
0response_format
object
nullable
An object specifying the format that the model must output
The type of response format
Possible values: [text, json_object, json_schema]
json_schema
object
The JSON schema for the response format
falseIf specified, our system will make a best effort to sample deterministically
stop
object
Up to 4 sequences where the API will stop generating further tokens
oneOf
string
string
If set, partial message deltas will be sent
falsestream_options
object
nullable
Options for streaming response
If set, an additional chunk will be streamed with usage statistics
What sampling temperature to use, between 0 and 2
Possible values: <= 2
1An alternative to sampling with temperature, called nucleus sampling
Possible values: <= 1
1tools
object[]
nullable
A list of tools the model may call
The type of the tool
Possible values: [function]
function
object
required
The name of the function to be called
A description of what the function does
The parameters the functions accepts, described as a JSON Schema object
Whether to enable strict schema adherence
falsetool_choice
object
Controls which (if any) tool is called by the model
oneOf
Controls which (if any) tool is called by the model
string
Possible values: [none, auto, required]
Specifies a tool the model should use
Possible values: [function]
function
object
required
The name of the function to call
Whether to enable parallel function calling during tool use
trueA unique identifier representing your end-user
Responses
- 200
- 400
Successful Response
- application/json
- text/event-stream
- Schema
- Example (from schema)
Schema
Array [
Array [
]
]
A unique identifier for the chat completion
The object type, which is always chat.completion
Possible values: [chat.completion]
The Unix timestamp (in seconds) of when the chat completion was created
The model used for the chat completion
choices
object[]
required
A list of chat completion choices
The index of the choice in the list of choices
message
object
required
The role of the message author
Possible values: [assistant]
The contents of the message
An optional name for the participant
tool_calls
object[]
The tool calls generated by the model
The ID of the tool call
The type of the tool
Possible values: [function]
function
object
required
The name of the function to call
The arguments to call the function with, as generated by the model in JSON format
function_call
object
deprecated
Deprecated and replaced by tool_calls
The name of the function to call
The arguments to call the function with
Log probability information for the choice
The reason the model stopped generating tokens
Possible values: [stop, length, tool_calls, content_filter, function_call]
usage
object
required
Number of tokens in the prompt
Number of tokens in the generated completion
Total number of tokens used in the request
This fingerprint represents the backend configuration
{
"id": "string",
"object": "chat.completion",
"created": 0,
"model": "string",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "string",
"name": "string",
"tool_calls": [
{
"id": "string",
"type": "function",
"function": {
"name": "string",
"arguments": "string"
}
}
]
},
"logprobs": {},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
},
"system_fingerprint": "string"
}
- Schema
- Example (from schema)
- Stream
Schema
Array [
Array [
]
]
A unique identifier for the chat completion
The object type, which is always chat.completion.chunk
Possible values: [chat.completion.chunk]
The Unix timestamp (in seconds) of when the chat completion was created
The model used for the chat completion
choices
object[]
required
A list of chat completion choice deltas. Empty array in the final usage-only chunk when stream_options.include_usage is true.
The index of the choice in the list of choices
delta
object
required
Contenuto incrementale del messaggio in questo chunk. Il client deve concatenare il campo content di ogni chunk per ricostruire il messaggio completo.
Present only in the first chunk of the stream
Possible values: [assistant]
Incremental content fragment for this chunk
tool_calls
object[]
Present when the model is calling one or more tools. Each field other than index arrives fragmented across multiple chunks and must be concatenated client-side.
Possible values: [function]
function
object
JSON string fragment, to be concatenated
Log probability information for the choice
The reason the model stopped generating tokens. Null in every chunk except the last one for this choice.
Possible values: [stop, length, tool_calls, content_filter, function_call]
usage
object
nullable
Present only in the final chunk, and only if stream_options.include_usage was true in the request. In that chunk, choices is an empty array.
Number of tokens in the prompt
Number of tokens in the generated completion
Total number of tokens used in the request
This fingerprint represents the backend configuration
{
"id": "string",
"object": "chat.completion.chunk",
"created": 0,
"model": "string",
"choices": [
{
"index": 0,
"delta": {
"role": "assistant",
"content": "string",
"tool_calls": [
{
"index": 0,
"id": "string",
"type": "function",
"function": {
"name": "string",
"arguments": "string"
}
}
]
},
"logprobs": {},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
},
"system_fingerprint": "string"
}
data: {"id":"chatcmpl-8f9a3b1c2d","object":"chat.completion.chunk","created":1717000000,"model":"gpt-oss-20b","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null}]}
data: {"id":"chatcmpl-8f9a3b1c2d","object":"chat.completion.chunk","created":1717000000,"model":"gpt-oss-20b","choices":[{"index":0,"delta":{"content":"Paris"},"finish_reason":null}]}
data: {"id":"chatcmpl-8f9a3b1c2d","object":"chat.completion.chunk","created":1717000000,"model":"gpt-oss-20b","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: {"id":"chatcmpl-8f9a3b1c2d","object":"chat.completion.chunk","created":1717000000,"model":"gpt-oss-20b","choices":[],"usage":{"prompt_tokens":15,"completion_tokens":8,"total_tokens":23}}
data: [DONE]
Bad request Error when passing an invalid or non-existing model name or an invalid enum or an invalid type in a field
- application/json
- Schema
- Example (from schema)
Schema
error
object
required
Error returned as response for invalid or missing model name
{
"error": {
"message": "string",
"type": "string",
"param": "string",
"code": "string"
}
}