OpenRouter API keys are created at openrouter.ai/keys, each with a name and an optional credit limit, and sent as Authorization: Bearer <key> to https://openrouter.ai/api/v1. OpenRouter's examples read the key from OPENROUTER_API_KEY. OpenRouter recommends a credit limit on every key, because one key can spend the account's whole balance, including auto top-ups.
OpenRouter key types
| Type | Prefix | Secret? | Scope | Expiry |
|---|---|---|---|---|
| OpenRouter API key OpenRouter does not document a key prefix; an example response in its management key docs shows a label beginning sk-or-v1-. Onboarding keys also come with a $100 credit limit. | — | Yes | Calls every model OpenRouter routes to, spending account credits up to the key's own credit limit | Keys created during onboarding expire after 180 days; OpenRouter does not document expiry for other keys |
| Management API key Created at openrouter.ai/settings/management-keys. In organizations only Organization Admins can create one. | — | Yes | Account administration through `/api/v1/keys` and other admin endpoints across every workspace; cannot call completion endpoints | Chosen at creation and cannot be changed; expired keys fail with `401 Unauthorized` and "API key expired" |
How to create a OpenRouter key
- Sign in to OpenRouter and open the API keys page at
openrouter.ai/keys. - Create a key and give it a name that identifies the app or agent that will use it.
- Set a credit limit, optionally with a daily, weekly or monthly reset.
- Copy the OpenRouter key and store it in
OPENROUTER_API_KEYor a secrets manager.
Open OpenRouter's key settings
Limiting what the key can do
An OpenRouter key cannot be limited to particular models through the key itself, so the main control is money: each key has its own credit limit, and once a key reaches it OpenRouter rejects its requests until the limit is raised or resets on its daily, weekly or monthly schedule. A management key can update keys through PATCH /api/v1/keys/{hash} to rename or disable them, set limit_reset, and choose whether bring-your-own-key (BYOK) usage counts toward the limit. Budgets and guardrails at the account or organization level add further limits, and a guardrail or budget block is returned as HTTP 403.
How to rotate a OpenRouter key
- Create a new OpenRouter key at
openrouter.ai/keyswith the same credit limit (or callPOST /api/v1/keyswith a management key). - Replace
OPENROUTER_API_KEYwherever the old key is deployed. - Confirm requests succeed, then delete the old key in the dashboard or with
DELETE /api/v1/keys/{hash}.
OpenRouter lists key rotation as a use case for management keys, which can create, list, update and delete keys programmatically. Management key expiry is fixed at creation, so extending one means creating a new management key and deleting the old one.
How to revoke a OpenRouter key
- Open the API keys page at
openrouter.ai/settings/keys. - Delete the key, or disable it through the management API with
PATCH /api/v1/keys/{hash}.
If your OpenRouter key leaked
- Delete the exposed key at
openrouter.ai/settings/keys; OpenRouter advises deleting and recreating any key you suspect is exposed. - Create a replacement key with a credit limit and deploy it.
- Review the account's activity and credits for spend you do not recognise, and check whether auto top-up is on.
- Watch for OpenRouter's email; it is a GitHub secret scanning partner and notifies you when it detects a compromised key.
Environment variables and CLI
OpenRouter's SDKs and docs read the key from OPENROUTER_API_KEY.
Things that catch people out
- A key with no credit limit lets a leaked key or a runaway agent spend the entire OpenRouter balance, including auto top-ups.
- Keys made during onboarding have a $100 credit limit and expire after 180 days, which can break a long-running integration without warning.
- Management keys cannot call models, and API keys cannot call management endpoints; using one in place of the other fails.
- OpenRouter keys can be used in OAuth flows and set app credit limits, which OpenRouter says makes them more powerful than a single model provider's key.
Common OpenRouter authentication errors
401 - Invalid credentials (OAuth session expired, disabled/invalid API key)
The OpenRouter key is wrong, disabled or deleted, an OAuth session has expired, or a management key has passed its expiry.
402 - Your account or API key has insufficient credits
The account balance or the key's own credit limit has been used up.
403 - Forbidden (insufficient permissions, guardrail block, or moderation flag)
A guardrail, an organization budget or a moderation flag blocked the request before it reached a provider.
Using your OpenRouter key with AI agents
A coding agent that can read your .env file or your shell history can read the key, and anything in its context can end up in logs, transcripts or a prompt-injected request. The safer pattern is to keep the key in a credential broker that performs the authenticated step for the agent and hands back only the result.
BotPassword works this way. For a OpenRouter key, these intents fit:
| Intent | What BotPassword does |
|---|---|
run_with | Runs a command with the key injected as an environment variable or a 0600 temporary file, never on the command line, and redacts the key from the output. |
http_request | Makes an authenticated API call after checking the destination against the hosts this key may be sent to. The response comes back with credential-shaped values redacted, and one that holds the key itself is refused. |
Set it up in your agent: Aider · Amp · Claude Code · Claude Desktop · Cline · OpenAI Codex CLI · all agents
Frequently asked questions
Where do I get an OpenRouter API key?
Create one at openrouter.ai/keys. Give it a name and a credit limit, then copy it; OpenRouter recommends a limit on every key.
What is the OpenRouter API key environment variable?
OpenRouter's quickstart uses OPENROUTER_API_KEY in its Python, TypeScript and curl examples. With the OpenAI SDK, pass that value as the API key and set the base URL to https://openrouter.ai/api/v1.
How do I limit how much an OpenRouter key can spend?
Set a credit limit on the key when you create it or later on the key's page. The limit can reset daily, weekly or monthly, and requests are rejected with 402 once it is reached.
How do I give an AI coding agent an OpenRouter key safely?
Create a dedicated OpenRouter key for the agent with a small credit limit and a periodic reset, so a mistake or a leak is capped. Delete that key when the agent no longer needs it.
What happens if I commit my OpenRouter key to GitHub?
OpenRouter is a GitHub secret scanning partner, so a key pushed to a public repository can be detected and you receive an email. Delete the key and create a new one either way.
Can an AI agent use my OpenRouter key without seeing it?
Yes, if the key never enters the agent's context. Instead of pasting the key into a chat or leaving it in a .env file the agent can read, keep it in a credential broker that injects it into the command or request on the agent's behalf. BotPassword does this with run_with, http_request, so the agent gets the result and never the value.