List chat completions
GET https://api.fastapi.ai/v1/chat/completions
List stored chat completions. Only chat completions that have been stored with the store
parameter set to true
will be returned.
Query parameters
model
string Optional
The model used to generate the chat completions.
metadata
Optional
A list of metadata keys to filter the chat completions by. Example:
metadata[key1]=value1&metadata[key2]=value2
after
string Optional
Identifier for the last chat completion from the previous pagination request.
limit
integer Optional Defaults to 20
Number of chat completions to retrieve.
order
string Optional Defaults to asc
Sort order for chat completions by timestamp. Use asc
for ascending order or desc
for descending order. Defaults to asc
.
Returns
A list of chat completions matching the specified filters.
The chat completion list object
An object representing a list of chat completions.
object
string
The type of this object. It is always set to "list".
data
array
An array of chat completion objects.
id
string
A unique identifier for the chat completion.
choices array
A list of chat completion choices. Can be more than one if n is greater than 1.
finish_reason
string
The reason the model stopped generating tokens. This will bestop
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, orfunction_call
(deprecated) if the model called a function.
index
integer
The index of the choice in the list of choices.
message
object
A chat completion message generated by the model.
content
string or null
The contents of the message.
refusal
string or null
The refusal message generated by the model.
tool_calls
array
The tool calls generated by the model, such as function calls.
id
string
The ID of the tool call.
type
string
The type of the tool. Currently, onlyfunction
is supported.
function
object
The function that the model called.
name
string
The name of the function to call.
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.
role
string
The role of the author of this message.
function_call
Deprecated object
Deprecated and replaced bytool_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.
audio
object or null
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.
expires_at
integer
The Unix timestamp (in seconds) for when this audio response will no longer be accessible on the server for use in multi-turn conversations.
data
string
Base64 encoded audio bytes generated by the model, in the format specified in the request.
transcript
string
Transcript of the audio generated by the model.
id
string
The identifier of the chat message.
logprobs
object or null
Log probability information for the choice.
content
array or null
A list of message content tokens with log probability information.
token
string
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.
bytes
array or 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 benull
if there is no bytes representation for the token.
top_logprobs
array
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 requestedtop_logprobs
returned.
token
string
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.
bytes
array or 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 benull
if there is no bytes representation for the token.
created
integer
The Unix timestamp (in seconds) of when the chat completion was created.
model
string
The model used for the chat completion.
service_tier
string or null
The service tier used for processing the request.
system_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.
object
string
The object type, which is always chat.completion
.
usage
object
Usage statistics for the completion request.
completion_tokens
integer
Number of tokens in the generated completion.
prompt_tokens
integer
Number of tokens in the prompt.
total_tokens
integer
Total number of tokens used in the request (prompt + completion).
completion_tokens_details object
Breakdown of tokens used in a completion.
accepted_prediction_tokens
integer
When using Predicted Outputs, the number of tokens in the prediction that appeared in the completion.
audio_tokens
integer
Audio input tokens generated by the model.
reasoning_tokens
integer
Tokens generated by the model for reasoning.
rejected_prediction_tokens
integer
When using Predicted Outputs, the number of tokens in the prediction that did not appear in the completion. However, like reasoning tokens, these tokens are still counted in the total completion tokens for purposes of billing, output, and context window limits.
prompt_tokens_details object
Breakdown of tokens used in the prompt.
audio_tokens
integer
Audio input tokens present in the prompt.
cached_tokens
integer
Cached tokens present in the prompt.
first_id
string
The identifier of the first chat completion in the data array.
last_id
string
The identifier of the last chat completion in the data array.
has_more
boolean
Indicates whether there are more chat completions available.
{
"object": "list",
"data": [
{
"object": "chat.completion",
"id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2",
"model": "gpt-4o-2024-08-06",
"created": 1738960610,
"request_id": "req_ded8ab984ec4bf840f37566c1011c417",
"tool_choice": null,
"usage": {
"total_tokens": 31,
"completion_tokens": 18,
"prompt_tokens": 13
},
"seed": 4944116822809979520,
"top_p": 1.0,
"temperature": 1.0,
"presence_penalty": 0.0,
"frequency_penalty": 0.0,
"system_fingerprint": "fp_50cad350e4",
"input_user": null,
"service_tier": "default",
"tools": null,
"metadata": {},
"choices": [
{
"index": 0,
"message": {
"content": "Mind of circuits hum, \nLearning patterns in silence— \nFuture's quiet spark.",
"role": "assistant",
"tool_calls": null,
"function_call": null
},
"finish_reason": "stop",
"logprobs": null
}
],
"response_format": null
}
],
"first_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2",
"last_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2",
"has_more": false
}
Example
Request
curl https://api.fastapi.ai/v1/chat/completions \
-H "Authorization: Bearer $FAST_API_KEY" \
-H "Content-Type: application/json"
Response
{
"object": "list",
"data": [
{
"object": "chat.completion",
"id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2",
"model": "gpt-4o-2024-08-06",
"created": 1738960610,
"request_id": "req_ded8ab984ec4bf840f37566c1011c417",
"tool_choice": null,
"usage": {
"total_tokens": 31,
"completion_tokens": 18,
"prompt_tokens": 13
},
"seed": 4944116822809979520,
"top_p": 1.0,
"temperature": 1.0,
"presence_penalty": 0.0,
"frequency_penalty": 0.0,
"system_fingerprint": "fp_50cad350e4",
"input_user": null,
"service_tier": "default",
"tools": null,
"metadata": {},
"choices": [
{
"index": 0,
"message": {
"content": "Mind of circuits hum, \nLearning patterns in silence— \nFuture's quiet spark.",
"role": "assistant",
"tool_calls": null,
"function_call": null
},
"finish_reason": "stop",
"logprobs": null
}
],
"response_format": null
}
],
"first_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2",
"last_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2",
"has_more": false
}