Responses

Create a response

Changed on

Creates a streaming or non-streaming response using OpenResponses API format

post/responses

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

ResponsesRequest required

Request schema for Responses endpoint

access_programs, object

OpenAI access programs for this request. cyber selects the Cyber access program: standard, daybreak_blue, or daybreak_red. A program other than standard is supported only on BYOK requests that run on your own OpenAI key enrolled in that program; any other endpoint, including OpenRouter's own OpenAI credentials, rejects it with a 400 error. Requests on OpenRouter's OpenAI credentials always run standard. Omit the field unless your key is enrolled in a Daybreak program.

background, boolean nullable
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.

context_management, ResponsesContextManagement[] nullable

Server-side context management (compaction). Supported for OpenAI models served by OpenAI or Azure, which return compaction output items. Providers translated to another API format drop it. Replay returned compaction items in input on later turns.

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

include, ResponseIncludesEnum[] nullable
input, union

Input for a response request - can be a string or array of items

instructions, string nullable
max_output_tokens, integer nullable
max_tool_calls, integer nullable

Maximum number of server-tool (e.g. openrouter:web_search) agent steps the model may take during a request. Defaults to 30, which is also the maximum. Ignored when stop_server_tools_when is set.

metadata, RequestMetadata nullable

Metadata key-value pairs for the request. Keys must be ≤64 characters and cannot contain brackets. Values must be ≤512 characters. Maximum 16 pairs allowed.

modalities, OutputModalityEnum[]

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

model, string
models, string[]
parallel_tool_calls, boolean nullable
plugins, union[]

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

presence_penalty, number double nullable
previous_response_id, unknown
prompt, StoredPromptTemplate nullable
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, ReasoningConfig nullable

Configuration for reasoning mode in the response

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

safety_identifier, string nullable

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

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.

store, false
stream, boolean
temperature, number double nullable
text, TextExtendedConfig

Text output configuration including format and verbosity

tool_choice, union
tools, union[]
top_k, integer
top_logprobs, integer nullable
top_p, number double nullable
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.

truncation, 'auto' | 'disabled' | 'null' nullable
user, string

A unique identifier representing your end-user, which helps distinguish between different users of your app. This allows your app to identify specific users in case of abuse reports, preventing your entire app from being affected by the actions of individual users. Maximum of 256 characters.

Example request

{
  "input": [
    {
      "content": "Hello, how are you?",
      "role": "user",
      "type": "message"
    }
  ],
  "model": "anthropic/claude-4.5-sonnet-20250929",
  "temperature": 0.7,
  "tools": [
    {
      "description": "Get the current weather in a given location",
      "name": "get_current_weather",
      "parameters": {
        "properties": {
          "location": {
            "type": "string"
          }
        },
        "type": "object"
      },
      "type": "function"
    }
  ],
  "top_p": 0.9
}

Response

Successful response

OpenResponsesResult required

Complete non-streaming response from the Responses API

object
access_programs, object nullable

Access program the upstream provider reported for this response (OpenAI access_programs). null when the provider reported none, including OpenAI's implicit Standard program.

alignment, Alignment

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

error, OpenResponsesErrorField nullable

Error of a failed response; metadata carries OpenRouter-specific details.

error_type, 'context_length_exceeded' | 'max_tokens_exceeded' | 'token_limit_exceeded' | 'string_too_long' | 'authentication' | 'permission_denied' | 'payment_required' | 'rate_limit_exceeded' | 'provider_overloaded' | 'provider_unavailable' | 'invalid_request' | 'invalid_prompt' | 'not_found' | 'precondition_failed' | 'payload_too_large' | 'unprocessable' | 'content_policy_violation' | 'refusal' | 'invalid_image' | 'image_too_large' | 'image_too_small' | 'unsupported_image_format' | 'image_not_found' | 'image_download_failed' | 'server' | 'timeout' | 'unmapped'

Canonical OpenRouter error type, stable across all API formats

input_transformations, ResponsesInputTransformation[]

Input items the upstream provider changed before inference (OpenAI input_transformations). Present only when the provider reported the field; empty when it changed nothing.

openrouter_metadata, OpenRouterMetadata
output, OutputItems[]
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
text, TextExtendedConfig

Text output configuration including format and verbosity

usage, Usage nullable

Token usage information for the response

Example response

{
  "completed_at": 1704067210,
  "created_at": 1704067200,
  "error": null,
  "frequency_penalty": null,
  "id": "resp-abc123",
  "incomplete_details": null,
  "instructions": null,
  "max_output_tokens": null,
  "metadata": null,
  "model": "gpt-4",
  "object": "response",
  "output": [
    {
      "content": [
        {
          "annotations": [],
          "text": "Hello! How can I help you today?",
          "type": "output_text"
        }
      ],
      "id": "msg-abc123",
      "role": "assistant",
      "status": "completed",
      "type": "message"
    }
  ],
  "parallel_tool_calls": true,
  "presence_penalty": null,
  "status": "completed",
  "temperature": null,
  "tool_choice": "auto",
  "tools": [],
  "top_p": null,
  "usage": {
    "input_tokens": 10,
    "input_tokens_details": {
      "cached_tokens": 0
    },
    "output_tokens": 25,
    "output_tokens_details": {
      "reasoning_tokens": 0
    },
    "total_tokens": 35
  }
}

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