Get chat messages
GET https://api.fastapi.ai/v1/chat/completions/{completion_id}/messages
Get the messages in a stored chat completion. Only chat completions that have been created with the store
parameter set to true
will be returned.
Path parameters
completion_id
string Required
The ID of the chat completion to retrieve messages from.
Query parameters
after
string Optional
Identifier for the last message from the previous pagination request.
limit
integer Optional Defaults to 20
Number of messages to retrieve.
order
string Optional Defaults to asc
Sort order for messages by timestamp. Use asc
for ascending order or desc
for descending order. Defaults to asc
.
Returns
A list of messages for the specified chat completion.
The chat completion message list object
An object representing a list of chat completion messages.
object
string
The type of this object. It is always set to "list".
data
array
An array of chat completion message objects.
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 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.
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.
first_id
string
The identifier of the first chat message in the data array.
last_id
string
The identifier of the last chat message in the data array.
has_more
boolean
Indicates whether there are more chat messages available.
{
"object": "list",
"data": [
{
"id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"role": "user",
"content": "write a haiku about ai",
"name": null,
"content_parts": null
}
],
"first_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"last_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"has_more": false
}
Example
Request
curl https://api.fastapi.ai/v1/chat/completions/chat_abc123/messages \
-H "Authorization: Bearer $FAST_API_KEY" \
-H "Content-Type: application/json"
Response
{
"object": "list",
"data": [
{
"id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"role": "user",
"content": "write a haiku about ai",
"name": null,
"content_parts": null
}
],
"first_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"last_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"has_more": false
}