Skip to content

Chat Completions

POST /v1/chat/completions

Use the model name shown on the Pricing page.

Authorization: Bearer OMROUTER_API_KEY
Content-Type: application/json
Field Type Required Description
model string Yes Model name shown on the Pricing page.
messages array Yes Conversation messages in order.
messages[].role string Yes Common values are system, user, assistant, and tool.
messages[].content string or array Yes Text or model-supported content parts.
stream boolean No Return content as it is generated when true.
max_tokens integer No Maximum generated tokens where supported.
max_completion_tokens integer No Newer completion-token limit where supported.
temperature number No Sampling control; support and range depend on the model.
tools array No Tool definitions for models that support tool calling.
response_format object No Output-format constraint where supported.

Optional fields vary by model. Start with the simple request below, then add other fields one at a time.

Terminal window
curl --silent --show-error \
'https://omrouter.com/v1/chat/completions' \
--header "Authorization: Bearer $OMROUTER_API_KEY" \
--header 'Content-Type: application/json' \
--data "{
\"model\": \"$OMROUTER_MODEL_ID\",
\"messages\": [
{\"role\": \"system\", \"content\": \"Be concise.\"},
{\"role\": \"user\", \"content\": \"What is an API gateway?\"}
]
}"
{
"id": "chatcmpl-...",
"object": "chat.completion",
"created": 0,
"model": "model-id",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "..."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
}
}

Some models return additional fields or slightly different token details.

Set stream: true to receive incremental events. See Streaming responses for completion and retry rules.

If the request fails, check the API key, model name, and request fields. See Errors and retries.