Endpoint
Request headers
string
required
Bearer token for authentication. Format:
Bearer YOUR_API_KEY.string
required
Must be
application/json.string
Your application’s URL. Used for usage tracking in logs.
string
Your application’s name. Appears in usage logs.
Request body
string
required
Model ID in
provider/model-name format. For example: anthropic/claude-sonnet-4-6, openai/gpt-4o, google/gemini-2.5-pro. See Models for available options.object[]
required
Array of conversation messages. Each message has a
role and content.boolean
default:"true"
When
true, the response is delivered as a stream of Server-Sent Events. When false, a single JSON object is returned after the model finishes generating.object[]
Tool definitions in OpenAI function-calling format. When provided, the model may respond with a
tool_calls array instead of a text reply.number
default:"Model default"
Sampling temperature between
0.0 and 2.0. Lower values produce more deterministic output; higher values produce more varied output.Message roles
Streaming response
Whenstream: true (the default), the response is a series of Server-Sent Events. Each line starts with data: and contains a JSON chunk. The stream ends with data: [DONE].
Streaming chunk fields
string
Generation ID, consistent across all chunks in a stream.
string
The model ID that generated the response.
object[]
object
Token counts and cost. Included in the final chunk only.
Non-streaming response
Whenstream: false, the API waits for the model to finish and returns a single JSON object:
Multi-turn conversations
Include previous messages in themessages array to maintain context across turns:
Tool calling
Define tools that the model can call using the OpenAI function-calling format. When the model decides to use a tool, it responds with atool_calls array instead of a text reply.
1. Define tools in the request
2. Receive the tool call
3. Return the tool result
Send the result back as atool role message to continue the conversation:
Reasoning models
Some models support extended thinking, where the model reasons through a problem before generating a reply. Reasoning content streams in thedelta.reasoning field:
Reasoning tokens are counted separately from output tokens. Not all models support reasoning — check model capabilities before using this feature.
Image input
Models that support images accept base64-encoded content in themessages array:
Complete example
Authentication
Set up your API key.
Errors
Handle errors and implement retry logic.