Create a chat completion
Sends a request for a model response for the given chat conversation. Supports both streaming and non-streaming modes.
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
Chat completion request parameters
List of messages for the conversation
1Chat completion message with role-based discrimination
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
{
"content": "What is the capital of France?",
"name": "Assistant Config",
"role": "user"
}[{ "content": "Hello!", "role": "user" }]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 }Frequency penalty (-2.0 to 2.0)
0
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" }Token logit bias adjustments
{ "50256": -100 }Return log probabilities
false
Maximum tokens in completion
100
Maximum tokens (deprecated, use max_completion_tokens). Note: some providers enforce a minimum of 16.
100
Key-value pairs for additional object information (max 16 pairs, 64 char keys, 512 char values)
{
"session_id": "session-456",
"user_id": "user-123"
}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.
0.1
Output modalities for the response. Supported values are "text", "image", and "audio".
text, image, audio ["text", "image"]Model to use for completion
"openai/gpt-4"
Models to use for completion
Available OpenRouter chat completion models
["openai/gpt-4", "openai/gpt-4o"]Whether to enable parallel function calling during tool use. When true, the model may generate multiple tool calls in a single response.
true
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"
}Presence penalty (-2.0 to 2.0)
0
When multiple model providers are available, optionally indicate your routing preference.
{ "allow_fallbacks": true }Configuration options for reasoning models
{ "effort": "medium", "summary": "concise" }Shorthand for setting reasoning effort. Equivalent to setting reasoning.effort. Cannot be used simultaneously with reasoning.effort if they differ.
max, xhigh, high, medium, low, minimal, none, null "medium"
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.
1
Response format configuration
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
{ "type": "json_object" }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"
Random seed for deterministic outputs
42
The service tier to use for processing this request.
auto, default, flex, priority, scale, null "auto"
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 sequences (up to 4)
["\n"]Stop 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"
}
]Enable streaming response
false
Streaming configuration options
{ "include_usage": true }Sampling temperature (0-2)
0.7
Tool choice configuration
none "auto"
Available tools for function calling
Tool definition for function calling (regular function or OpenRouter built-in server tool)
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- Option 6
- Option 7
- Option 8
- Option 9
- Option 10
- Option 11
{
"function": {
"description": "Get the current weather for a location",
"name": "get_weather",
"parameters": {
"properties": {
"location": {
"description": "City name",
"type": "string"
},
"unit": {
"enum": ["celsius", "fahrenheit"],
"type": "string"
}
},
"required": ["location"],
"type": "object"
}
},
"type": "function"
}[
{
"function": {
"description": "Get weather",
"name": "get_weather"
},
"type": "function"
}
]Consider only tokens with "sufficiently high" probabilities based on the probability of the most likely token. Not all providers support this parameter.
0
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.
40
Number of top log probabilities to return (0-20)
5
Nucleus sampling parameter (0-1)
1
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"
}Unique user identifier
"user-123"
Response
Successful chat completion response
Chat completion response
List of completion choices
Unix timestamp of creation
1677652288
Unique completion identifier
"chatcmpl-123"
Model used for completion
"openai/gpt-4"
chat.completion System fingerprint
"fp_44709d6fcb"
{
"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"
}The service tier used by the upstream provider for this request
"default"
Token usage statistics
{
"completion_tokens": 15,
"completion_tokens_details": { "reasoning_tokens": 5 },
"cost": 0.0012,
"cost_details": {
"upstream_inference_completions_cost": 0.0004,
"upstream_inference_cost": null,
"upstream_inference_prompt_cost": 0.0008
},
"is_byok": false,
"prompt_tokens": 10,
"prompt_tokens_details": { "cached_tokens": 2 },
"server_tool_use_details": {
"tool_calls_executed": 2,
"tool_calls_requested": 2
},
"total_tokens": 25
}