Endpoint
Request Headers
Request Body
Message Format
Each message in themessages array has this structure:
Multi-Turn Conversation
Include previous messages to maintain context:Streaming Response
Whenstream: true (the default), the response is a series of Server-Sent Events:
data: line contains a JSON chunk. Key fields:
Usage Object
The final chunk includes token usage and cost:Non-Streaming Response
Whenstream: false and the request includes the X-Response-Format: openai header, the response is a single JSON object in the standard OpenAI Chat Completions shape:
Without the OpenAI-compatible clients and proxies expect
X-Response-Format: openai header, non-streaming responses use the legacy format, which nests the completion object under data and adds a success flag:choices at the top level, so send the header when using them. Streaming responses are unaffected and always use the standard OpenAI format.Tool Calling
You can define tools that the model can call using the OpenAI function calling format:tool_calls array:
Reasoning Models
Some models support extended thinking (reasoning). When using these models, the response may include reasoning content in the streaming delta:delta.reasoning field. Some providers return encrypted reasoning blocks via delta.reasoning_details that can be passed back in subsequent requests to preserve the reasoning trace.
Not all models support reasoning. See Models for which models have reasoning capabilities.
Complete Example
Related
Models
Browse available models and their capabilities.
Errors
Handle errors and implement retry logic.
SDK Examples
Use this endpoint from Python, Node.js, and more.
Authentication
API key management and security practices.