惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

人人都是产品经理
人人都是产品经理
D
Docker
GbyAI
GbyAI
B
Blog RSS Feed
博客园 - 司徒正美
博客园 - Franky
美团技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
IT之家
IT之家
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com
AI
AI
O
OpenAI News
Attack and Defense Labs
Attack and Defense Labs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
S
Secure Thoughts
博客园 - 聂微东
L
LINUX DO - 最新话题
U
Unit 42
SecWiki News
SecWiki News
A
Arctic Wolf
Schneier on Security
Schneier on Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Visual Studio Blog
量子位
The Cloudflare Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
G
Google Developers Blog
T
Threat Research - Cisco Blogs
TaoSecurity Blog
TaoSecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
B
Blog
博客园 - 【当耐特】
C
CERT Recently Published Vulnerability Notes
Scott Helme
Scott Helme
Last Week in AI
Last Week in AI
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
Latest news
Latest news

OpenRouter Blog

Choosing the Optimal Image Input Detail Level in LLMs — OpenRouter Blog DeepSeek V4 Is Earning Agentic Token Share — OpenRouter Blog The Open Weight Models that Matter: June 2026 — OpenRouter Blog The OpenRouter MCP Server — OpenRouter Blog Introducing the Unified Image API — OpenRouter Blog The AI Governance Checklist That Maps to Your Stack — OpenRouter Blog Enforce AI Data Residency at the Routing Layer — OpenRouter Blog OpenRouter vs Portkey: Routing Network vs Control Plane — OpenRouter Blog OpenRouter vs LiteLLM: Managed vs Self-Hosted Gateway — OpenRouter Blog Connect OpenClaw to OpenRouter: One Key, Failover, Free Models — OpenRouter Blog Connect SillyTavern to OpenRouter: Setup, Models, Fixes — OpenRouter Blog A Robot is Sprinting Towards You: Do You Want it Running on Claude or Grok? Kilo Code + OpenRouter: Setup, Routing, and Free Models — OpenRouter Blog Codex CLI with OpenRouter: config.toml Setup and Models — OpenRouter Blog Claude Code with OpenRouter: Setup, Models, and Costs — OpenRouter Blog Subagent: Let Your Model Delegate the Busywork — OpenRouter Blog Free LLM API in 2026: 13 Options Ranked and Compared — OpenRouter Blog How to Enforce Agentic AI Governance at the API Layer — OpenRouter Blog Keep Your Agent Running When Models Disappear — OpenRouter Blog Hermes Agent + OpenRouter: Setup, Model Choice & Routing Config — OpenRouter Blog Lowest-Cost LLM Inference: The Complete OpenRouter Guide — OpenRouter Blog How OpenRouter Model Routing Works: Providers, Fallbacks & Auto Router — OpenRouter Blog OpenRouter Failover: Provider Failover vs Model Fallbacks Explained — OpenRouter Blog Surpassing Frontier Performance with Fusion — OpenRouter Blog Dinner is Served — OpenRouter Blog LLM Gateway: What It Is and How to Choose One — OpenRouter Blog Advisor: Give Any Model a Lifeline to a Smarter One — OpenRouter Blog Gemini 2.5 Flash API - Pricing, Quickstart & Provider Comparison — OpenRouter Blog EU AI Act & Colorado ADMT Compliance: Human Oversight for AI Agents — OpenRouter Blog May Release Spotlight — OpenRouter Blog Guardrails: Protect your Agents, Data, and Costs — OpenRouter Blog OpenRouter Raises $113M Series B — OpenRouter Blog Human-in-the-Loop Tools for the Agent SDK — OpenRouter Blog Consistent Web Search and Fetch Across Every Model — OpenRouter Blog GPT-5.5 Price Increase: What It Actually Costs — OpenRouter Blog New Audio APIs for Speech and Transcription — OpenRouter Blog Response Caching: Zero Cost for Identical Requests — OpenRouter Blog April Release Spotlight — OpenRouter Blog Create OpenRouter Accounts via CLI with Stripe Projects — OpenRouter Blog Opus 4.7 Agent SDK: Building Multi-turn Agent Workflows on OpenRouter — OpenRouter Blog Build Your Own Harness with the Agent SDK — OpenRouter Blog Introducing Workspaces — OpenRouter Blog Announcing Video Generation — OpenRouter Blog Auto Exacto: Adaptive Quality Routing, On by Default — OpenRouter Blog February Release Spotlight — OpenRouter Blog OpenRouter Outages on February 17 and 19, 2026 — OpenRouter Blog January Release Spotlight — OpenRouter Blog Distillable Models and Synthetic Data Pipelines with NeMo Data Designer — OpenRouter Blog December Release Spotlight — OpenRouter Blog Response Healing: Reduce JSON Defects by 80%+ — OpenRouter Blog The 2025 State of AI Report — OpenRouter Blog Is Implicit Caching Prompt Retention? — OpenRouter Blog Provider Variance: Introducing Exacto — OpenRouter Blog 1 million free BYOK requests per month — OpenRouter Blog The First-Ever Image Model Is Up on OpenRouter — OpenRouter Blog GPT-5 is now live — OpenRouter Blog Audio Inputs and PDF URLs for Apps — OpenRouter Blog Presets: How To Seamlessly Transfer Model Configurations Across Apps — OpenRouter Blog New Privacy-Focused Provider Drop: Venice — OpenRouter Blog Use OpenRouter Models in Cursor: Try it with Moonshot AI Updates to Our Free Tier: Sustaining Accessible AI for Everyone — OpenRouter Blog New Stealth Model: "Cypher Alpha" — OpenRouter Blog Introducing Presets: Manage LLM Configs from Your Dashboard! — OpenRouter Blog Dev & BYOK Updates: Uptime API + Smarter Key Management — OpenRouter Blog Simplifying Our Platform Fee — OpenRouter Blog GIF Prompts, Omni Search, Tool Caching, and BYOK Flags — OpenRouter Blog New Features: Reasoning Streams, Crypto Invoices, End-User IDs & More — OpenRouter Blog Passkeys, DevEx Upgrades, and a New Guide for TypeScript Agents — OpenRouter Blog New Provider Drop: Cerebras Is Here — OpenRouter Blog Better Insights, Faster Metrics, and New Developer Power Tools — OpenRouter Blog Privacy Clarity, New Providers, OAuth Upgrade, and Gemini Gets Parallel Tools — OpenRouter Blog Universal PDF Support — OpenRouter Blog Smarter Charts, Inline SVGs, and Live Usage Accounting — OpenRouter Blog Quasar Alpha and Optimus Alpha Reveal — OpenRouter Blog "Stealth" model: Optimus Alpha — OpenRouter Blog “Stealth” model: Quasar Alpha — OpenRouter Blog Never Pay for Empty AI Responses Again — OpenRouter Blog Deep Research & Many New Models — OpenRouter Blog Introducing Nitro and Floor Price Shortcuts — OpenRouter Blog Introducing Cloudflare as a new provider — OpenRouter Blog Reasoning Tokens for Thinking Models — OpenRouter Blog Introducing Web Search via the API — OpenRouter Blog Standardized finish reasons — OpenRouter Blog Happy New Year! Introducing a new Auto Router — OpenRouter Blog Holiday launches: Web Search & Price Cuts — OpenRouter Blog Bring Your Own API Keys — OpenRouter Blog Crypto Payments API — OpenRouter Blog Structured Outputs & Free Gemini Flash 2.0 — OpenRouter Blog Price Drops and Llama 3.3 70b — OpenRouter Blog Author Pages & Amazon Nova — OpenRouter Blog
How to Use OpenRouter With Any Coding Agent or AI Tool — OpenRouter Blog
OpenRouter · 2026-06-16 · via OpenRouter Blog

OpenRouter sits between your coding tool and the model providers it calls. Your tool still sends the requests. OpenRouter handles the provider relationships, the model catalog, usage visibility, billing, and routing behind one API key.

That matters the moment you use more than one tool, model, or provider. Without it, you juggle a separate key, a separate billing dashboard, and a separate config path for OpenAI, Anthropic, Google, and everyone else. With it, every supported tool uses the same sk-or-... key, the same model slug format, and the same base URL.

Connect a tool once and you can switch models by editing one string, watch all your spend in one place, and keep an agent running when a provider falls over. Here’s the setup pattern and the tools that already speak it.

Three setup moves that work everywhere

Any tool that speaks the OpenAI Chat Completions API works with OpenRouter, because OpenRouter exposes that same API. You change two values, the base URL and the key, then pick a model, and the rest of your code stays put. That single endpoint fronts 300+ models across 70+ providers.

The three moves:

  1. Get a key. Create one on your keys page. OpenRouter keys start with sk-or-, which is how a tool knows it’s talking to OpenRouter and not OpenAI directly. Store it in an environment variable, not in source. A plain sk-... key is an OpenAI key and won’t route.
  2. Point the base URL at https://openrouter.ai/api/v1. Because the API is OpenAI-compatible, the official OpenAI SDKs work once you swap this one value.
  3. Pick a model slug in provider/model form, like openai/gpt-4o or anthropic/claude-sonnet-4. The slug is the only thing you change to switch models. Browse the catalog at openrouter.ai/models.

Most tools expose these settings in different places, an environment variable, a config file, or a settings screen, but the values are identical everywhere. Here’s the same call three ways.

curl https://openrouter.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4",
    "messages": [{"role": "user", "content": "Refactor this function."}]
  }'
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key=os.environ["OPENROUTER_API_KEY"],
)
resp = client.chat.completions.create(
    model="openai/gpt-4o",
    messages=[{"role": "user", "content": "Refactor this function."}],
)
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://openrouter.ai/api/v1",
  apiKey: process.env.OPENROUTER_API_KEY,
});
const resp = await client.chat.completions.create({
  model: "anthropic/claude-sonnet-4",
  messages: [{ role: "user", content: "Refactor this function." }],
});

Those two use the OpenAI SDK, which most projects already have installed. OpenRouter also ships its own SDKs that make the same call with no base URL to set: openrouter for Python and @openrouter/sdk for TypeScript.

from openrouter import OpenRouter
import os

with OpenRouter(api_key=os.environ["OPENROUTER_API_KEY"]) as client:
    resp = client.chat.send(
        model="anthropic/claude-sonnet-4",
        messages=[{"role": "user", "content": "Refactor this function."}],
    )
import { OpenRouter } from "@openrouter/sdk";

const client = new OpenRouter({
  apiKey: process.env.OPENROUTER_API_KEY,
});
const resp = await client.chat.send({
  model: "anthropic/claude-sonnet-4",
  messages: [{ role: "user", content: "Refactor this function." }],
});

Two optional headers, HTTP-Referer and X-Title, let you label your app so it shows up in OpenRouter’s rankings. Neither is required for a working request. See app attribution for the details.

The same key works across every tool below, so once you have one, you’re done provisioning for the whole list. The terminal agents read config files or environment variables; the editors and extensions configure in a settings panel.

ToolHow it connectsSetup
Claude Code (Anthropic’s terminal agent)Environment variables, via OpenRouter’s Anthropic-compatible endpointGuide
Codex CLI (OpenAI’s open-source terminal agent)~/.codex/config.toml with model_provider = "openrouter"Guide
OpenClaw (open-source agent, formerly Moltbot/Clawdbot)~/.openclaw/openclaw.json, or OPENROUTER_API_KEYGuide
Hermes Agent (Nous Research’s open-source CLI agent)~/.hermes/config.yaml, with the key in ~/.hermes/.envGuide
Cursor (AI code editor)In-app settings: custom OpenAI base URL plus keyGuide
Cline (VS Code agent extension)Extension settings: OpenRouter providerPage
Kilo Code (VS Code agent extension)Extension settings: OpenRouter providerPage
SillyTavern (local-first chat frontend)Connection settings: OpenRouter APIPage

That list isn’t exhaustive. OpenRouter also works with Claude Desktop, Junie CLI, OpenCode, and MCP servers. The pattern is the same every time: one key, one base URL, one slug.

How routing keeps your agent alive

The single endpoint buys you routing, and that matters more for an agent than for a one-off script.

A failed API call is easy to handle on its own. You catch the error and retry. An agent on a multi-step task is less forgiving, because it holds state across many calls. A provider failure halfway through can leave a half-applied edit, a tool call that never returned its result, or a plan the agent now reasons about as if it finished. When the failover happens down at the routing layer, the agent never sees the failure. It gets its completion and keeps going. Two mechanisms do this work, and they stack.

Automatic provider failover

This needs no configuration. A given model is often served by several providers, and if the one OpenRouter tries first is down or rate-limiting you, it routes the same model to another provider serving it. You pay only for the call that lands.

Manual model fallback

This is the layer you opt into. Instead of backup providers, you name backup models by passing a models array (with the OpenAI SDK, inside extra_body={"models": [...]}). OpenRouter tries your primary first, then each fallback in order, and bills you for whichever model actually ran, returned in the response’s model field. That covers the case where a model has a single provider behind it and that provider goes dark, exactly when provider-level failover has nowhere to route.

If you would rather not choose at all, the Auto Router (openrouter/auto) picks a model per prompt, sending simpler requests to cheaper models and harder ones to stronger models. You pay the standard rate for whatever it selects, with no extra routing fee. It’s handy when prototyping, before you know which model fits a task.

Building your own agent with the SDKs

If you’re wiring up an existing tool, the steps above are all you need. If you’re building your own agent, OpenRouter gives you two SDKs.

The Client SDK, for TypeScript and Python, is a thin, type-safe layer over the REST API, with generated types and autocomplete instead of hand-written HTTP.

The Agent SDK runs the loop for you. It manages the multi-turn conversation, executes your tools, and tracks state through a single callModel primitive. Because you can change the model between turns, a cheap step like reading a file can route to a cheap model while code generation goes to a stronger one, inside the same loop.

Here’s the shape of a tool-using call. This one callModel invocation sends the prompt, lets the model call get_weather, runs it, feeds the result back, and returns the final text.

import { callModel, tool } from "@openrouter/agent";
import { z } from "zod";

const weatherTool = tool({
  name: "get_weather",
  description: "Get the current weather for a location",
  inputSchema: z.object({ location: z.string() }),
  execute: async ({ location }) => ({ temperature: 72, condition: "sunny", location }),
});

const result = await callModel({
  model: "anthropic/claude-sonnet-4",
  messages: [{ role: "user", content: "What is the weather in San Francisco?" }],
  tools: [weatherTool],
});

const text = await result.getText();

Cost and rate limits

OpenRouter has a free tier. 20+ models run at $0, capped at 50 requests a day and 20 a minute, rising to 1,000 a day once you add $10 in credits. Two caveats before you lean on it. Failed attempts still count against the daily quota, and popular free models can get rate-limited by the upstream provider at peak times. Even so, it’s enough to take an agent end to end before you spend anything on inference.

On paid usage, OpenRouter doesn’t mark up model pricing. You pay the same per-token rate you’d pay the provider directly, which is what the model catalog shows. On top of that, credit purchases carry a 5.5% fee, with a $0.80 minimum. So your inference stays at provider rates and OpenRouter’s cut is that fee on credits. The pricing page has the current numbers, and the Activity dashboard shows per-request model and cost in real time, the fastest way to catch an agent burning credits on a model heavier than the task needs.

Frequently asked questions

Do I need a separate API key for each tool?

No. One OpenRouter key works in every tool in this list. Generate it once at openrouter.ai/keys and paste the same sk-or-... value into Claude Code, Codex CLI, Cursor, or any other supported tool.

Does OpenRouter work with the OpenAI SDK?

Yes. Point base_url (Python) or baseURL (TypeScript) at https://openrouter.ai/api/v1 and pass your OpenRouter key. OpenRouter is a drop-in replacement for the OpenAI Chat API, so the official SDKs work with no other changes.

How do I use OpenRouter for free?

Use a free model and stay within the free tier. Free models, the :free variants on the models page, run at up to 50 requests a day, rising to 1,000 a day once you add $10 in credits.

Can I use OpenRouter in VS Code?

Yes. Use an agent extension like Cline or Kilo Code that exposes an OpenRouter provider, or any extension that lets you set a custom OpenAI base URL. Set the base URL to https://openrouter.ai/api/v1, paste your key, and pick a model.

What model slug format does OpenRouter use?

The format is provider/model, for example openai/gpt-4o or anthropic/claude-sonnet-4. Prefix the author with ~, like ~anthropic/claude-sonnet-latest, to always resolve to the newest version in a family. Browse the full list at openrouter.ai/models.

Does OpenRouter log my code or prompts?

No, not by default, even if a request errors, unless you explicitly opt in. There’s an opt-in setting that trades logging for a small usage discount. See the Privacy Policy for the details.