Leaked AI API key: what to do first
Last updated
If an API key for an AI provider has leaked, or your bill shows charges you didn't make, turn the key off first. Then save the usage records and report it to the provider. This page has the steps for Gemini, OpenAI, Anthropic and OpenRouter, and what each provider's own pages say about the charges.
Each provider's part of this page was checked against that provider's own pages on November 13, 2026, and the GitHub parts against GitHub's docs. One third-party report and our own suggestions are marked as such. The sources are linked under the sections they back up. None of those pages promises a refund, and nothing here is legal advice.
The short version
Do these three things in the first ten minutes, in this order.
- Turn the key off at the provider. The steps for each provider are below: Gemini, OpenAI, Anthropic, OpenRouter. They delete the key at Google, OpenAI and Anthropic, and disable it at OpenRouter. Each section also says what that provider's pages say about disabling versus deleting. The pages: Google Cloud Credentials, OpenAI API keys, Claude Console API keys, OpenRouter Security settings.
- Save what the key did. Export the usage for the days in question. Write down the key's name and the times.
- Report it to the provider, with those details. Then create a new key, set a spending limit, and put the new key in your app.
- Deleting the commit is not enough. Taking the key out of your code, or deleting the commit, does not turn it off. GitHub's guide to removing sensitive data says that for a secret, “as a first step you need to revoke and/or rotate that secret”.
- Your own app stops too. Once the key is off, everything that uses it fails until the new key is in place.
- The providers don't agree on the order. For a leaked key, Anthropic, OpenAI and OpenRouter say to revoke or delete it right away. Google's checklist creates the new key first and turns the old one off once the new one works, to avoid downtime. With that order, the leaked key keeps working until the last step.
- If the key was taken from a host, for example from its environment variables, treat every other key stored there as leaked too. That is our suggestion. The provider pages don't cover it.
Source: GitHub, Removing sensitive data from a repository. The providers' pages are linked under each section below.
Gemini (Google)
Turn the key off
Google's Gemini checklist is: create a new key (in AI Studio or the Cloud console), update your app, then disable or delete the leaked key in the Cloud console. The checklist doesn't give the clicks. Google's Gemini docs give click-by-click steps for deleting a key on another page, written for a key you no longer need. Steps 3 to 5 below are those steps:
- Create a new key on the AI Studio API keys page.
- Update your app to use the new key.
- In the Cloud console, open the Credentials page.
- Find the leaked key and click the Actions icon.
- Select Delete API key. In the Delete credential dialog, select Delete.
- Deleting takes a few minutes. Google says: “Deleting an API key takes a few minutes to propagate. After propagation completes, any traffic using the deleted API key is rejected.”
- If charges are arriving now, you can delete the leaked key (steps 3 to 5) before you update your app (step 2). The leaked key then stops working sooner, for everyone who has it. Your own app stops too, until it has the new key. Google's Gemini checklist says the opposite: “Do not delete the old key until the new key is fully active to avoid application downtime.” Google Cloud's page on compromised credentials says “you must take immediate action to limit the impact of the compromise”. Deleting first is our suggestion, not Google's order.
- A key you deleted by mistake can be restored. Google Cloud says you can restore a deleted key within 30 days: on the Credentials page, click Restore deleted credentials.
- Disable or delete? Google's Gemini checklist calls its third step “Disable or delete the compromised key”. The Cloud pages we read describe deleting an API key, not disabling one. Google's AI Studio docs list deleting API keys as something AI Studio can do (it needs the
apikeys.keys.deletepermission), but give no steps for it. - Rotate key. Google Cloud's general steps for any API key use a Rotate key button: on the Credentials page, click the key's name, click Rotate key and create the new key. After you update your app, click Delete the previous key on the new key's page. Google's Gemini pages don't mention Rotate key. They say that creating a Gemini API key in the Cloud console requires binding it to a service account. The Cloud steps say the new key gets the same restrictions. They don't say it keeps that binding.
- Google may have blocked the key already. Google says it blocks keys it knows are leaked from the Gemini API. Requests with such a key can fail with
403 PERMISSION_DENIED. Google says you may see this message:Your API key was reported as leaked. Please use another API key.Google says AI Studio shows which of your keys are blocked. - Check other Google services too. Google says a key without API restrictions can be used with all APIs that accept keys generated by Google Cloud. Keys created in AI Studio since May 28, 2026 are authorization keys, which Google says are restricted to the Gemini API by default.
- If you prepay, cap auto-reload. Auto-reload tops up your credit balance when it runs low. To cap what it can buy in a month, open the AI Studio Billing page, click Manage auto-reload, expand Monthly Limit, enter a limit and click Save.
See what it spent
- In AI Studio, open Dashboard → Usage. Requests that AI Studio can't match to a named key are grouped under (unknown keys). Google says that includes keys without a display name and keys deleted more than 30 days ago.
- In the Cloud console, open Billing → Reports. It groups by service for the current month. To see only Gemini, set Services to Gemini API and Group by to SKU.
- Keep one key in the project. Google says: “If all API keys in a project are deleted (for example, if a leaked key was deleted), you will lose visibility of the project's logs until an API key is available.” To keep the AI Studio Logs page readable, create the new key in the same project before you delete the leaked one, or right after.
- The first number may not be the full amount. Google says cost details usually arrive within a day but can take more than 24 hours, and that the cost graphs in AI Studio can take up to 24 hours to update.
What Google's pages say about the charges
- Keys Google blocked itself. The Gemini troubleshooting page has a section on keys Google blocked after it “identified a vulnerability where some API keys may have been publicly exposed”. Under “Unexpected charges due to vulnerability” it says: Submit a billing support case. It adds: “Our billing team is working on this, and we will communicate updates as soon as possible.”
- For a compromised account, Google's Cloud Billing page says to follow its steps for compromised credentials, which include rotating API keys. It also says to “contact Cloud Billing Cloud Customer Care to report the compromise and discuss potential billing adjustments. Google Cloud reviews such cases on an individual basis.”
- The same page says: “Any usage that occurred before the account suspension or compromise, up to the point of effective resource termination, will be billed.”
- How to reach billing support: in the Cloud console, open Help and support, select Billing, then click Get billing support. Google says billing support is free for all accounts, and that you must be a Billing Account Administrator to contact it. If you aren't one, the same page links a contact troubleshooter. One of the cases it lists is unknown charges that you are unable to stop.
- Prepaid credits: Google says “Refunds aren't allowed for Prepay billing accounts, except when switching account types.” Postpay accounts follow the Google Cloud refund policy.
- Disputes: the Cloud Billing page has a section called Dispute charges. It starts: “The process to dispute unauthorized charges depends on your country.”
Sources: Google AI Studio, Using Gemini API keys, Troubleshooting guide, Gemini Developer API vs. Gemini platform, Troubleshoot Google AI Studio, Logs and datasets, Billing; Google Cloud, Respond to compromised Google Cloud credentials, Manage API keys, Creating and managing API keys, Resolve Cloud Billing issues, Get Cloud Billing support
OpenAI
Turn the key off
- Open the API keys page.
- Click the trash can icon next to the leaked key.
- OpenAI says deleted keys cannot be used, so apps that rely on the key may stop working. The OpenAI pages we read describe deleting a key, not disabling one.
- OpenAI may have disabled the key already. It says: “When OpenAI detects an API key on the public internet, or leaked inside an app in an app store, the API key is disabled immediately.”
- If someone may have signed in to your account, OpenAI's steps are: change your password, log out of all sessions, delete your API keys, review your usage and your security history, and contact Support.
- Auto recharge keeps buying credits. On prepaid billing, it adds credits when your balance falls below your threshold. OpenAI says of the Use auto-reload setting: “It is turned on by default during setup.” OpenAI's article on prepaid billing links your organization's API billing overview for setting up prepaid billing, buying credits and checking your balance. It doesn't say where to turn auto recharge off after setup. The optional monthly recharge limit caps those purchases. OpenAI says it is not an API usage limit. It also says usage can run past a zero balance and show up as a negative balance.
See what it spent
- Open the Usage dashboard, select the organization and choose the period. You need to be an organization owner or have the Usage Dashboard permission.
- The dashboard shows data in UTC. Usage detail pages go down to 1-minute intervals.
- OpenAI says usage per API key shows on the Usage page once tracking is on for the key. Keys created after December 20, 2023 have it on. Usage that wasn't tracked shows as
Untracked. - Export the usage. OpenAI says there is no limit on the export date range.
What OpenAI's pages say about the charges
- OpenAI gives three steps for an exposed key: delete it, review your usage and keep the details, contact Support.
- How to reach support: open a new chat on any Help Center page. OpenAI says: “Include details of activity you didn’t perform or authorize.” Another help page says to use the Fraudulent Activity webform and choose ‘Report unauthorized activity involving my account.’ The form is linked from that page.
- Prepaid credits: “Credits are non-refundable unless required by law or contract, or an approved exception applies.” About refunds for credits that were already used, the same article says: “Credits already used may qualify only for confirmed unauthorized use or a verified billing correction, subject to applicable law or contract.” To ask for a review, OpenAI says to contact Support.
- A card charge you don't recognize is a different case. OpenAI has a separate page for it.
Sources: OpenAI, Keeping your OpenAI account secure, Where do I find my OpenAI API Key?, Reviewing API usage and costs, Production best practices, Setting up and managing prepaid API billing, How can I report fraud or suspicious activity?
Anthropic (Claude)
Turn the key off
- In the Claude Console, open the API keys page.
- Click the menu (the three dots) next to the leaked key.
- Select Delete API key.
- Disable or delete? Anthropic's docs say that on the API keys page, Disable is reversible and Delete is permanent. Either one fits its advice to “disable or delete any key you suspect has leaked”. The Anthropic pages we read don't say whether the Usage page still lists a deleted key. If you need that key's usage records, disable it first, export the usage (see below), then delete it. That order is our suggestion.
- Anthropic may have turned the key off already. It says that when GitHub finds a Claude API key in a public repository, GitHub notifies Anthropic, and Anthropic deactivates the key automatically and emails you.
- Create the new key with the Create key button on the same page.
- Turn off auto-reload if it is on. Auto-reload buys more credits when your balance falls below a threshold you set. On the Billing page, click Manage auto-reload, then Turn off, and confirm with Turn off again.
See what it spent
- Open the Usage page and select the API key. You can click a bar in the chart to go down to the hour and the minute, and export the data as CSV.
- The Cost page shows spend by workspace, model and month, with a daily chart and a CSV export.
- The Usage and Cost pages are visible to the Developer, Billing and Admin roles.
- Anthropic also recommends reviewing the Logs page.
What Anthropic's pages say about the charges
- The help article on a compromised key says to revoke the key immediately, and then: “If you continue to see any suspicious API activity or have other concerns, please contact our Support team.”
- How to reach support: in the Console, click your initials or name in the lower left corner and select Get help. You start with an AI support bot. Anthropic says Console Admins can get further help from its Product Support team, and that other members need an Admin to reach out for them.
- Anthropic's Commercial Terms say: “Customer is responsible for all activity under its account.” They also say the customer will promptly notify Anthropic if it believes its account has been compromised.
- The billing help article says: “All credit purchases are non-refundable.”
- The Anthropic pages we read don't describe a process for reviewing usage from a stolen key. Ask Support.
Sources: Anthropic, What should I do if I suspect my API key has been compromised?, API key best practices, Authentication, Cost and usage reporting in the Claude Console, How to get support, How do I pay for my Claude API usage?, Commercial Terms of Service
OpenRouter
Turn the key off
OpenRouter's Authentication page says to delete the compromised key and create a new one. We put Disable first, for two reasons. Another OpenRouter page says: “Disabling is reversible; deleting is not.” And Railway, a hosting company, wrote in a guide dated October 22, 2026 that when you delete a key, “the key's usage fields disappear with it”. It told its users to disable the key and to export the usage “before you delete anything”. That is Railway's report, not OpenRouter's documentation.
- Open Settings → Security and select the Key safety tab.
- On the leaked key's row, click Disable.
- Open Settings → API Keys and create a new key.
- Disable, archive or delete? OpenRouter says disabling a key is reversible and archiving is permanent. Archive is on the same row as Disable. To delete the key instead, use Settings → API Keys, as the Authentication page says. The docs we read don't say what records a deleted key keeps.
- OpenRouter says requests with a deleted or disabled key get
401withInvalid API keyorUser not found. - OpenRouter may email you first. It says it is a GitHub secret scanning partner and has other ways to detect exposed keys, and that you get an email if it determines your key is compromised. The page doesn't say it turns the key off for you.
- Give the new key a credit limit. OpenRouter warns that if a key has no limit and it leaks, it can spend your whole balance, including any auto top-ups. OpenRouter's docs don't say where to turn auto top-up off. How to set a credit limit.
- If it was a management key, check your list of keys too. OpenRouter says a leaked management key could create, edit and delete API keys in your account. On the Key safety tab, management keys are hidden unless you select Show management keys.
See what it spent
- Open Activity. In the Explore tab, set the metric to spend and group by API key.
- Export the result as CSV or PDF. The export keeps your filters and date range.
- From most cards you can click View logs to see individual generations.
What OpenRouter's pages say about the charges
- OpenRouter's Terms say: “You are responsible for all activity and charges under its account or API Credentials, whether or not authorized by you, except to the extent caused directly by OpenRouter's breach of these Terms.” They also say you agree to promptly notify OpenRouter of any actual or suspected compromise.
- How to reach support: for billing and account questions, OpenRouter gives support@openrouter.ai. Its support page also lets you raise a ticket.
- Refunds: the FAQ covers unused credits only: “Refunds for unused Credits may be requested within twenty-four (24) hours from the time the transaction was processed.”
- The OpenRouter pages we read don't describe a process for credits that a stolen key spent. Ask support.
Sources: OpenRouter, Authentication, Security settings, API Key Audit, Management API Keys, Activity, FAQ, Terms of Service; Railway, Check for Unexpected OpenRouter Usage (October 22, 2026)
Limit the damage before it happens
These are measures the providers document themselves. None of them keeps a key from leaking. They limit what a leaked key can do.
- Set a spending limit at each provider. One guide for each: Gemini, OpenAI, Anthropic and OpenRouter. OpenAI says a hard spend limit helps “limit unexpected costs from a leaked key”, and that spend alerts alone don't stop API traffic. OpenRouter recommends a credit limit on every key. Each guide also shows how to stop your code from retrying a limit.
- Restrict where the key works. Google lets you restrict a key to certain APIs and to certain IP addresses, websites or apps. OpenAI has an IP allowlist for every API customer, for a project or the whole organization. It says the allowlist doesn't prevent all misuse. Anthropic has IP allowlisting in beta. OpenRouter's IP allowlist needs an Enterprise plan.
- Give keys an end date. OpenAI project keys, Anthropic keys and OpenRouter keys can be created with an expiration. Anthropic says expiration “limits the lifetime of a leaked credential, but it is not a substitute for secret hygiene”.
- Cap or turn off automatic top-ups. A balance that refills itself is not a limit. What each provider documents is in its section above.
- Use one key per app. Anthropic says separate keys let you “quickly disable just that use case” when one is compromised. OpenAI says separate keys make usage easier to track.
- Keep keys out of your repository. All four providers say this. Google and OpenAI also say never to put a key in client-side code, and to send requests through your own backend server instead.
- Don't count on secret scanning. GitHub scans public repositories and tells the providers in its partner program about the keys it finds. Its list says it does this for Anthropic, OpenAI and OpenRouter API keys and for Google API keys. A separate “Google Gemini API Key” row is not marked that way. What each provider then does is in its section above. None of these pages says a provider can see a key taken from a private place, such as a host's environment variables.
Sources: GitHub, Supported secret scanning patterns, Secret scanning partner program; OpenAI, Best practices for API key safety, IP allowlisting for OpenAI API; Anthropic, IP allowlisting; Google Cloud, Best practices for managing API keys. The other pages are linked under the provider sections above.
Where Billfuse fits
If a key of yours is being used right now, do the steps above first: turning the key off at the provider is what stops it. Billfuse is the tool we built to notice unusual spend sooner next time. It doesn't replace the providers' limits. Keep them on.
- Spike alerts, with no budget needed. When one provider's day reaches 3 times a normal day, and at least $10 more, you get an email, and a Slack message if you added one. Billfuse checks once an hour. For OpenAI and Anthropic, the alert comes the same day only if the provider has already reported the spend.
- Budget alerts. Billfuse emails you at 50%, 80% and 100% of one monthly budget across your providers.
- Pausing OpenAI and Anthropic, if you turn it on. Automatic pausing is off by default. It fires when a budget reaches 100%, not on a spike alert. You can also pause by hand: in Billfuse's settings, under Pause spending, click Pause now. For OpenAI, Billfuse sets each active project's spend limit to $0.01. For Anthropic, it switches off each active API key. It isn't instant: automatic pausing happens at the hourly check, and OpenAI says its limit isn't enforced instantly either.
- A pause is not a fix. The leaked key still exists. Delete it at the provider before you click Resume spending.
- Gemini and OpenRouter: it would not have stopped a thief. Billfuse can't pause them. Their spend reaches Billfuse about a day late, so the alert is about a day late too. Their own limits act much sooner.
- It reads spend, not balances. Billfuse doesn't show a prepaid credit balance, so it won't tell you that one is running down.
- It is one more key to protect. To read your spend, Billfuse needs a key of its own for each provider: an admin key for OpenAI or Anthropic, a management key for OpenRouter, a service account key for Gemini. How Billfuse stores keys.
More guides
- How to put a hard spending cap on OpenAI, Anthropic, Gemini and OpenRouter
- How to set a hard spending limit on the OpenAI API
- How to set a spending limit on the Anthropic API
- How to set a spending limit on the Gemini API
- How to set a spending limit on the OpenRouter API
- Billing error or rate limit? AI API errors from OpenAI, Anthropic, Gemini and OpenRouter
- Fix "Your credit balance is too low to access the Anthropic API"
- Gemini API error 402: "Your prepayment credits are depleted"
- OpenAI error 429 insufficient_quota: "You exceeded your current quota"
- OpenRouter 402: "This request requires more credits, or fewer max_tokens"
It's free while Billfuse is in early access. You can try it with sample data first, no sign-up needed.