Chat

Create a chat completion

Changed on

Sends a request for a model response for the given chat conversation. Supports both streaming and non-streaming modes.

post/chat/completions

Request

  • Base URL
    https://openrouter.ai/api/v1
  • Auth
    HTTP bearer

Headers

X-OpenRouter-Metadata, 'disabled' | 'enabled'

Opt-in level for surfacing routing metadata on the response under openrouter_metadata.

Example:enabled

Opt-in to surface routing metadata on the response under openrouter_metadata. Defaults to disabled. The legacy header X-OpenRouter-Experimental-Metadata is also accepted for backward compatibility.

Request body

ChatRequest required

Chat completion request parameters

cache_control, AnthropicCacheControlDirective

Enable automatic prompt caching. When set at the top level, the system automatically applies cache breakpoints to the last cacheable block in the request. When set on an individual content block, it marks an explicit cache breakpoint; block-level markers also work on OpenAI models that support explicit prompt caching — OpenRouter converts them to the provider's native format.

debug, ChatDebugOptions

Debug options for inspecting request transformations (streaming only)

deferred_tools, DeferredToolsControl

Opt-in versioned router-level deferred-tool protocol. Replay assistant reasoning unchanged on continuation. The portable profile needs the catalog unchanged across a continuation; the universal profile accepts a changed catalog and, with announce_catalog_changes, tells the model about it.

frequency_penalty, number double nullable

Frequency penalty (-2.0 to 2.0)

image_config, ImageConfig

Provider-specific image configuration options. Keys and values vary by model/provider. See https://openrouter.ai/docs/guides/overview/multimodal/image-generation for more details.

logit_bias, object nullable

Token logit bias adjustments

logprobs, boolean nullable

Return log probabilities

max_completion_tokens, integer nullable

Maximum tokens in completion

max_tokens, integer nullable

Maximum tokens (deprecated, use max_completion_tokens). Note: some providers enforce a minimum of 16.

messages, ChatMessages[] required

List of messages for the conversation

metadata, object

Key-value pairs for additional object information (max 16 pairs, 64 char keys, 512 char values)

min_p, number double nullable

Minimum probability threshold relative to the most likely token. Tokens with probability below min_p * (probability of top token) are filtered out. Not all providers support this parameter.

modalities, string[]

Output modalities for the response. Supported values are "text", "image", and "audio".

model, string

Model to use for completion

models, intersection[]

Models to use for completion

parallel_tool_calls, boolean nullable

Whether to enable parallel function calling during tool use. When true, the model may generate multiple tool calls in a single response.

plugins, union[]

Plugins you want to enable for this request, including their settings.

prediction, Prediction nullable

Static predicted output content. Supported models can use this to reduce latency when much of the response is known in advance.

presence_penalty, number double nullable

Presence penalty (-2.0 to 2.0)

prompt_cache_key, string nullable
prompt_cache_options, PromptCacheOptions nullable

Request-level prompt-cache controls. mode: "explicit" disables OpenAI-managed breakpoints so only blocks marked with prompt_cache_breakpoint are cached. ttl sets the minimum cache lifetime for every breakpoint the request writes: "30m" (default) or "12h" (billed at the higher 12h cache-write rate). Only supported by OpenAI GPT-5.6 and newer.

provider, ProviderPreferences nullable

When multiple model providers are available, optionally indicate your routing preference.

reasoning, object

Configuration options for reasoning models

reasoning_effort, 'max' | 'xhigh' | 'high' | 'medium' | 'low' | 'minimal' | 'none' | 'null' nullable

Shorthand for setting reasoning effort. Equivalent to setting reasoning.effort. Cannot be used simultaneously with reasoning.effort if they differ.

repetition_penalty, number double nullable

Penalizes tokens based on how much they have already appeared in the text. A value of 1.0 means no penalty. Values above 1.0 penalize repeated tokens more strongly. Not all providers support this parameter.

response_format, union

Response format configuration

route, 'fallback' | 'sort' | 'null' nullable

DEPRECATED Use providers.sort.partition instead. Backwards-compatible alias for providers.sort.partition. Accepts legacy values: "fallback" (maps to "model"), "sort" (maps to "none").

seed, integer nullable

Random seed for deterministic outputs

service_tier, 'auto' | 'default' | 'fast' | 'flex' | 'priority' | 'scale' | 'ultrafast' | 'null' nullable

The service tier to use for processing this request. fast is accepted as an alias for priority. ultrafast prefers ultrafast endpoints and falls back to priority, then default endpoints.

session_id, string

A unique identifier for grouping related requests (e.g., a conversation or agent workflow). When provided, OpenRouter uses it as the sticky routing key, routing all requests in the session to the same provider to maximize prompt cache hits. Also used for observability grouping. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 256 characters.

stop, union

Stop sequences (up to 4)

stop_server_tools_when, StopServerToolsWhenCondition[]

Stop conditions for the server-tool agent loop. Any condition firing halts the loop (OR logic). When set, this overrides max_tool_calls. When a condition fires while the model is still emitting tool calls, the pending tool calls are executed and one final turn is made with tool calls disabled so the response ends with a natural-language answer instead of an unfinished tool call.

stream, boolean

Enable streaming response

stream_options, ChatStreamOptions nullable

Streaming configuration options

temperature, number double nullable

Sampling temperature (0-2)

tool_choice, union

Tool choice configuration

tools, ChatFunctionTool[]

Available tools for function calling

top_a, number double nullable

Consider only tokens with "sufficiently high" probabilities based on the probability of the most likely token. Not all providers support this parameter.

top_k, integer nullable

Limits the model to choose from the top K most likely tokens at each step. A value of 1 means the model will always pick the most likely next token. Not all providers support this parameter.

top_logprobs, integer nullable

Number of top log probabilities to return (0-20)

top_p, number double nullable

Nucleus sampling parameter (0-1)

trace, TraceConfig

Metadata for observability and tracing. Known keys (trace_id, trace_name, span_name, generation_name, parent_span_id) have special handling. Additional keys are passed through as custom metadata to configured broadcast destinations.

user, string

Per-end-user identifier for abuse isolation. Use a stable ID, hash, or pseudonym. When a provider requires a user identity, OpenRouter folds it into the hashed identity sent upstream and never forwards it raw. If omitted, requests use an account-level identity, so provider policy blocks can affect the whole account.

Example request

{
  "max_tokens": 150,
  "messages": [
    {
      "content": "You are a helpful assistant.",
      "role": "system"
    },
    {
      "content": "What is the capital of France?",
      "role": "user"
    }
  ],
  "model": "openai/gpt-4",
  "temperature": 0.7
}

Response

Successful chat completion response

ChatResult required

Chat completion response

alignment, Alignment

Beta. The result of the alignment plugin for this request; the shape may change.

choices, ChatChoice[] required

List of completion choices

created, integer required

Unix timestamp of creation

id, string required

Unique completion identifier

model, string required

Model used for completion

object, 'chat.completion' required
openrouter_metadata, OpenRouterMetadata
safeguard_results, ArmorSafeguardResult[]

OpenRouter Armor's verdict for each client tool call of this response, present whenever Armor evaluated the response (even when nothing was flagged). Independent of the openrouter_metadata opt-in.

service_tier, string nullable

The service tier used by the upstream provider for this request

system_fingerprint, string nullable required

System fingerprint

usage, ChatUsage

Token usage statistics

Example response

{
  "choices": [
    {
      "finish_reason": "stop",
      "index": 0,
      "message": {
        "content": "The capital of France is Paris.",
        "role": "assistant"
      }
    }
  ],
  "created": 1677652288,
  "id": "chatcmpl-123",
  "model": "openai/gpt-4",
  "object": "chat.completion",
  "system_fingerprint": "fp_44709d6fcb",
  "usage": {
    "completion_tokens": 15,
    "prompt_tokens": 10,
    "total_tokens": 25
  }
}

Changes

    • info

      added the new optional request property provider/options/celeris

    • info

      added the new Celeris enum value to the request property provider/ignore/items/anyOf[#/components/schemas/ProviderName]

    • info

      added the new Celeris enum value to the request property provider/only/items/anyOf[#/components/schemas/ProviderName]

    1 more change in this revision