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
  • URL: https://openrouter.ai/api/v1/chat/completions
  • 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

frequency_penaltynumber double nullable

Frequency penalty (-2.0 to 2.0)

image_configImageConfig

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_biasobject nullable

Token logit bias adjustments

logprobsboolean nullable

Return log probabilities

max_completion_tokensinteger nullable

Maximum tokens in completion

max_tokensinteger nullable

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

metadataobject

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

min_pnumber 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.

modalitiesstring[]

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

modelstring

Model to use for completion

modelsstring[]

Models to use for completion

parallel_tool_callsboolean nullable

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

presence_penaltynumber double nullable

Presence penalty (-2.0 to 2.0)

prompt_cache_keystring nullable
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_penaltynumber 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.

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").

seedinteger 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_idstring

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.

streamboolean

Enable streaming response

temperaturenumber double nullable

Sampling temperature (0-2)

top_anumber 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_kinteger 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_logprobsinteger nullable

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

top_pnumber double nullable

Nucleus sampling parameter (0-1)

userstring

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

createdinteger required

Unix timestamp of creation

idstring required

Unique completion identifier

modelstring required

Model used for completion

object'chat.completion' required
service_tierstring nullable

The service tier used by the upstream provider for this request

system_fingerprintstring nullable required

System fingerprint

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 armor discriminator mapping keys to the / request property

    • info

      added to the / request property oneOf list

    • info

      added the optional property / to the response with the status (media type: text/event-stream)

    • info

      added the optional property to the response with the status (media type: application/json)

    • breaking

      added the new required request property ////////

    • breaking

      added the new required request property ////////

    • breaking

      the /////// request property type changed from string to object

    • info

      the /////// request property's minLength was decreased from 1 to 0

    • info

      removed the pattern ^[^\n\r]*$ from the request property ///////

    • info

      added the optional property to the response with the status (media type: application/json)

    • info

      added the optional property / to the response with the status (media type: text/event-stream)