Chat Completions
POST /v1/chat/completionsUse the model name shown on the Pricing page.
Authentication
Section titled “Authentication”Authorization: Bearer OMROUTER_API_KEYContent-Type: application/jsonRequest body
Section titled “Request body”| 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.
Example
Section titled “Example”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?\"} ] }"Response
Section titled “Response”{ "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.
Streaming
Section titled “Streaming”Set stream: true to receive incremental events. See Streaming responses for completion and retry rules.
Errors
Section titled “Errors”If the request fails, check the API key, model name, and request fields. See Errors and retries.