Docs
Chat Completions
POST /v1/chat/completions — parameters, response shape and streaming.
POST
https://iranrouter.com/v1/chat/completionsThe main surface. OpenAI-compatible, so the request and response shapes are what SDKs already expect.
Parameters
| Name | Type | Notes |
|---|---|---|
model | string | Required. Model ID or alias. |
messages | array | Required. Messages with role system / user / assistant / tool. |
max_tokens | int | Output ceiling. Directly drives the amount held from your wallet — set it realistically. |
max_completion_tokens | int | The newer clients' spelling of max_tokens; both are honoured. |
stream | bool | SSE streaming response. |
temperature | number | Sampling randomness. |
top_p | number | Nucleus sampling. |
tools | array | Tool definitions. Their schemas count as input tokens. |
tool_choice | string|object | Force or free the tool choice. |
response_format | object | Structured / JSON output. |
stop | string|array | Stop sequences. |
seed | int | For reproducibility, where the model supports it. |
Each model accepts its own subset. The exact supported-parameter list is on that model's page; unknown parameters are ignored rather than rejected.
Response
json
{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 1767000000,
"model": "openai/gpt-4o-mini",
"choices": [
{
"index": 0,
"message": { "role": "assistant", "content": "..." },
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 108,
"total_tokens": 132
}
}The non-streaming path returns tool_calls, logprobs, refusal and n>1 in full.
Full example
bash
curl https://iranrouter.com/v1/chat/completions \
-H "Authorization: Bearer ir-..." \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4o-mini",
"messages": [
{"role": "system", "content": "You answer in Persian."},
{"role": "user", "content": "پایتخت ایران کجاست؟"}
],
"max_tokens": 200,
"temperature": 0.4
}'