Skip to content

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.

Terminal window
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"}]}'

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.

Field support varies by vendor:

  • Anthropic models ignore temperature and top_p, and also ignore response_format, presence_penalty, frequency_penalty, seed, logprobs and logit_bias. Thinking is turned on by reasoning_effort with one of low, medium, high or xhigh. Without it most Claude models answer without thinking; some newer ones decide for themselves, and reasoning in /v1/models says which. The thinking text arrives in reasoning_content.
  • Google Gemini models support response_format with json_object or json_schema. They ignore reasoning_effort, presence_penalty, frequency_penalty, logprobs and parallel_tool_calls.
  • Other vendors receive the fields as sent. Reasoning text, where a model returns it, arrives in reasoning_content.

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-tokens header.
  • If max_tokens and max_completion_tokens have different values, the request is refused with 400 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.

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.
PDF {"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.

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_breakpoint becomes a 5-minute cache_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_control on a system, developer, user or tool part becomes a prompt_cache_breakpoint. Its ttl is 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.

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:

  1. a chunk whose choices[0].finish_reason is set,
  2. a chunk with "choices": [] and the usage object, when the vendor reported usage,
  3. 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.

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.

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.