Create a response
Creates a streaming or non-streaming response using OpenResponses API format
Authorizations
API key as bearer token in Authorization header
Headers
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.
Opt-in level for surfacing routing metadata on the response under openrouter_metadata.
disabled, enabled "enabled"
Body
Request schema for Responses endpoint
Enable automatic prompt caching. When set at the top level, the system automatically applies cache breakpoints to the last cacheable block in the request. Currently supported for Anthropic Claude models.
{ "type": "ephemeral" }Debug options for inspecting request transformations (streaming only)
{ "echo_upstream_body": true }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.
{ "aspect_ratio": "16:9", "quality": "high" }file_search_call.results, message.input_image.image_url, computer_call_output.output.image_url, reasoning.encrypted_content, code_interpreter_call.outputs Input for a response request - can be a string or array of items
[
{
"content": "What is the weather today?",
"role": "user"
}
]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.
{
"session_id": "abc-def-ghi",
"user_id": "123"
}Output modalities for the response. Supported values are "text" and "image".
text, image ["text", "image"]Plugins you want to enable for this request, including their settings.
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- Option 6
- Option 7
- Option 8
- Option 9
{
"allowed_models": ["anthropic/*", "openai/gpt-4o"],
"cost_quality_tradeoff": 7,
"enabled": true,
"id": "auto-router"
}{
"id": "prompt-abc123",
"variables": { "name": "John" }
}When multiple model providers are available, optionally indicate your routing preference.
{ "allow_fallbacks": true }Configuration for reasoning mode in the response
{
"effort": "medium",
"summary": "auto",
"enabled": true
}DEPRECATED Use providers.sort.partition instead. Backwards-compatible alias for providers.sort.partition. Accepts legacy values: "fallback" (maps to "model"), "sort" (maps to "none").
fallback, sort, null "fallback"
auto, default, flex, priority, scale, null 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.
256Stop conditions for the server-tool agent loop. Any condition firing halts the loop (OR logic). When set, this overrides max_tool_calls.
1A single condition that, when met, halts the server-tool agent loop.
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
{ "step_count": 5, "type": "step_count_is" }[
{ "step_count": 5, "type": "step_count_is" },
{
"max_cost_in_dollars": 0.5,
"type": "max_cost"
}
]Text output configuration including format and verbosity
{
"format": { "type": "text" },
"verbosity": "medium"
}auto "auto"
Function tool definition
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- Option 6
- Option 7
- Option 8
- Option 9
- Option 10
- Option 11
- Option 12
- Option 13
- Option 14
- Option 15
- Option 16
- Option 17
- Option 18
- Option 19
- Option 20
- Option 21
- Option 22
- Option 23
- Option 24
- Option 25
- Option 26
{
"description": "Get the current weather in a location",
"name": "get_weather",
"parameters": {
"properties": {
"location": {
"description": "The city and state",
"type": "string"
},
"unit": {
"enum": ["celsius", "fahrenheit"],
"type": "string"
}
},
"required": ["location"],
"type": "object"
},
"type": "function"
}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.
{
"trace_id": "trace-abc123",
"trace_name": "my-app-trace"
}auto, disabled, null "auto"
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.
256Response
Successful response
Complete non-streaming response from the Responses API
Error information returned from the API
{
"code": "rate_limit_exceeded",
"message": "Rate limit exceeded. Please try again later."
}{ "reason": "max_output_tokens" }[
{
"content": "What is the weather today?",
"role": "user"
}
]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.
{
"session_id": "abc-def-ghi",
"user_id": "123"
}response An output item from the response
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- Option 6
- Option 7
- Option 8
- Option 9
- Option 10
- Option 11
- Option 12
- Option 13
- Option 14
- Option 15
- Option 16
- Option 17
- Option 18
- Option 19
- Option 20
- Option 21
- Option 22
- Option 23
- Option 24
- Option 25
- Option 26
- Option 27
- Option 28
- Option 29
- Option 30
- Option 31
- Option 32
- Option 33
- Option 34
- Option 35
- Option 36
- Option 37
- Option 38
- Option 39
- Option 40
- Option 41
- Option 42
- Option 43
- Option 44
- Option 45
- Option 46
- Option 47
- Option 48
- Option 49
- Option 50
- Option 51
- Option 52
- Option 53
- Option 54
- Option 55
- Option 56
- Option 57
- Option 58
- Option 59
- Option 60
- Option 61
- Option 62
- Option 63
- Option 64
- Option 65
- Option 66
- Option 67
- Option 68
- Option 69
- Option 70
- Option 71
- Option 72
- Option 73
- Option 74
- Option 75
- Option 76
- Option 77
- Option 78
- Option 79
- Option 80
- Option 81
- Option 82
- Option 83
- Option 84
- Option 85
- Option 86
- Option 87
- Option 88
- Option 89
- Option 90
- Option 91
- Option 92
- Option 93
- Option 94
- Option 95
- Option 96
- Option 97
- Option 98
- Option 99
- Option 100
- Option 101
- Option 102
- Option 103
- Option 104
- Option 105
- Option 106
- Option 107
- Option 108
- Option 109
- Option 110
- Option 111
- Option 112
- Option 113
- Option 114
- Option 115
- Option 116
- Option 117
- Option 118
- Option 119
- Option 120
- Option 121
- Option 122
- Option 123
- Option 124
- Option 125
- Option 126
- Option 127
- Option 128
- Option 129
- Option 130
- Option 131
- Option 132
- Option 133
- Option 134
- Option 135
- Option 136
- Option 137
- Option 138
- Option 139
- Option 140
- Option 141
- Option 142
- Option 143
- Option 144
- Option 145
- Option 146
- Option 147
- Option 148
- Option 149
- Option 150
- Option 151
- Option 152
- Option 153
- Option 154
- Option 155
- Option 156
- Option 157
- Option 158
- Option 159
- Option 160
- Option 161
- Option 162
- Option 163
- Option 164
- Option 165
- Option 166
- Option 167
- Option 168
- Option 169
- Option 170
- Option 171
- Option 172
- Option 173
- Option 174
- Option 175
- Option 176
- Option 177
- Option 178
- Option 179
- Option 180
- Option 181
- Option 182
- Option 183
- Option 184
- Option 185
- Option 186
- Option 187
- Option 188
- Option 189
- Option 190
- Option 191
- Option 192
- Option 193
- Option 194
- Option 195
- Option 196
- Option 197
- Option 198
- Option 199
- Option 200
- Option 201
- Option 202
- Option 203
- Option 204
- Option 205
- Option 206
- Option 207
- Option 208
- Option 209
- Option 210
- Option 211
- Option 212
- Option 213
- Option 214
- Option 215
- Option 216
- Option 217
- Option 218
- Option 219
- Option 220
- Option 221
- Option 222
- Option 223
- Option 224
- Option 225
- Option 226
- Option 227
- Option 228
- Option 229
- Option 230
- Option 231
- Option 232
- Option 233
- Option 234
- Option 235
{
"content": [
{
"text": "Hello! How can I help you today?",
"type": "output_text"
}
],
"id": "msg-abc123",
"role": "assistant",
"status": "completed",
"type": "message"
}completed, incomplete, in_progress, failed, cancelled, queued "completed"
auto "auto"
Function tool definition
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- Option 6
- Option 7
- Option 8
- Option 9
- Option 10
- Option 11
- Option 12
- Option 13
- Option 14
{
"description": "Get the current weather in a location",
"name": "get_weather",
"parameters": {
"properties": {
"location": {
"description": "The city and state",
"type": "string"
},
"unit": {
"enum": ["celsius", "fahrenheit"],
"type": "string"
}
},
"required": ["location"],
"type": "object"
},
"type": "function"
}{
"id": "prompt-abc123",
"variables": { "name": "John" }
}{ "effort": "medium", "summary": "auto" }auto, default, flex, priority, scale, null "default"
Text output configuration including format and verbosity
{
"format": { "type": "text" },
"verbosity": "medium"
}auto, disabled, null "auto"
Token usage information for the response
{
"input_tokens": 10,
"input_tokens_details": { "cached_tokens": 0 },
"output_tokens": 25,
"output_tokens_details": { "reasoning_tokens": 0 },
"total_tokens": 35,
"cost": 0.0012,
"cost_details": {
"upstream_inference_cost": null,
"upstream_inference_input_cost": 0.0008,
"upstream_inference_output_cost": 0.0004
}
}Canonical OpenRouter error type, stable across all API formats
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 "rate_limit_exceeded"
{
"attempt": 1,
"endpoints": {
"available": [
{
"model": "openai/gpt-4o",
"provider": "OpenAI",
"selected": true
}
],
"total": 1
},
"is_byok": false,
"region": "iad",
"requested": "openai/gpt-4o",
"strategy": "direct",
"summary": "available=1, selected=OpenAI"
}