Chat Completions
POST /v1/chat/completions takes the same request as OpenAI’s Chat Completions API, for every chat model in the catalog. Point an OpenAI SDK at https://api.indorouter.ai/v1 and put an indoRouter model ID in model.
curl https://api.indorouter.ai/v1/chat/completions \ -H "Authorization: Bearer $INDOROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "openai/gpt-4o-mini", "max_tokens": 200, "messages": [{"role": "user", "content": "hello"}]}'import osfrom openai import OpenAI
client = OpenAI( base_url="https://api.indorouter.ai/v1", api_key=os.environ["INDOROUTER_API_KEY"],)
reply = client.chat.completions.create( model="openai/gpt-4o-mini", max_tokens=200, messages=[{"role": "user", "content": "hello"}],)print(reply.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.indorouter.ai/v1", apiKey: process.env.INDOROUTER_API_KEY,});
const reply = await client.chat.completions.create({ model: "openai/gpt-4o-mini", max_tokens: 200, messages: [{ role: "user", content: "hello" }],});console.log(reply.choices[0].message.content);Request field handling
Section titled “Request field handling”Most fields are forwarded to the vendor unchanged. Field support depends on the model. The table below describes the fields handled directly by indoRouter.
| Field | What indoRouter does |
|---|---|
model |
Required. The indoRouter model ID, such as openai/gpt-4o-mini. The vendor receives its own name for the model, and the response gives back the ID you sent. |
messages |
Required, with at least one message. A developer message is sent as system to vendors that use the OpenAI format. |
max_tokens, max_completion_tokens |
The output cap. Either field is accepted. If you send both, their values must match. See Output cap. |
stream |
Read by indoRouter. See Streaming. |
stream_options |
Accepted and ignored. A streamed reply always ends with a usage chunk when the vendor reported usage. |
user |
Removed. It never reaches the vendor. |
store |
Always sent to the vendor as false. |
| Anything else | Forwarded as you wrote it: temperature, top_p, stop, n, seed, tools, tool_choice, response_format, reasoning_effort, logprobs and the rest. If the vendor refuses a field, you get its reason in the error message. |
You cannot choose the provider. These fields are refused with 400 refused_request_field, because the route and its price are fixed before the request runs: provider, providers, route, routes, fallbacks, credential, credential_alias, api_key, api_base, base_url, service_tier, inference_geo and speed. Headers starting with x-indorouter- are removed from your request.
Differences between vendors
Section titled “Differences between vendors”Field support varies by vendor:
- Anthropic models ignore
temperatureandtop_p, and also ignoreresponse_format,presence_penalty,frequency_penalty,seed,logprobsandlogit_bias. Thinking is turned on byreasoning_effortwith one oflow,medium,highorxhigh. Without it most Claude models answer without thinking; some newer ones decide for themselves, andreasoningin/v1/modelssays which. The thinking text arrives inreasoning_content. - Google Gemini models support
response_formatwithjson_objectorjson_schema. They ignorereasoning_effort,presence_penalty,frequency_penalty,logprobsandparallel_tool_calls. - Other vendors receive the fields as sent. Reasoning text, where a model returns it, arrives in
reasoning_content.
Output cap
Section titled “Output cap”max_tokens (or max_completion_tokens) caps how many tokens the reply may have.
- If you leave it out, the model’s default cap is used.
- If you ask for more than the model allows, the cap is lowered to the model’s maximum. The request is not refused.
- Every reply carries the cap that was actually used in the
x-indorouter-max-output-tokensheader. - If
max_tokensandmax_completion_tokenshave different values, the request is refused with400 conflicting_output_caps.
Before a request runs, we set aside enough of your balance to pay for its largest possible reply (see How billing works). If your balance does not cover the cap you asked for, but does cover a smaller one, we lower the cap to what your balance covers, down to 4,096 tokens, and send the reply with the header x-indorouter-max-output-tokens-lowered-from, which holds the cap you asked for. Such a reply can end with finish_reason: "length".
If even 4,096 tokens are not covered, you get 402 insufficient_funds. If your application must never get a shorter cap than it asked for, set the key’s low-balance behavior to refuse requests (see API keys). Requests made with that key then get 402 insufficient_funds instead of a lowered cap.
Images, PDFs, audio and video
Section titled “Images, PDFs, audio and video”Send these as content parts in a user message. The model must take that kind of input; the model list says which do.
| Input | Content part | Notes |
|---|---|---|
| Image | {"type": "image_url", "image_url": {"url": "..."}} |
An https:// URL, which the vendor fetches, or a data:image/...;base64,... URL. detail: "low" is passed on. |
{"type": "file", "file": {"filename": "a.pdf", "file_data": "data:application/pdf;base64,..."}} |
Inline only. We read the page count from the PDF. | |
| Audio | {"type": "input_audio", "input_audio": {"data": "<base64>", "format": "mp3"}} |
Inline only. WAV, MP3, FLAC, Ogg and M4A. |
| Video | A file part with a data:video/mp4;base64,... URL |
Inline only, MP4 or WebM. |
Files go inside the request. We do not fetch a file by ID. A file_id, a gs:// URL or another reference to an object in a vendor’s account is refused with 400 vendor_object_reference. A file uploaded to /v1/files is not usable from a chat message either: send its bytes inline. The whole request body may be up to 32 MB.
A model that does not take a kind of input refuses it with 400 unsupported_content_part. A PDF whose page count cannot be read gets 400 unreadable_document, and an audio or video clip whose length cannot be read gets 400 unreadable_media.
Prompt caching
Section titled “Prompt caching”Mark the end of a reusable prompt prefix with Anthropic’s cache_control on a content part or OpenAI’s prompt_cache_breakpoint. We adapt these markers to the format each model supports:
- On Anthropic and Alibaba models that cache on request, a
prompt_cache_breakpointbecomes a 5-minutecache_control. Anthropic takes at most four markers, so we add breakpoints only up to the remaining limit after your existing markers, starting with the last breakpoint. - On OpenAI models from gpt-5.6 on, a
cache_controlon a system, developer, user or tool part becomes aprompt_cache_breakpoint. Itsttlis dropped, because OpenAI sets one TTL for the whole request. - Elsewhere, including OpenAI models before gpt-5.6, which refuse breakpoints, both are dropped. Most of these models still cache repeated prefixes on their own.
A hint never makes a request fail. The x-indorouter-cache response header says what happened to yours: kept, shortened (sent with the default 5-minute TTL because the model has no 1-hour one) or dropped. Request-level prompt_cache_options and a top-level cache_control are always dropped.
tools and tool_choice work as in OpenAI’s API on models that support function calling. A model without function calling refuses tools with 400 tools_not_supported. The hosted image_generation tool is refused on every model with 400 refused_tool_type, and file_search is refused with 400 vendor_object_reference.
Streaming
Section titled “Streaming”With "stream": true the reply is a stream of server-sent events, each a line data: {...} holding a chat.completion.chunk. A finished stream ends with:
- a chunk whose
choices[0].finish_reasonis set, - a chunk with
"choices": []and theusageobject, when the vendor reported usage, data: [DONE].
We send no keep-alive comments. If the vendor sends nothing for two minutes, the stream ends as cut short, with finish_reason: "length". If the vendor fails after the stream has started, the last event is data: {"error": {...}} and no [DONE] follows. Treat a stream without [DONE] as failed.
If the request fails before any output is ready, you get an ordinary JSON error with its HTTP status, not a stream.
Response
Section titled “Response”| Field | Value |
|---|---|
id |
The request ID, req_.... The same value is in the x-request-id header. |
model |
The model ID you sent. |
choices[].finish_reason |
stop, length, content_filter or tool_calls. |
usage |
prompt_tokens, completion_tokens, total_tokens, and when reported, prompt_tokens_details.cached_tokens, prompt_tokens_details.cached_write_tokens and completion_tokens_details.reasoning_tokens. cost is what the request cost in rupiah, service fee included, the same figure as total_cost in GET /v1/generation. Left out when the vendor reported no usage. |
When the vendor reports usage, usage.cost contains the request cost. You can also look up the cost by passing the request ID to GET /v1/generation.
Sending a request again safely
Section titled “Sending a request again safely”Send an Idempotency-Key header (up to 255 bytes) to make sure a retried request is not run twice. The request ID becomes idem_.... A second request with the same key and the same body is refused with 409 idempotency_key_in_use, because responses are not stored and cannot be replayed. The same key with a different body gets 409 idempotency_key_mismatch.
Every error code is on Errors, and the per-minute limits are on Rate limits.