Response details
Non-streaming results
A successful non-streamed response includes the following members:
id string
Unique ID for each request (not message). Same ID for all responses in a streaming response.
model string
The model used to generate the response.
choices list of objects
One or more responses, depending on the n
parameter from the request.
Each response includes the following members.
show more
index
Zero-based index of the message in the list of messages. Note that this might not correspond with the position in the response list.
message object
The message generated by the model.
role
content
tool_calls array of objects
Tool calls only occur if a tools parameter was specified in the request. These tool calls apply solely to the current message, and returned values should be added to the message thread in both the assistant message tool_calls fields and the tool message.
id string
ID of the tool call, generated by the model.
type string
The type of tool called. Currently the only possible value is "function".
function object
The invoked function.
show more
- name string
The name of the function, which you specified in your request.
- arguments object
A JSON object containing the function's parameters and values.
finish_reason string
Why the message ended.
show more
stop: The response ended naturally as a complete answer (due to end-of-sequence token) or because the model generated a stop sequence provided in the request.
length: The response ended by reaching max_tokens.
usage object
The token counts for this request.
Per-token billing is based on the prompt token and completion token counts and rates.
cop
show more
prompt_tokens integer
Number of tokens in the prompt for this request.
The prompt token contains the entire message history and extra tokens for combining messages, proportional to the number of messages.
completion_tokens integer
Number of tokens in the response message.
total_tokens integer
prompt_tokens and completion_tokens.
Response Example
{
"id": "chatcmpl-e4714c34-e0f9-723c-82e4-9f39a242533d",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "I'm sorry to hear that you're having trouble. Can you provide more details about the issue you're experiencing? For example, are you encountering an error message, or is something else happening?",
"tool_calls": null
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 66,
"completion_tokens": 43,
"total_tokens": 109
}
Streamed results
Setting stream = true
in the request will return a stream of messages, each containing one token.
Read more about streaming calls using the SDK.
The last message will be data:[DONE]
. The other messages will have data set to a JSON object with the following fields:
data object
An object containing either an object with the following members, or the string "DONE" for the last message.
id string
Unique ID for each request (not message). Same ID for all streaming responses.
choices object
An array with one object containing the following fields:
index integer
Always zero.
delta object
- The first message in the stream will be an object set to
{"role":"assistant"}
. - Subsequent messages will have an object
{"content": __token__}
with the generated token.
finish_reason string
show more
usage object
The last message includes this field, which shows the total token counts for the request. Per-token billing is based on the prompt token and completion token counts and rates.
When present, it contains a null value except for the last chunk which contains the token usage statistics for the entire request.
show more
prompt_tokens integer
Number of tokens in the prompt for this request.
The prompt token contains the entire message history and extra tokens for combining messages, proportional to the number of messages.
completion_tokens integer
Number of tokens in the response message.
total_tokens integer
prompt_tokens and completion_tokens.
Response Example
{
"id": "chatcmpl-df270136-7f88-e600-dd58-e83cee415d71",
"choices": [
{
"index": 0,
"delta": {
"content": "",
"role": null
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 66,
"completion_tokens": 41,
"total_tokens": 107
}
}
}
usage
will be null
except for the last chunk which contains the token usage statistics for the entire request.
{
"id": "chatcmpl-df270136-7f88-e600-dd58-e83cee415d71",
"choices": [
{
"index": 0,
"delta": {
"content": "?",
"role": null
},
"logprobs": null,
"finish_reason": null
}
],
"usage": null
}
Error Codes
500 - Internal Server Error
429 - Too Many Requests (You are sending requests too quickly.)
503 - Service Unavailable (The engine is currently overloaded, please try again later)
401 - Unauthorized (Incorrect API key provided/Invalid Authentication)
403 - Access Denied
422 - Unprocurable Entity (Request body is malformed)