https://your-instance.com/v1/chat/completionsSend a conversation as a list of messages and get the next one back. This is the endpoint to reach for unless you specifically need a provider's native format — every text model is available here, including Claude and Gemini models, translated to and from the OpenAI shape for you.
Request body
modelstringrequiredModel to use. Call GET /v1/models for the names this instance serves.
messagesobject[]requiredThe conversation so far. Each entry has a role of system, user, assistant or tool, and content.
streambooleandefault: falseStream the reply as server-sent events instead of waiting for the whole completion.
toolsobject[]Function definitions the model may call. See the tool calling section.
tool_choicestring | objectdefault: "auto"Force or forbid tool use: "none", "auto", "required", or a specific function.
response_formatobjectSet to {"type": "json_object"} to constrain output to valid JSON.
temperaturenumberdefault: 1Sampling temperature between 0 and 2. Lower is more deterministic.
top_pnumberdefault: 1Nucleus sampling. Consider setting this or temperature, not both.
max_tokensintegerUpper bound on generated tokens. The request fails if the prompt plus this exceeds the model's context window.
stopstring | string[]Up to four sequences that end generation when produced.
Example
curl https://your-instance.com/v1/chat/completions \
-H "Authorization: Bearer $CLAWROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5",
"messages": [
{"role": "system", "content": "You are concise."},
{"role": "user", "content": "Why is the sky blue?"}
]
}'Response
{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 1750000000,
"model": "claude-sonnet-5",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "Rayleigh scattering..." },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 61,
"total_tokens": 85
}
}Images in a prompt
Multimodal models accept image parts inside a user message. Pass a URL the provider can fetch, or inline the bytes as a data URI.
{
"model": "claude-sonnet-5",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "What is in this image?" },
{
"type": "image_url",
"image_url": { "url": "data:image/jpeg;base64,/9j/4AAQ..." }
}
]
}
]
}Tool calling
Describe the functions the model may call. When it chooses one, the reply carries tool_calls instead of content, and you run the function and send the result back as a tool message.
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather for a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
response = client.chat.completions.create(
model="claude-sonnet-5",
messages=[{"role": "user", "content": "Weather in Taipei?"}],
tools=tools,
)
call = response.choices[0].message.tool_calls[0]
print(call.function.name, call.function.arguments)