Command Palette

Search for a command to run...

OpenRouter

OpenRouter is a unified gateway that provides developers and organizations with a single, OpenAI-compatible API for 400-plus large-language models (LLMs) supplied by more than 60 different model providers.

Rather than managing multiple credentials, rate limits, and slightly different API dialects for each vendor, you can purchase credits once on OpenRouter and query any supported model with the same request format used by openai.ChatCompletion.create()


  What problem does it solve?

Challenge without OpenRouterHow OpenRouter helps
Each LLM vendor exposes its own endpoint, auth method, rate limits and schema quirks.A single key, a single endpoint (https://openrouter.ai/api/v1/chat/completions) that mirrors the OpenAI spec.
Provider outages cause hard errors in production.Provider routing & automatic fall-back: if the preferred provider for a model is unhealthy, OpenRouter retries the next provider transparently.
Continually switching to the cheapest / fastest provider is painful.Dynamic variants (:nitro, :floor) automatically route to the fastest or cheapest provider for each request.
Limited visibility into pricing and usage across vendors.A unified credit system, detailed usage analytics, and per-model pricing tables.
Need to experiment with new models quickly.400+ models are instantly available—one CLI or curl command away.

  Key Features

    Huge model catalog

  • Frontier models: GPT-4.1, Claude 3.7, Gemini 2.5 Pro, Mistral‐Medium, Perplexity Mixtral-8x22B, etc.
  • Open-source models served on high-performance GPU clusters (Groq, Together, Nous, Databricks, etc.).
  • All models are discoverable via the Models API that returns rich JSON metadata (context length, pricing, supported parameters, etc.).

    Unified, OpenAI-style API

POST https://openrouter.ai/api/v1/chat/completions
Authorization: Bearer $OPENROUTER_API_KEY
Content-Type: application/json

{
  "model": "anthropic/claude-3-sonnet",  
  "messages": [{"role": "user", "content": "Hello!"}],
  "stream": true
}

• Works with any OpenAI SDK out of the box.

    Provider & model routing

  • Provider routing: If you specify multiple providers for the same model, OpenRouter will pick the best one based on latency or cost, and fail-over when necessary.
  • Model routing: Provide a list of models and let OpenRouter fall back or A/B test automatically.
  • Variants: append :nitro, :floor, :online, :beta, :free, etc., to tweak routing behavior.

    Privacy & logging controls

  • Zero prompt / completion logging by default.
  • Opt-in prompt logging for a 1 % discount.
  • Fine-grained privacy settings (e.g., disallow routing to providers that log prompts for training).

    Advanced capabilities

  • Tool calling / function calling identical to OpenAI.
  • Images & PDFs as input where supported by the underlying model.
  • Structured Outputs JSON schema enforcement.
  • Web-enabled variants to automatically include live search results.
  • Reasoning tokens to pay for chain-of-thought only when you need it.

    Enterprise features

  • Custom data policies to restrict where prompts can be processed.
  • Provisioning API for programmatic key management.
  • SLAs, team management, and dedicated support (contact sales).

  Pricing

OpenRouter does not add any markup to the per-token prices of the underlying provider. Instead, it charges a 5 % + $0.35 fee only when you purchase credits. Once credits are in your account:

  • You pay the exact provider-listed price per prompt/completion token (or per image/request if applicable).
  • BYOK (Bring Your Own Key) is supported with a 5 % usage fee deducted from your credits.
  • Many community or open-source models are free, but have low daily rate limits (50-1000 req/day).

A small free credit allowance is provided to new accounts so you can test the API without entering payment information.


  Pros & Cons

    Pros

  1. Breadth of models: widest catalog on the market.
  2. OpenAI drop-in: minimal code changes to switch.
  3. Automatic fallbacks greatly improve production reliability.
  4. Transparent pricing with no inference markup.
  5. Edge-deployed infrastructure adds only ~25 ms latency overhead.

    Cons

  1. You pre-pay credits; unused credits may expire after one year.
  2. Purchasing credits incurs a 5 % fee, so at very high volume direct provider billing might be cheaper.
  3. Some free models have strict rate limits and may throttle quickly.
  4. As a proxy layer, certain provider-specific features (e.g., OpenAI vector storage) are not exposed.

  When to Use OpenRouter

  • You want to benchmark many models quickly without opening new accounts.
  • Your application must stay online even if Anthropic or OpenAI has an outage.
  • You need cost or latency optimization across providers in real time.
  • You prefer a single invoice and dashboard for all model usage.

  Getting Started

  1. Sign up at https://openrouter.ai/ (GitHub, Google, or crypto wallet).

  2. Buy credits (Stripe, AliPay, or USDC) or use the free starter allowance.

  3. Generate an API key in the dashboard.

  4. Replace your OpenAI base URL & key:

    import openai
    openai.api_key = "YOUR_OPENROUTER_API_KEY"
    openai.base_url = "https://openrouter.ai/api/v1"
  5. Send a test request with any supported model slug—done!


  Resources