Skip to content

OpenAI Chat Completions

/v1/chat/completions is the simplest and broadest LLM text-generation protocol on OmniRouters.

It is the best default when you want:

  • a familiar OpenAI-style messages payload
  • broad SDK compatibility
  • one request format that can be reused across different model families

Official Documentation

  • OmniRouters route: POST https://omnirouters.com/v1/chat/completions
  • OpenAI official docs: Chat API reference

OmniRouters Notes

  • All models enabled in your OmniRouters account can be called through the OpenAI-compatible protocol.
  • That includes Claude-style and Gemini-style models, as long as the model name is available in your account.
  • Authentication stays the same as other OmniRouters APIs:
text
Authorization: Bearer <your-api-key>

Minimal Example

bash
curl https://omnirouters.com/v1/chat/completions \
  -H "Authorization: Bearer $OMNIROUTERS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "your-enabled-model",
    "messages": [
      {
        "role": "system",
        "content": "You are a helpful assistant."
      },
      {
        "role": "user",
        "content": "Write a short product introduction for OmniRouters."
      }
    ],
    "stream": false
  }'

Common Fields

FieldRequiredPurpose
modelYesThe OmniRouters model name you want to call
messagesYesConversation history, usually system, user, and assistant roles
streamNoReturn streaming chunks when set to true
temperatureNoControl randomness when supported by the model
top_pNoAlternative sampling control
extra_bodyNoProvider-specific extension object when required by a capability

Request Body Parameters

The table below combines fields explicitly declared in the current OmniRouters OpenAPI schema with common OpenAI Chat Completions-compatible fields that may be accepted when the selected model supports them. Sampling, tool use, and multimodal support can differ by model.

FieldTypeRequiredDescription
modelstringYesModel name enabled in your OmniRouters account, such as gpt-4o, claude-..., gemini-..., or a model alias from the OmniRouters catalogue.
messagesarrayYesConversation messages in chronological order. Usually contains system, user, and assistant messages. See the message object structure below.
streambooleanNoWhether to return Server-Sent Events instead of a complete JSON object. Defaults to false.
temperaturenumberNoSampling temperature, commonly from 0 to 2. Higher values make output more varied; lower values make it more deterministic. Some reasoning models may ignore or restrict it.
top_pnumberNoNucleus sampling parameter, commonly from 0 to 1. Usually tune either temperature or top_p, not both heavily.
nintegerNoNumber of candidate completions to generate. Keep this at 1 unless you really need multiple candidates, because each candidate consumes tokens.
stopstring or string[]NoStop sequences. Generation stops when the model emits one of these strings. Commonly up to 4 sequences.
max_tokensintegerNoMaximum number of tokens to generate. Some newer models may also support compatibility fields such as max_completion_tokens.
presence_penaltynumberNoPresence penalty, commonly from -2 to 2. Positive values encourage new topics.
frequency_penaltynumberNoFrequency penalty, commonly from -2 to 2. Positive values reduce repeated phrasing.
logit_biasobjectNoAdjusts likelihood for specific token ids. Keys are usually token ids and values are bias scores.
userstringNoEnd-user identifier for debugging, abuse monitoring, or cost attribution. Prefer an anonymized id.
response_formatobjectNoOutput format control. Common values include { "type": "text" } and { "type": "json_object" }; models with structured output support may also accept JSON Schema formats.
seedintegerNoAttempts to make sampling more reproducible. Exact determinism is not guaranteed.
toolsarrayNoTool definitions. The most common shape is a function tool: { "type": "function", "function": { "name": "...", "parameters": {...} } }.
tool_choicestring or objectNoControls whether tools are used. Common values are none, auto, and required, or an object selecting a specific function.
parallel_tool_callsbooleanNoWhether the model may issue multiple tool calls in parallel. Useful to control complex tool workflows.
logprobsbooleanNoWhether to return token log probabilities, when supported by the model.
top_logprobsintegerNoUsed with logprobs; returns the top candidate tokens per output position, commonly from 0 to 20.
extra_bodyobjectNoOmniRouters extension object for provider-specific parameters. The current OpenAPI schema explicitly declares google.image_config.

messages Object Structure

FieldTypeRequiredRolesDescription
rolestringYesAllMessage role. The current OmniRouters OpenAPI schema explicitly declares system, user, and assistant; OpenAI-native clients may also use developer, tool, and function. For cross-model use, system, user, and assistant are the safest choices.
contentstring or Part[]Yessystem, user, assistantMessage body. Pass a string for plain text, or a Part array for multimodal or structured content. The current OmniRouters Chat schema declares this as string, so validate Part arrays with the target model before relying on them.
namestringNosystem, user, assistantOptional participant name, useful when multiple participants share the same role.
tool_callsarrayNoassistantTool calls generated by the model. When continuing a tool workflow, include the assistant message with its tool_calls.
tool_call_idstringConditionallytoolThe id of the tool call this tool result answers. Required for tool-result messages.
function_callobjectNoassistantLegacy function-calling field, replaced by tool_calls. Kept for older client compatibility.

Function tool calls commonly contain:

FieldTypeDescription
idstringTool call id. A later tool message refers to it with tool_call_id.
typestringTool type, usually function.
function.namestringFunction name to call.
function.argumentsstringJSON string generated by the model. Validate it before executing the function.

Part Object Structure

When messages[].content is an array, each item is a Part:

Part typeShapeDescription
Text{ "type": "text", "text": "..." }Structured text part.
Image URL or base64 data URL{ "type": "image_url", "image_url": { "url": "...", "detail": "auto" } }url may be a public image URL or a data:image/png;base64,... URL. detail commonly accepts auto, low, or high.
Audio input{ "type": "input_audio", "input_audio": { "data": "...", "format": "mp3" } }Base64 audio input. format commonly accepts mp3 or wav. Only supported by multimodal audio models.
File input{ "type": "file", "file": { "file_id": "...", "file_data": "...", "filename": "..." } }File input by uploaded file id or base64 file content. Support depends on model and platform capability.
Refusal{ "type": "refusal", "refusal": "..." }Usually appears in assistant history or response content to represent a refusal. Rarely authored by user requests.

ExtraContent Object Structure

extra_body carries model- or provider-specific options outside the standard protocol fields. The current OpenAPI schema explicitly declares this structure:

FieldTypeRequiredDescription
extra_body.googleobjectNoGoogle / Gemini-specific configuration container.
extra_body.google.image_configobjectNoImage generation configuration. Meaningful only when the selected model supports image output or image generation.
extra_body.google.image_config.aspect_ratiostringNoImage aspect ratio. Allowed values: 1:1, 3:4, 4:3, 9:16, 16:9. Defaults to 16:9.
extra_body.google.image_config.image_sizestringNoImage size or quality tier. Allowed values: 1K, 2K, 4K. Defaults to 1K.

Example:

json
{
  "extra_body": {
    "google": {
      "image_config": {
        "aspect_ratio": "16:9",
        "image_size": "1K"
      }
    }
  }
}

Response Body Parameters

Non-streaming requests usually return a Chat Completion object:

FieldTypeDescription
idstringCompletion id.
objectstringObject type, usually chat.completion.
createdintegerUnix timestamp in seconds.
modelstringModel actually used for generation.
choicesarrayCandidate responses. More than one may be returned when n is greater than 1.
choices[].indexintegerCandidate index.
choices[].messageobjectAssistant message generated by the model.
choices[].message.rolestringUsually assistant.
choices[].message.contentstring or nullGenerated text. May be null for tool-call or refusal flows.
choices[].message.refusalstring or nullRefusal text, usually null when there is no refusal.
choices[].message.tool_callsarray or nullTool calls requested by the model. Execute them in your application, then send results back as tool messages.
choices[].message.annotationsarrayAdditional annotations such as citations or retrieved sources. Returned only when supported.
choices[].finish_reasonstringStop reason. Common values: stop, length, content_filter, tool_calls, function_call.
choices[].logprobsobject or nullToken log probability information when requested and supported.
usageobjectToken usage.
usage.prompt_tokensintegerInput token count.
usage.completion_tokensintegerOutput token count.
usage.total_tokensintegerTotal input plus output tokens.
usage.prompt_tokens_detailsobjectInput-token breakdown, such as cached_tokens or audio_tokens.
usage.completion_tokens_detailsobjectOutput-token breakdown, such as reasoning_tokens, audio_tokens, accepted_prediction_tokens, or rejected_prediction_tokens.
service_tierstringProcessing tier, when returned by the platform or model.
system_fingerprintstringBackend fingerprint for reproducibility debugging. May be absent.

When stream: true, the API returns SSE chunks. Each chunk commonly contains:

FieldTypeDescription
objectstringUsually chat.completion.chunk.
idstringCompletion id, usually the same across all chunks in the stream.
createdintegerChunk creation timestamp.
modelstringModel name.
choices[].deltaobjectIncremental content. May include role, content, tool_calls, or refusal.
choices[].finish_reasonstring or nullUsually null until the final chunk that carries the stop reason.
usageobjectUsage may appear near the end when stream usage reporting is enabled.

When to Use This Route

Use this route if:

  • you want the safest cross-model default
  • you already have OpenAI chat client code
  • you want a clean messages-based request shape
  • you do not need provider-native payload formats

When Another Route May Be Better