Skip to content

Chat Completions

Chat Completions is the most commonly used conversation API. It is suitable for chat, coding assistants, summarization, classification, tool calling, and multi-turn conversations.

It follows the OpenAI Chat Completions protocol, so an existing OpenAI integration only needs its Base URL and API key changed. The same endpoint also reaches Claude, Gemini, and other models; RouteAPI converts the request and response formats internally.

POST /v1/chat/completions

Full URL:

https://api.routeapi.ai/v1/chat/completions

If a client is configured with a Base URL that omits /v1 (for example https://api.routeapi.ai), requests to /chat/completions are accepted as well; RouteAPI rewrites them to /v1/chat/completions.

Terminal window
curl https://api.routeapi.ai/v1/chat/completions \
-H "Authorization: Bearer $ROUTEAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.5",
"messages": [
{ "role": "user", "content": "Introduce RouteAPI in one sentence" }
]
}'
FieldTypeRequiredDescription
modelstringYesModel ID, must be available to the current account
messagesarrayYesConversation message list
streambooleanNoWhether to use SSE streaming output, default false
temperaturenumberNoSampling temperature
top_pnumberNonucleus sampling parameter
max_tokensnumberNoMaximum output token count
max_completion_tokensnumberNoNewer name for the output limit; RouteAPI’s own limit and metering use it in preference to max_tokens when both are set
stopstring/arrayNoCustom stop sequences
nintegerNoNumber of candidates to generate; whether more than one is honored depends on the model
presence_penaltynumberNoPresence penalty
frequency_penaltynumberNoFrequency penalty
seednumberNoBest-effort sampling seed; reproducibility depends on the upstream model
userstringNoEnd-user identifier, forwarded to upstream services that support it
toolsarrayNoTool definitions
tool_choicestring/objectNoTool choice strategy
response_formatobjectNoJSON mode or JSON Schema
stream_optionsobjectNoExtra streaming output options, such as include_usage

Optional fields are forwarded as sent: a field that is absent is not filled in with a default value. See Explicit zero values.

[
{ "role": "system", "content": "You are a rigorous technical assistant." },
{ "role": "user", "content": "Explain what an API gateway is." }
]

Common roles:

RoleDescription
systemSystem prompt
userUser input
assistantHistorical model response
toolTool call result

content may be a plain string or an array of content blocks for multimodal input; see Multimodal Input. When an assistant message returns tool calls, pass that message back unchanged followed by role: "tool" results; see Tool Calling.

{
"id": "chatcmpl_xxx",
"object": "chat.completion",
"created": 1730000000,
"model": "gpt-5.5",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "RouteAPI is an API gateway for unified access to multiple AI model services."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 18,
"total_tokens": 42
}
}

finish_reason tells you why generation stopped: stop (natural end), length (hit the output limit), tool_calls (the model wants to call a tool), or content_filter (blocked by a content filter).

Set stream: true to receive Server-Sent Events. Each line is a chat.completion.chunk whose choices[0].delta carries the increment, and the stream ends with data: [DONE]:

data: {"id":"chatcmpl_xxx","object":"chat.completion.chunk","created":1730000000,"model":"gpt-5.5","choices":[{"index":0,"delta":{"content":"RouteAPI"},"finish_reason":null}]}
data: {"id":"chatcmpl_xxx","object":"chat.completion.chunk","created":1730000000,"model":"gpt-5.5","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]

By default RouteAPI appends a final chunk with token usage and an empty choices array before data: [DONE]. Send "stream_options": {"include_usage": false} to suppress it (channels that do not support stream_options always send it); usage is still recorded in the console logs. Full event handling and mid-stream errors are covered in Streaming Responses.

The official OpenAI SDKs work unchanged once the API key and Base URL point at RouteAPI.

Terminal window
pip install openai
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["ROUTEAPI_KEY"],
base_url="https://api.routeapi.ai/v1",
)
response = client.chat.completions.create(
model="gpt-5.5",
messages=[{"role": "user", "content": "Introduce RouteAPI in one sentence"}],
)
print(response.choices[0].message.content)
Terminal window
npm install openai
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.ROUTEAPI_KEY,
baseURL: 'https://api.routeapi.ai/v1',
});
const response = await client.chat.completions.create({
model: 'gpt-5.5',
messages: [{ role: 'user', content: 'Introduce RouteAPI in one sentence' }],
});
console.log(response.choices[0].message.content);

Both libraries accept a custom OpenAI-compatible endpoint:

import os
from langchain_openai import ChatOpenAI
llm = ChatOpenAI(
model="gpt-5.5",
openai_api_key=os.environ["ROUTEAPI_KEY"],
openai_api_base="https://api.routeapi.ai/v1",
)
import os
import litellm
response = litellm.completion(
model="gpt-5.5",
messages=[{"role": "user", "content": "Introduce RouteAPI in one sentence"}],
api_key=os.environ["ROUTEAPI_KEY"],
api_base="https://api.routeapi.ai/v1",
)

Any client that supports a custom OpenAI Base URL can connect with the same three settings:

  1. API key — a RouteAPI API Key starting with sk-.
  2. Base URL — https://api.routeapi.ai/v1.
  3. Model — a model ID returned by GET /v1/models; see Models.

For ready-made configurations for Codex, Cursor, Claude Code, OpenCode, and other tools, see Migrating from OpenAI.

The official OpenAI API only serves OpenAI’s own models. The same model field here accepts models from multiple providers — for example gpt-5.5, claude-sonnet-4-5, and gemini-2.5-pro — subject to what is available to your key and group. Which models you can call is answered only by GET /v1/models.

Billing and rate limits are managed by RouteAPI

Section titled “Billing and rate limits are managed by RouteAPI”
  • Billing uses RouteAPI’s price list, which may differ from the provider’s official price.
  • Rate limits follow RouteAPI’s policies rather than the provider’s own limits.
  • Balance and key quotas are managed in the RouteAPI console.

See Billing and quotas and Model pricing for details.

The protocol defines the fields; the model decides which of them actually work. Tool calling, image input, structured output, streaming usage, and reasoning controls depend on the selected model and the upstream service behind it. The models endpoint does not return capability flags, so verify the capabilities you rely on with one real request before depending on them in production.

Optional parameters sent explicitly as 0, 0.0, or false are preserved and forwarded, not discarded as “unset”. This lets a client pin temperature: 0 for deterministic sampling. To leave a parameter unset, omit the field entirely rather than sending null.

When the model service rejects a request, RouteAPI returns the upstream status code and message in the standard error body, with (request id: <id>) appended. Errors produced before routing — invalid key, model not allowed, no available channel — use the codes listed in Common Errors.

  • The same parameter may be supported differently by different model services.
  • If the request includes optional parameters such as tools, response_format, or stream_options, confirm that the selected model supports the corresponding capability first.
  • Optional parameters explicitly passed as 0 or false should be treated as user-provided values.
  • When combining structured output with tool calling, read the constraints in Structured Outputs first.
  • Responses — the newer OpenAI protocol, common in coding agents.
  • Claude Messages — Anthropic’s native format for Claude-specific features.
  • Google Gemini API — Google’s native format.
  • Models — which models your key can call and their endpoint types.