Skip to content

API

Chat Completions

POST /v1/chat/completions takes OpenAI's request body and returns OpenAI's response shape.

POST /v1/chat/completions takes the same body as OpenAI's Chat Completions API and returns the same shape.

Every text model on sale answers on this route.

POST/v1/chat/completions

Authorization

Fields
ParameterDetails
Authorization
stringheaderrequired

Your API key as Bearer <key>.

See Authentication.

Request body

Fields
ParameterDetails
model
stringrequired

A slug from the model list, for example qwen/qwen3.8-flash.

messages
object[]required

The conversation so far, as OpenAI { role, content } objects.

Show child attributes

rolestringrequired

system, user, assistant or tool.

contentstringrequired

The message text.

tool_callsobject[]

On an assistant message: the calls the model made, as its reply returned them in message.tool_calls.

tool_call_idstring

On a tool message: the id of the call it answers.

max_tokens
integer

Upper bound on output tokens, reasoning included.

If it runs out while the model is still reasoning, the reply has content: null and finish_reason: "length": see Reasoning models.

temperature
number

Sampling temperature.

tools
object[]

Functions the model may call, in OpenAI's function tool format.

See Tool calls.

Only function tools are accepted.

A custom tool is refused here with 400 invalid_request; the Responses API (/v1/responses, which Codex CLI uses) takes custom tools.

Server-side tools that cost extra, such as web search (a web_search tool or web_search_options), are refused with 400 invalid_request.

Show child attributes

typestringrequired

function.

functionobjectrequired

The function's name, its description, and its arguments as a JSON Schema in parameters.

tool_choice
string or object

auto lets the model decide.

Forcing a call with required or a named function depends on the model: qwen/qwen3.8-flash refuses both with 400 while it reasons.

response_format
object

Ask for JSON output, as in OpenAI's API: {"type": "json_object"} makes the reply's content a JSON string you can parse.

stream
boolean

Send the reply as server-sent events.

See Streaming.

stream_options
object

With {"include_usage": true}, the stream's last chunk before [DONE] carries usage.

See Usage in the stream.

Response

The same shape as OpenAI's.

The response can carry other fields that OpenAI's doesn't; ignore any you don't use.

Fields
ParameterDetails
object
string

chat.completion.

model
string

The model that answered.

choices
object[]

The reply.

Show child attributes

finish_reasonstring

stop, length when max_tokens ran out, or tool_calls when the model wants a tool.

messageobject

The reply as { role, content }.

Reasoning models also return the model's thinking in message.reasoning, and a tool call arrives in message.tool_calls.

usage
object

Tokens counted for the bill: prompt_tokens, completion_tokens (reasoning included) and total_tokens, with prompt_tokens_details.cached_tokens and completion_tokens_details.reasoning_tokens.

Audio input

Some models take speech: azrouter models --json lists audio in a model's input, for example google/gemini-3.8-flash and google/gemini-4-argon.

Send the file in the user message as an input_audio part: data is the file in base64, format is wav. Ask for the transcript, a summary or anything else in a text part beside it.

An audio request holds some credit before the answer starts, then charges only what was used. Set max_tokens to the longest answer you need: it keeps the hold small.

The audio is billed as input tokens, at the model's price per million tokens.

Tool calls

Describe your functions in tools.

When the model wants one, the reply has finish_reason: "tool_calls" and the call in message.tool_calls.

Run the function yourself, then send its result back as a {"role": "tool", "tool_call_id": ..., "content": ...} message in the next request.