Async Messages
Initiate Async Chat Stream
Initiate an asynchronous chat completion stream.
This endpoint starts an asynchronous chat completion process that streams events. Unlike synchronous chat, this endpoint returns immediately with a message_id that can be used to observe the stream progress.
Key Features:
- Asynchronous Processing: Non-blocking request handling with immediate response
- Stream Observation: Use returned message_id to observe real-time events
- Works exactly like synchronous chat, but in an async manner
Notes:
- Optional message_id query parameter for custom stream identification
- Stream events follow the same format as synchronous chat responses
- Stream status can be monitored via status endpoint
post/v1/messages/async
Query parameters
message_idstring nullable
Optional custom identifier for the stream. If not provided, a unique ID will be generated automatically.
Example:custom_msg_12345
Optional custom identifier for the stream. If not provided, a unique ID will be generated automatically.
Request body
Example request
{
"max_tokens": 1000,
"messages": [
{
"content": "How do you fry an egg? Choose the best method.",
"role": "user"
}
],
"response_format": {
"type": "text"
},
"stream": false,
"system": {
"citations": {
"enabled": true
},
"text": "You are a helpful cooking assistant. Provide clear, step-by-step instructions."
},
"temperature": 0.7,
"thinking": {
"enabled": false
},
"tool_choice": {
"disable_parallel_tool_use": false,
"type": "auto"
},
"tools": [
{
"description": "A tool to fry eggs with precise temperature control",
"input_schema": {
"properties": {
"temperature": {
"description": "Temperature in degrees Celsius",
"type": "number"
},
"time": {
"description": "Time in minutes to fry the egg",
"type": "number"
}
},
"required": [
"temperature",
"time"
],
"type": "object"
},
"name": "egg_fryer"
}
]
}Response
Chat stream initiated successfully
Example response
{
"message": "Request initiated successfully",
"message_id": "msg_async_12345",
"status": "pending"
}