Skip to main content
The Chat Completions endpoint generates model responses from a conversation. It follows the OpenAI Chat Completions format.

Endpoint

Request Headers

Request Body

Message Format

Each message in the messages array has this structure:
Roles:

Multi-Turn Conversation

Include previous messages to maintain context:

Streaming Response

When stream: true (the default), the response is a series of Server-Sent Events:
Each data: line contains a JSON chunk. Key fields:

Usage Object

The final chunk includes token usage and cost:

Non-Streaming Response

When stream: false, the response is a single JSON object:

Tool Calling

You can define tools that the model can call using the OpenAI function calling format:
When the model decides to call a tool, the response includes a tool_calls array:
To continue the conversation after a tool call, include the tool result:

Reasoning Models

Some models support extended thinking (reasoning). When using these models, the response may include reasoning content in the streaming delta:
Reasoning tokens are separate from the main content and appear in the 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

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.