OpenRouter¶
What it is¶
OpenRouter is a unified interface (meta-provider) for LLMs, providing access to almost any model (OpenAI, Anthropic, Meta, DeepSeek, etc.) via a single OpenAI-compatible API.
What problem it solves¶
Eliminates the need to manage multiple API keys and client libraries for different providers. It also provides access to models that might be otherwise hard to access in certain regions.
Where it fits in the stack¶
Provider / Router Layer. It sits between the Agent and the actual LLM Providers.
Architecture overview¶
Proxy service. Your agent sends requests to OpenRouter, which then routes them to the specified backend provider (e.g., Together AI, DeepInfra, Anthropic directly).
Typical use cases¶
- Model Switching: Easily testing different models (e.g., switching from Claude 3.5 to GPT-4o) just by changing the model ID string.
- Unified Billing: Paying one provider for usage across many different model families.
- Accessing Open Models: Using Llama 3, Qwen, or Mistral models without self-hosting.
- Tool Calling: Standardizing tool usage across different models and providers.
- Interleaved Thinking: Allowing models to reason between tool calls for sophisticated decision-making.
Strengths¶
- Simplicity: One API key for everything.
- Model Variety: Access to both proprietary and open-source models.
- Standardized API: Uses the OpenAI chat completions format.
- Competitive Pricing: Often finds the cheapest provider for a given open model.
Limitations¶
- Additional Latency: Adds a small proxy overhead.
- Dependency: If OpenRouter is down, access to all routed models is lost.
- Privacy: Adds another party (OpenRouter) into the data flow.
When to use it¶
- During development and testing to quickly compare models.
- When you want to use many different models without setting up accounts with every provider.
- For hobbyist/homelab projects that benefit from unified billing.
When not to use it¶
- For latency-critical production applications.
- When you have direct enterprise agreements/discounts with a specific provider (e.g. Azure OpenAI).
Security considerations¶
- Third-party Data Flow: Your prompts pass through OpenRouter; ensure this is acceptable for your data sensitivity.
- API Key Security: Treat your OpenRouter key as a "master key" for all your AI services.
Related tools / concepts¶
Integration ecosystem and technical signal feeds¶
The OpenRouter settings integrations page is account-scoped. The table below is built from publicly documented OpenRouter community integrations and mapped to each integration's technical blog feed.
| Integration | OpenRouter integration guide | Primary use | Technical blog / engineering feed | Signal value |
|---|---|---|---|---|
| OpenAI SDK | Guide | OpenAI-compatible client routing | OpenAI News | API and model release notes |
| Anthropic Agent SDK | Guide | Agent runtime + tool orchestration | Anthropic News | Claude capabilities and policy changes |
| LangChain | Guide | LLM app chains and agents | LangChain Blog | Framework patterns and breaking changes |
| Langfuse | Guide | Tracing, observability, evals | Langfuse Blog | Prompt/trace observability practices |
| Arize | Guide | Evaluation and monitoring | Arize Blog | Production eval and drift monitoring |
| LiveKit | Guide | Realtime voice/video agents | LiveKit Blog | Realtime agent implementation details |
| PydanticAI | Guide | Typed agent workflows | Pydantic Articles | Structured-output and schema patterns |
| TanStack AI | Guide | Frontend AI UX integration | TanStack Blog | Frontend framework and API updates |
| Vercel AI SDK | Guide | Streaming and UI assistants | Vercel Blog (AI) | AI SDK capabilities and patterns |
| Infisical | Guide | Secret management for keys | Infisical Blog | Secret ops and secure delivery practices |
| Zapier | Guide | SaaS automation and triggers | Zapier Engineering | Integration architecture and reliability |
| Xcode | Guide | Apple-side local development flow | Apple Developer News | Toolchain and platform-level updates |
Suggested comparison matrix¶
Use this matrix for quarterly integration reviews:
| Integration | Setup complexity | Observability depth | Security posture | Best for | Notes |
|---|---|---|---|---|---|
| OpenAI SDK | Low | Medium | Medium | Simple API migration | Minimal integration friction |
| Anthropic Agent SDK | Medium | Medium | Medium | Agentic workflows | Strong tool-loop ergonomics |
| LangChain | Medium | Medium | Medium | Multi-step pipelines | Large ecosystem, more moving parts |
| Langfuse | Medium | High | Medium | Traces/evals | High value for debugging |
| Arize | Medium | High | Medium | Model quality monitoring | Best for long-lived systems |
| LiveKit | High | Medium | Medium | Realtime agents | Voice/video-centric stacks |
| PydanticAI | Medium | Medium | Medium | Typed structured outputs | Strong schema discipline |
| TanStack AI | Medium | Medium | Medium | Frontend AI apps | UI-oriented workflows |
| Vercel AI SDK | Low | Medium | Medium | Streaming chat apps | Fast web integration |
| Infisical | Medium | Low | High | Secret lifecycle | Good baseline hardening layer |
| Zapier | Low | Low | Medium | No-code automation | Fast to ship, less control |
| Xcode | Medium | Low | Medium | Apple-native tooling | Useful for iOS/macOS pipelines |
Getting started¶
Installation¶
OpenRouter is an OpenAI-compatible API. You can use the standard OpenAI Python client by pointing the base_url to OpenRouter.
pip install openai
Minimal Python Example¶
from openai import OpenAI
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key="your-api-key",
)
completion = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
messages=[
{
"role": "user",
"content": "What is the capital of France?"
}
]
)
print(completion.choices[0].message.content)
API examples¶
Using OpenAI SDK with OpenRouter¶
from openai import OpenAI
# Initialize the client with OpenRouter's base URL and your API key
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key="sk-or-v1-xxxxxx...",
)
completion = client.chat.completions.create(
extra_headers={
"HTTP-Referer": "https://your-site-url.com", # Optional, for including your app on openrouter.ai rankings.
"X-Title": "Your App Name", # Optional. Shows in rankings on openrouter.ai.
},
model="anthropic/claude-3.5-sonnet",
messages=[
{
"role": "user",
"content": "What is the best way to implement a multi-agent system?"
}
]
)
print(completion.choices[0].message.content)
Tool Calling with OpenRouter (OpenAI SDK)¶
import json
from openai import OpenAI
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key="your-api-key",
)
# 1. Define the tool
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "The city and state, e.g. San Francisco, CA"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["location"]
}
}
}
]
# 2. First request to let the model decide to use a tool
messages = [{"role": "user", "content": "What's the weather like in Paris?"}]
response = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
messages=messages,
tools=tools
)
response_message = response.choices[0].message
messages.append(response_message)
# 3. Handle tool calls
if response_message.tool_calls:
for tool_call in response_message.tool_calls:
# Execute your local function here based on tool_call.function.name
# For this example, we'll use a dummy response
tool_result = "Sunny, 22°C"
messages.append({
"role": "tool",
"tool_call_id": tool_call.id,
"name": tool_call.function.name,
"content": tool_result
})
# 4. Send the tool result back to the model
final_response = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
messages=messages,
tools=tools # Must be included in every request
)
print(final_response.choices[0].message.content)
Sources / References¶
- OpenRouter overview
- OpenRouter Tool & Function Calling
- OpenRouter integrations settings
- OpenRouter community integration guides
- OpenAI News
- Anthropic News
- LangChain Blog
- Langfuse Blog
- Arize Blog
- LiveKit Blog
- Pydantic Articles
- TanStack Blog
- Vercel Blog (AI)
- Infisical Blog
- Zapier Engineering
- Apple Developer News
Contribution Metadata¶
- Last reviewed: 2026-03-03
- Confidence: medium