What to do if your OpenRouter API key leaked
An OpenRouter key spends your prepaid credits and, unless a guardrail restricts it, can call any model OpenRouter offers, so a leaked one can burn through a balance (and any auto top-ups) quickly. Here’s the order that matches OpenRouter’s own docs, plus what the short answers leave out: reading the key’s usage before you turn it off, disable versus delete, management keys, and how to check the rest of your keys.
Last reviewed 20 Nov 2026
The short version
- Optional, 30 seconds: read what the key has spent with
GET /api/v1/keywhile it still works. - Turn the key off. OpenRouter’s authentication docs say to delete it on the API keys page and create a new one. Security settings → Key safety can also Disable (reversible) or Archive (permanent).
- Create a replacement with a credit limit and an expiration (you can’t add an expiration later), store it server-side only, redeploy.
- Open Activity, group by API key, look at the exposure window, and export it as CSV before you delete anything.
- If the leaked secret was a management key, assume your other keys were touched: list them all, including disabled ones.
KeyBark checks your OpenAI, Anthropic or OpenRouter spend about every 15 minutes during the beta and emails you when it crosses a daily or monthly threshold you set, or jumps above its 7-day average. It doesn't set or enforce limits for you. Free for one key, no card.
1. Optional: read the key’s usage first
Every OpenRouter API key can describe itself. Before you turn it off, one call shows what it has spent (in USD credits) and whether it has a cap left. Railway’s OpenRouter incident guide suggests the same step. Don’t paste the key into a chat or ticket to do this; run it in a terminal.
curl https://openrouter.ai/api/v1/key \
-H "Authorization: Bearer $EXPOSED_OPENROUTER_KEY"The response includes usage, usage_daily, usage_weekly, usage_monthly, limit, limit_remaining, limit_reset and expires_at. A usage_daily far above your normal day is your first sign of abuse. If you see abuse, skip ahead and turn the key off now; this step is a nice-to-have, not a reason to wait.
2. Turn the key off
| Action | Where | Undo? | Notes |
|---|---|---|---|
| Delete | API keys page, or DELETE /api/v1/keys/{hash} with a management key | No | What OpenRouter’s authentication docs tell you to do after a compromise. |
| Disable | Security settings → Key safety, or PATCH /api/v1/keys/{hash} with {"disabled": true} | Yes | Disabled keys drop out of the Key safety list; the API lists them with include_disabled=true. |
| Archive | Security settings → Key safety (type archive to confirm) | No | Permanent, like delete. |
After any of the three, requests with that key get 401 with Invalid API key or User not found. (per the 401 troubleshooting table). Anything still using the key breaks until you deploy the replacement, so if you see no abuse and need to avoid downtime, you can create and deploy the new key first and then turn the old one off. Don’t leave a key you believe is exposed active “for a bit”.
Disable or delete? Disabling is reversible and, per Railway’s guide, keeps the key’s history for review, while deleting removes the key’s usage fields with it. That’s Railway’s report, not OpenRouter’s documentation, but it’s a reasonable order: disable now, export Activity, then delete or archive.
Turning off by API, with a management key (the hash comes from the keys list or from the key’s page):
curl -X PATCH https://openrouter.ai/api/v1/keys/$KEY_HASH \
-H "Authorization: Bearer $OPENROUTER_MANAGEMENT_KEY" \
-H "Content-Type: application/json" \
-d '{"disabled": true}'A Read only management key gets 403 on that call; it needs a read/write key. If your management key is workspace-scoped, it can only touch keys in its own workspace.
3. Deploy a capped, expiring replacement
- Credit limit. OpenRouter recommends a limit on every key: a key with no limit lets a leaked key or a runaway agent spend your whole balance, including auto top-ups. Pick a daily, weekly or monthly reset if you want one; once the limit is used, requests with that key are rejected until it resets or you raise it. Details in our OpenRouter key limits guide.
- Expiration. You can’t change the expiration of an existing key, so set it now (the create-key API takes
expires_at). An expired key gets401 API key expired, so put a calendar reminder before that date. - One key per app and environment. Then the next leak only takes out one thing, and Activity tells you which one.
- Server-side only. Keep it in a secrets manager or a server environment variable such as
OPENROUTER_API_KEY. Anything bundled into a browser or mobile app is public, includingNEXT_PUBLIC_andVITE_variables. - Redeploy everywhere it was stored: production, preview environments, CI secrets, local
.envfiles, agents and scripts. Then confirm the old key is no longer used (step 4).
OpenRouter’s key rotation recipe shows the same create → switch → remove sequence with the management API, if you’d rather script it.
4. Review what the key spent
- Open Activity. It shows Spend, Tokens and Requests, filtered by 1 hour, 1 day, 1 month or 1 year, and can be grouped by model, API key or creator (docs).
- Group by API key and look at the leaked key across the exposure window. Spend on models you never use is the usual giveaway.
- Export it: options menu → Export to… → CSV or PDF. Click into a metric (e.g. Spend) first for a per-key breakdown. Do this before deleting the key.
- Watch the leaked key’s line for a while after you turned it off. It should stay flat; new spend means something else is still using a key you missed.
- Check Credits for purchases you didn’t make and, in an organization, the members list for people you didn’t invite (Railway’s checklist includes both).
For a scripted view, see our OpenRouter usage per API key guide (keys list, Analytics API and /api/v1/activity, and why their totals differ).
5. If it was a management key, check every key
Management keys use the same sk-or-v1- format as API keys, so you can’t tell them apart from the string. OpenRouter’s docs say a leaked management key could create, edit and delete the API keys in your account (other than those provisioned by a Connect client). Management keys can’t call completion endpoints themselves, but they can mint keys that can.
- Delete it on the Management API Keys page and create a new one with an expiration (and a Read only access level if the job only reads).
- List every API key in every workspace with
GET /api/v1/keys?include_disabled=true(100 per page; passoffset; once perworkspace_id), and look for keys you don’t recognize, recentcreated_atvalues, raised limits or re-enabled keys. OpenRouter’s API key audit recipe has a ready script. - That endpoint doesn’t return management keys or OAuth keys: review those on Security settings (select “Show management keys” on the Key safety tab).
6. Clean up the leak site and tell OpenRouter
- Removing the key from code does not un-leak it. Git history, forks, CI logs, error trackers, screenshots and pasted chats can keep it. Clean what you can, but rely on step 2, not on deletion from the repo.
- Rotate any other secrets that sat in the same file, commit or environment.
- OpenRouter’s Terms ask you to promptly notify them of any actual or suspected compromise, and make you responsible for charges under your credentials unless OpenRouter breached the Terms. If you see usage you didn’t make, send support the key name, times and your Activity export.
What OpenRouter catches for you, and what it doesn’t
- GitHub secret scanning. OpenRouter is a GitHub secret scanning partner: GitHub reports OpenRouter keys found in public repositories and public npm packages to OpenRouter, and OpenRouter emails you if it determines a key was compromised. Its docs don’t say it disables the key for you.
- Push protection. Since June 2026, GitHub blocks pushes containing
openrouter_api_keyby default in repositories with secret scanning enabled. That stops one common leak path; it doesn’t cover bundles, logs, chats or other git hosts. - Maximum key lifetime. In privacy settings you can set a maximum API key lifetime; OpenRouter then rejects requests from keys that never expire or exceed it, including existing keys (Security settings docs). Check what still uses old keys before you turn it on.
- IP allowlist. Enterprise plan only; rejects API requests from other addresses with
403, which limits what a leaked key can do from someone else’s machine. - Not covered in the docs we read: an alert when one key’s spend looks unusual. The credit limit is the cap; Activity is where you look.
Checklist
- □ (Optional)
GET /api/v1/keywith the exposed key, noteusage_daily - □ Disable, archive or delete the key
- □ New key with a credit limit and an expiration, server-side only, deployed everywhere
- □ Activity grouped by API key for the exposure window, exported to CSV
- □ Old key’s line stays flat after the switch
- □ Management key leaked? List all keys with
include_disabled=true, check management and OAuth keys on Security settings - □ Other secrets from the same place rotated; OpenRouter support told if there’s usage you didn’t make
- □ Security settings: no keys left with “No limit” or “No expiry” that you can’t explain
Prefer a provider-by-provider plan? Use the free leaked key response plan. Not sure whether your OpenRouter (and OpenAI / Anthropic) limits would actually stop a leaked key? The free AI key limit audit checks them in a few minutes (no sign-up, no key needed). Related: OpenAI API key leaked, Anthropic API key leaked, OpenRouter 402 insufficient credits, read-only admin key for cost tools.
Where KeyBark fits (and where it doesn't)
KeyBark reads a connected OpenRouter key’s usage from our servers about every 15 minutes during the beta (through /api/v1/key, or /api/v1/keys/{hash} with a management key) and emails you when a daily or monthly dollar threshold you set is crossed, or when today’s spend jumps above its 7-day average. About once a day it also searches public GitHub code for the key you connected (sending GitHub only a short fragment, never the whole key) and emails you a checklist if it appears. On paid plans an opt-in kill switch (beta) can disable a key you name through OpenRouter’s API when a threshold is crossed, not when a leak alert fires.
Limits, honestly: KeyBark doesn’t revoke or rotate keys for you, doesn’t scan private repositories, git history, bundles, logs or chats, and doesn’t set OpenRouter limits. It watches the keys you connect (the free plan covers one key), counts OpenRouter credit usage rather than BYOK, and checks on a schedule, so an alert can arrive after money has been spent. It isn’t a proxy and can’t block a request. Turn the leaked key off in OpenRouter first and give its replacement a credit limit; KeyBark is a second line of warning on top.
FAQ
What should I do if my OpenRouter API key leaked?
Turn the key off first. OpenRouter's authentication docs say to delete the compromised key on your API keys page and create a new one. The Security settings page also lets you disable a key (reversible) or archive it (permanent). Then put a replacement with a credit limit and an expiration into a server-only secret, redeploy, and review the Activity page grouped by API key for the exposure window.
Should I disable or delete a leaked OpenRouter key?
Either stops the key: OpenRouter answers a deleted or disabled key with 401 “Invalid API key” or “User not found.” Disabling is reversible, archiving and deleting are not. Railway's incident guide (Oct 2026) suggests disabling first and deleting only after you have reviewed usage and exported Activity, because a deleted key's usage fields go with it. That last point is Railway's report, not OpenRouter's documentation.
Does OpenRouter automatically detect leaked keys?
Partly. OpenRouter says it is a GitHub secret scanning partner and has other ways to detect exposed keys, and that it emails you if it determines a key was compromised. GitHub reports partner secrets found in public repositories and public npm packages. The docs don't say OpenRouter turns the key off for you, and leaks in private repos, logs, chats, frontend bundles or screenshots may never be reported. Don't wait for the email.
Who pays for usage from a stolen OpenRouter key?
By default, you. OpenRouter's Terms (read 20 Nov 2026) say you are responsible for all activity and charges under your account or API credentials, whether or not authorized by you, except to the extent caused directly by OpenRouter's breach of the Terms, and that you agree to promptly notify OpenRouter of any actual or suspected compromise. Contact OpenRouter support with your Activity export; we found no published process for credits spent by a stolen key.
Sources (read 20 Nov 2026): OpenRouter authentication, security settings, management API keys, get current API key, update an API key, create an API key, API key audit, Activity export, Terms; GitHub secret scanning for partners and June 2026 changelog; Railway’s unexpected-OpenRouter-usage note. KeyBark is not affiliated with OpenRouter.
KeyBark watches your OpenAI, Anthropic and OpenRouter spend from the server and flags a crossed threshold or spike by email and on your dashboard. Free for one key.