Chat Completions
Compatible with OpenAI Chat Completions. All text models can be called through this API, including Claude, Gemini, DeepSeek and others.
https://api.codingrouter.ai/v1/chat/completionsAuthentication
Authorization: Bearer <token>
Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model name; the token's group must contain this model |
messages | array | Yes | Conversation messages, see below |
stream | boolean | No | When true, returns an SSE stream |
stream_options | object | No | {"include_usage": true}: returns usage in the last chunk |
max_tokens | integer | No | Maximum number of tokens to generate |
max_completion_tokens | integer | No | Same as above, the newer OpenAI form, includes reasoning tokens |
temperature | number | No | 0 to 2, higher is more random |
top_p | number | No | Nucleus sampling, 0 to 1 |
n | integer | No | Number of candidate answers to return |
stop | string / array | No | Stop generating when these strings appear |
presence_penalty | number | No | -2 to 2 |
frequency_penalty | number | No | -2 to 2 |
seed | integer | No | Fixed random seed, to make results as reproducible as possible |
tools | array | No | List of callable functions |
tool_choice | string / object | No | auto, none, required, or a specific function |
response_format | object | No | {"type": "json_object"} or {"type": "json_schema", ...} |
reasoning_effort | string | No | Thinking depth of reasoning models: low, medium, high |
Whether a parameter takes effect depends on the model itself. For example n and seed are supported by only some models. Parameters a model does not support are usually ignored.
messages
| Field | Type | Description |
|---|---|---|
role | string | system, user, assistant or tool |
content | string / array | Text, or an array of text and images |
tool_calls | array | Function calls made by the assistant (when role is assistant) |
tool_call_id | string | The ID of the matching function call (when role is tool) |
Request example
curl https://api.codingrouter.ai/v1/chat/completions \
-H "Authorization: Bearer $CODINGROUTER_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.5",
"messages": [
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Explain what an API gateway is in one sentence"}
]
}'from openai import OpenAI
client = OpenAI(base_url="https://api.codingrouter.ai/v1", api_key="sk-your-token")
resp = client.chat.completions.create(
model="gpt-5.5",
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Explain what an API gateway is in one sentence"},
],
)
print(resp.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.codingrouter.ai/v1",
apiKey: process.env.CODINGROUTER_KEY,
});
const resp = await client.chat.completions.create({
model: "gpt-5.5",
messages: [
{ role: "system", content: "You are a concise assistant." },
{ role: "user", content: "Explain what an API gateway is in one sentence" },
],
});
console.log(resp.choices[0].message.content);Response example
{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 1794806345,
"model": "gpt-5.5",
"choices": [{
"index": 0,
"message": {"role": "assistant", "content": "An API gateway is the entry layer that receives, routes and manages client API requests in one place."},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 28,
"completion_tokens": 23,
"total_tokens": 51,
"prompt_tokens_details": {"cached_tokens": 0}
}
}finish_reason: stop normal end, length length limit reached, tool_calls the model asks to call a function.
Streaming
stream = client.chat.completions.create(
model="gpt-5.5",
messages=[{"role": "user", "content": "Write a short poem about the starry sky"}],
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("\nUsage:", chunk.usage.total_tokens)Each chunk looks like data: {"object":"chat.completion.chunk","choices":[{"delta":{"content":"..."}}]}, and the last line is data: [DONE]. With include_usage on, a chunk with empty choices and a usage field comes before [DONE].
Image input
Vision-capable models accept images in content. Set url to a public address or a base64 string starting with data::
{
"model": "gpt-5.5",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "What color is this image?"},
{"type": "image_url", "image_url": {"url": "data:image/png;base64,iVBORw0KGgo..."}}
]
}]
}Tool calls
{
"model": "gpt-5.5",
"messages": [{"role": "user", "content": "What is the weather in Beijing today?"}],
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the weather of a city",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"]
}
}
}]
}When the model decides to call it, it returns:
{
"message": {
"role": "assistant",
"tool_calls": [{
"id": "call_...",
"type": "function",
"function": {"name": "get_weather", "arguments": "{\"city\":\"Beijing\"}"}
}]
},
"finish_reason": "tool_calls"
}After running the function, append the result to messages as {"role": "tool", "tool_call_id": "call_...", "content": "Sunny, 25°C"} and send the request again.
Structured output
{
"model": "gpt-5.5",
"messages": [{"role": "user", "content": "Which country does Beijing belong to?"}],
"response_format": {
"type": "json_schema",
"json_schema": {
"name": "answer",
"strict": true,
"schema": {
"type": "object",
"properties": {"city": {"type": "string"}, "country": {"type": "string"}},
"required": ["city", "country"],
"additionalProperties": false
}
}
}
}message.content will be a JSON string that matches the schema. When you only need valid JSON with no fixed structure, use {"type": "json_object"} and say in the prompt that the output must be JSON.
Calling other vendors' models
Change model to the model you want and use a token from the matching group:
curl https://api.codingrouter.ai/v1/chat/completions \
-H "Authorization: Bearer $CLAUDE_GROUP_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "claude-sonnet-5-5", "messages": [{"role": "user", "content": "Hello"}]}'Streaming, tool calls and image input work the same for Claude and Gemini models. Vendor-specific parameters (such as Claude's cache_control) do not necessarily take effect in this API. When you need them, use the native Claude Messages or Gemini API.
Reasoning models
Reasoning models such as GLM output their thinking (reasoning_content) first, then the body. If max_tokens is too small, you may get only thinking and an empty body (finish_reason is length). Leave 2000 or more.
