Skip to navigation

Chat Completions

View as Markdown

Use POST /chat/completions to send OpenAI-compatible chat requests through OpenModels.

Base URL:

https://api.getopenmodels.com/v1

Endpoint:

POST /chat/completions

Request

{
"model": "qwen3.5-flash",
"route": { "provider": "<provider-for-this-model>" },
"route_mode": "balanced",
"messages": [
{
"role": "system",
"content": "You are a concise assistant."
},
{
"role": "user",
"content": "Explain OpenModels in one sentence."
}
],
"max_tokens": 256,
"temperature": 0.7
}

Required fields:

FieldDescription
modelA supported model ID from the Models page, or a Model Route ID such as route:coding-agent
messagesConversation messages in OpenAI-compatible chat format

Common optional fields:

FieldDescription
max_tokensMaximum number of output tokens to generate
temperatureSampling temperature. Lower values are more deterministic
top_pNucleus sampling parameter
streamSet to true for server-sent event streaming
toolsFunction calling tools for models that support tool calling
tool_choiceControls whether the model can call tools
routeOptional OpenModels provider route override, such as { "provider": "Alibaba" }
route_modeOptional mode for Model Routes that use mode mapping: fast, balanced, or deep

Parameter support can vary by model and upstream provider. If a parameter is not supported by the selected model, choose a different model or remove the parameter.

Route selection

The examples on this page include optional route and route_mode fields so you can see where request-time routing controls belong. Remove both fields to use the default available route for the selected model.

To pin a request to a specific provider route, pass route.provider with a provider name you have confirmed in the Models table or OpenModels dashboard:

{
"model": "qwen3.5-flash",
"route": { "provider": "<provider-for-this-model>" },
"route_mode": "balanced",
"messages": [
{
"role": "user",
"content": "Hello!"
}
],
"max_tokens": 256
}

Fixed provider routes are only sent to the selected provider. If the provider route is unavailable for that model, remove route or choose another provider route.

For application-level route groups created in the dashboard, pass the route:* ID as model instead. See Model Routes.

cURL

curl https://api.getopenmodels.com/v1/chat/completions \
-H "Authorization: Bearer $OM_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "qwen3.5-flash",
"route": { "provider": "<provider-for-this-model>" },
"route_mode": "balanced",
"messages": [
{
"role": "system",
"content": "You are a concise assistant."
},
{
"role": "user",
"content": "Explain OpenModels in one sentence."
}
],
"max_tokens": 256,
"temperature": 0.7
}'

Python

import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.getopenmodels.com/v1",
api_key=os.environ["OM_API_KEY"],
)
response = client.chat.completions.create(
model="qwen3.5-flash",
messages=[
{
"role": "system",
"content": "You are a concise assistant.",
},
{
"role": "user",
"content": "Explain OpenModels in one sentence.",
},
],
max_tokens=256,
temperature=0.7,
extra_body={
"route": {"provider": "<provider-for-this-model>"},
"route_mode": "balanced",
},
)
print(response.choices[0].message.content)

Node.js

import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.getopenmodels.com/v1",
apiKey: process.env.OM_API_KEY,
});
const response = await client.chat.completions.create({
model: "qwen3.5-flash",
route: { provider: "<provider-for-this-model>" },
route_mode: "balanced",
messages: [
{
role: "system",
content: "You are a concise assistant.",
},
{
role: "user",
content: "Explain OpenModels in one sentence.",
},
],
max_tokens: 256,
temperature: 0.7,
});
console.log(response.choices[0].message.content);

Response

Responses follow the OpenAI-compatible chat completions shape:

{
"id": "chatcmpl_123",
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "OpenModels provides low-cost access to supported models through one OpenAI-compatible API key."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 18,
"completion_tokens": 20,
"total_tokens": 38
}
}

Use the usage object to understand token consumption for the request. Credit spend is based on actual input and output token usage.