πŸ€– AI/ML

OpenRouter

An API service providing multiple LLMs in one place

πŸ“– Detailed Explanation

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.

πŸ’» Code Example

# 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)

πŸ“Š Performance & Cost

As of January 2025 - OpenRouter provides models at original cost under a pass-through pricing policy.

ItemPricing/specsNotes
Price margin0% (Pass-through)Provided at original cost
Platform fee~5%When purchasing credits
Number of supported models400+GPT, Claude, Gemini, Llama, etc.
Free user limits50 requests/day1,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

πŸ—£οΈ Say It Like This in Practice

πŸ’¬ In a Meeting
"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."
πŸ’¬ In an Interview
"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."
πŸ’¬ In a Technical Discussion
"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

⚠️ Common Mistakes & Cautions

❌
Always using OpenRouter in production

Under heavy traffic, each provider's direct API can be more stable. Separate your prototype and production strategies.

❌
Hardcoding API keys

Entering your OpenRouter API key directly in code is a security risk. Use environment variables or a secrets manager.

βœ…
The right way

Compare various models through OpenRouter during development/testing, and in production switch to the chosen model's direct API or configure fallback settings.

πŸ”— Related Terms

πŸ“š Learn More