OpenRouter
An API service providing multiple LLMs in one place
An API service providing multiple LLMs in one place
OpenRouter is an AI model routing service that lets you access a variety of large language models (LLMs) through a single unified API. You can call more than 400 AI models, including OpenAI's GPT, Anthropic's Claude, Google's Gemini, and Meta's Llama, through a single endpoint, so developers can experiment with and use various models without managing multiple API keys.
OpenRouter was founded in 2023 to address the fragmentation of the AI ecosystem. By standardizing the different API formats and authentication methods of each AI provider into a unified OpenAI-compatible format, it lets developers switch and compare models easily.
The core principle is the API gateway pattern. It receives the user's request, forwards it to the relevant model provider, and returns the response in a standardized format. With the automatic fallback feature, if one model does not respond, it switches automatically to an alternative model, ensuring service stability.
In practice, it is useful for quickly testing various models during prototyping, or for using different models per task to optimize costs. With the pass-through pricing policy you pay the original cost as is, which makes it cost-efficient.
# OpenRouter API μ¬μ© μμ
import requests
OPENROUTER_API_KEY = "your-api-key"
response = requests.post(
url="https://openrouter.ai/api/v1/chat/completions",
headers={
"Authorization": f"Bearer {OPENROUTER_API_KEY}",
"Content-Type": "application/json"
},
json={
# λ€μν λͺ¨λΈ μ ν κ°λ₯
"model": "anthropic/claude-3.5-sonnet", # λλ "openai/gpt-4o"
"messages": [
{"role": "user", "content": "AIμ λ―Έλμ λν΄ μ€λͺ
ν΄μ£ΌμΈμ"}
]
}
)
result = response.json()
print(result["choices"][0]["message"]["content"])
# OpenAI SDK νΈν λ°©μ (κΆμ₯)
from openai import OpenAI
client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key=OPENROUTER_API_KEY,
)
completion = client.chat.completions.create(
model="google/gemini-pro-1.5", # λͺ¨λΈλ§ λ³κ²½νλ©΄ λ¨
messages=[
{"role": "user", "content": "νκ΅μ μλλ?"}
]
)
print(completion.choices[0].message.content)
As of January 2025 - OpenRouter provides models at original cost under a pass-through pricing policy.
| Item | Pricing/specs | Notes |
|---|---|---|
| Price margin | 0% (Pass-through) | Provided at original cost |
| Platform fee | ~5% | When purchasing credits |
| Number of supported models | 400+ | GPT, Claude, Gemini, Llama, etc. |
| Free user limits | 50 requests/day | 1,000 requests/day with a $10 top-up |
| Claude 3.5 Sonnet | $3/$15 (input/output per 1M) | Same as original cost |
| GPT-4o | $2.50/$10 (input/output per 1M) | Same as original cost |
| Llama 3.1 70B | $0.52/$0.75 (input/output per 1M) | Open-source models |
"At the prototype stage I compared the performance of several models through OpenRouter, and Claude gave the best results for code generation. In production, you can just switch directly to that model."
"Using an API gateway like OpenRouter gives you access to more than 400 models from a single codebase, so you can avoid vendor lock-in and find the best cost-performance combination."
"With OpenRouter's fallback feature, even if a particular model goes down, it automatically switches to an alternative model, so you can maintain service availability above 99.9%."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free
Under heavy traffic, each provider's direct API can be more stable. Separate your prototype and production strategies.
Entering your OpenRouter API key directly in code is a security risk. Use environment variables or a secrets manager.
Compare various models through OpenRouter during development/testing, and in production switch to the chosen model's direct API or configure fallback settings.