Skip to content

Chat Completions ​

Compatible with OpenAI Chat Completions. All text models can be called through this API, including Claude, Gemini, DeepSeek and others.

POSThttps://api.codingrouter.ai/v1/chat/completions

Authentication ​

Authorization: Bearer <token>

Request parameters ​

ParameterTypeRequiredDescription
modelstringYesModel name; the token's group must contain this model
messagesarrayYesConversation messages, see below
streambooleanNoWhen true, returns an SSE stream
stream_optionsobjectNo{"include_usage": true}: returns usage in the last chunk
max_tokensintegerNoMaximum number of tokens to generate
max_completion_tokensintegerNoSame as above, the newer OpenAI form, includes reasoning tokens
temperaturenumberNo0 to 2, higher is more random
top_pnumberNoNucleus sampling, 0 to 1
nintegerNoNumber of candidate answers to return
stopstring / arrayNoStop generating when these strings appear
presence_penaltynumberNo-2 to 2
frequency_penaltynumberNo-2 to 2
seedintegerNoFixed random seed, to make results as reproducible as possible
toolsarrayNoList of callable functions
tool_choicestring / objectNoauto, none, required, or a specific function
response_formatobjectNo{"type": "json_object"} or {"type": "json_schema", ...}
reasoning_effortstringNoThinking 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 ​

FieldTypeDescription
rolestringsystem, user, assistant or tool
contentstring / arrayText, or an array of text and images
tool_callsarrayFunction calls made by the assistant (when role is assistant)
tool_call_idstringThe ID of the matching function call (when role is tool)

Request example ​

bash
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"}
    ]
  }'
python
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)
js
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 ​

json
{
  "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 ​

python
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::

json
{
  "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 ​

json
{
  "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:

json
{
  "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 ​

json
{
  "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:

bash
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.