Skip to content
exoticrouter.com ↗

Chat Completions

OpenAI’s Chat Completions format, and the one endpoint every text model answers. Claude, GPT, Gemini, DeepSeek and the rest are called the same way; only model changes.

POST https://api.exoticrouter.com/v1/chat/completions

cURL
curl https://api.exoticrouter.com/v1/chat/completions \
-H "Authorization: Bearer $EXOTIC_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-5-5",
"max_tokens": 400,
"messages": [
{"role": "system", "content": "You answer in one short paragraph."},
{"role": "user", "content": "Why is the sky blue?"}
]
}'
Python
reply = client.chat.completions.create(
model="anthropic/claude-sonnet-5-5",
max_tokens=400,
messages=[
{"role": "system", "content": "You answer in one short paragraph."},
{"role": "user", "content": "Why is the sky blue?"},
],
)
print(reply.choices[0].message.content)
TypeScript
const reply = await client.chat.completions.create({
model: "anthropic/claude-sonnet-5-5",
max_tokens: 400,
messages: [
{ role: "system", content: "You answer in one short paragraph." },
{ role: "user", content: "Why is the sky blue?" },
],
});
console.log(reply.choices[0].message.content);

The Python and TypeScript samples on this page use the OpenAI SDK with its base URL set to https://api.exoticrouter.com/v1. OpenAI SDK shows the setup.

Field Type Description
model string required A model id. Any text model.
messages array required The conversation, at least one message. Each has a role of system, developer, user, assistant or tool, and content as text or as a list of parts.
max_tokens integer The longest answer allowed, in tokens. max_completion_tokens is read the same way and wins when both are sent. A value above the model’s max_output_tokens is lowered to it.
temperature, top_p number Passed to the model.
stop `string string[]`
tools, tool_choice, parallel_tool_calls Function tools, in OpenAI’s shape. See Tools.
response_format object Ask for JSON. See JSON answers.
reasoning_effort string How hard a reasoning model should think. See Reasoning.
stream boolean Send the answer as it is written. See Streaming.
stream_options.include_usage boolean Add a last chunk with the token counts to a stream.

Whether a model acts on tools, response_format or reasoning_effort is up to the model. Its capabilities in the list of models are the guide.

{
"id": "chatcmpl-8Zr0mQvT3nXyLw2KpB5cDfGhJ7sUa",
"object": "chat.completion",
"created": 1796169600,
"model": "anthropic/claude-sonnet-5-5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Sunlight is scattered by the air, and blue light is scattered the most."
},
"logprobs": null,
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 27,
"completion_tokens": 16,
"total_tokens": 43
}
}
  • model is the model’s full id, whichever spelling was sent. id and created are the gateway’s own.
  • finish_reason is stop, length, tool_calls or content_filter.
  • message.content is null when the answer is only tool calls. A model’s reasoning, when it shows any, is in message.reasoning_content.
  • usage.prompt_tokens is the gateway’s own count of the prompt, the same count the request is billed on. Reasoning tokens, when there are any, are in usage.completion_tokens_details.reasoning_tokens.
  • logprobs is always null, and there is no system_fingerprint.

With "stream": true the answer comes as server-sent events: lines of data: followed by a JSON chunk, and data: [DONE] at the end.

data: {"id":"chatcmpl-8Zr0…","object":"chat.completion.chunk","created":1796169600,"model":"anthropic/claude-sonnet-5-5","choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-8Zr0…","object":"chat.completion.chunk","created":1796169600,"model":"anthropic/claude-sonnet-5-5","choices":[{"index":0,"delta":{"content":"Sunlight"},"logprobs":null,"finish_reason":null}]}
data: {"id":"chatcmpl-8Zr0…","object":"chat.completion.chunk","created":1796169600,"model":"anthropic/claude-sonnet-5-5","choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]}
data: [DONE]
  • The first chunk carries the role, the ones after it carry content, reasoning_content or tool_calls, and one last chunk carries the finish_reason.
  • Token counts are sent only when asked for: with "stream_options": {"include_usage": true} one more chunk follows, with empty choices and a usage object.
  • While the model is silent the gateway sends a comment line, : keep-alive, every 15 seconds. SSE clients skip it.
  • If the model fails after the stream has begun, the status is already 200. The stream then ends with one frame that holds an error object, and no [DONE] follows.
Python
stream = client.chat.completions.create(
model="anthropic/claude-sonnet-5-5",
messages=[{"role": "user", "content": "Write a haiku about glass."}],
stream=True,
stream_options={"include_usage": True},
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
if chunk.usage:
print("\n", chunk.usage.total_tokens, "tokens")
TypeScript
const stream = await client.chat.completions.create({
model: "anthropic/claude-sonnet-5-5",
messages: [{ role: "user", content: "Write a haiku about glass." }],
stream: true,
stream_options: { include_usage: true },
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
if (chunk.usage) console.log("\n", chunk.usage.total_tokens, "tokens");
}

Describe your functions in tools. When the model wants one called, the answer has finish_reason: "tool_calls" and the calls in message.tool_calls; run them and send each result back as a tool message with the call’s id.

Python
tools = [{
"type": "function",
"function": {
"name": "get_weather",
"description": "The weather in a city, right now.",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
},
}]
messages = [{"role": "user", "content": "Do I need an umbrella in Paris?"}]
first = client.chat.completions.create(model="anthropic/claude-sonnet-5-5", messages=messages, tools=tools)
call = first.choices[0].message.tool_calls[0]
messages += [
first.choices[0].message,
{"role": "tool", "tool_call_id": call.id, "content": '{"rain": true, "temp_c": 11}'},
]
final = client.chat.completions.create(model="anthropic/claude-sonnet-5-5", messages=messages, tools=tools)
print(final.choices[0].message.content)
TypeScript
const tools = [{
type: "function" as const,
function: {
name: "get_weather",
description: "The weather in a city, right now.",
parameters: {
type: "object",
properties: { city: { type: "string" } },
required: ["city"],
},
},
}];
const messages: OpenAI.ChatCompletionMessageParam[] = [
{ role: "user", content: "Do I need an umbrella in Paris?" },
];
const first = await client.chat.completions.create({ model: "anthropic/claude-sonnet-5-5", messages, tools });
const call = first.choices[0].message.tool_calls![0];
messages.push(first.choices[0].message, {
role: "tool",
tool_call_id: call.id,
content: '{"rain": true, "temp_c": 11}',
});
const final = await client.chat.completions.create({ model: "anthropic/claude-sonnet-5-5", messages, tools });
console.log(final.choices[0].message.content);

A call’s id starts with call_ and is the gateway’s own. In a stream, a call’s first chunk has its id and function name, and the chunks after it add to function.arguments. Use a model whose capabilities.tools is true.

Give content as a list of parts to mix text and pictures. An image is an image_url part holding a link or a data: URL. The model has to read images: its capabilities.vision says so.

{
"model": "openai/gpt-6.2-astra",
"messages": [
{
"role": "user",
"content": [
{ "type": "text", "text": "What is in this picture?" },
{ "type": "image_url", "image_url": { "url": "https://example.com/cat.jpg" } }
]
}
]
}

response_format is passed to the model. {"type": "json_object"} asks for any valid JSON; {"type": "json_schema", "json_schema": {…}} asks for JSON that fits a schema. Not every model honours it, so check what comes back before relying on it.

For a model that thinks before it answers, reasoning_effort (low, medium, high) is passed to the model. When the model shows its reasoning, the text is in reasoning_content, in the message and in a stream’s deltas, whatever the model itself calls the field. Reasoning tokens are billed as output tokens.

A request that is not well formed answers 400 with the code invalid_request and a message that names the field. The common ones:

Message Cause
model is required. No model, or an empty one
messages must be a non-empty array. No messages
n other than 1 is not supported. n is 2 or more
max_tokens must be a positive integer. Zero, negative or not a number

Errors has every status, including what a model that is out of reach or a balance that has run out looks like.

  • Messages: Anthropic’s own format, for the Claude models.
  • Responses: OpenAI’s Responses format, for the OpenAI models.