Sources Last checked October 17, 2026 · Sources: official provider docs (linked below) · Educational, not an audit
The fix
If a tool you use reports a key exposure, or you're not sure where a key has been, don't wait for proof. Do these four things now, in this order:
- Create a replacement key and deploy it in your app.
- Revoke the old key once the new one works.
- Set a spend cap or alert so a leaked key can't run up an unlimited bill.
- Check usage for anything you don't recognize.
Below is how each provider documents those steps. Where we couldn't confirm an exact menu label, we say so.
OpenAI
- Revoke or rotate: OpenAI's advice for a compromised key is to delete it "through the API key dashboard," review your usage, and contact OpenAI Support (OpenAI Help). For planned rotation: create a replacement, update your apps, and revoke the old key "once you've verified that the replacement works" (OpenAI production best practices). OpenAI also says it disables keys it detects on the public internet (OpenAI Help).
- Spend caps and alerts: go to Project settings, select Limits, select Edit spend limit under Spend, enter the monthly amount, and turn on Enforce a hard limit (OpenAI spend limits). The same applies at organization level under Organization limits. Alerts alone "do not enforce a cap," and hard limits aren't instant, so spend "can slightly exceed" the amount (OpenAI spend limits).
- Usage per key: OpenAI supports "tracking usage by API key," and key usage shows on the Usage page once tracking is on. Keys created before Dec 20, 2023 don't have tracking on by default (OpenAI production best practices, OpenAI Help).
- Spotting unexpected charges: review usage for unexpected activity and keep the details for Support (OpenAI Help). Separate keys per feature or project make odd usage easier to pin down (OpenAI Help).
Anthropic
Google: Gemini API (AI Studio)
- Revoke or rotate: Google's leak checklist: generate a new key, deploy it, then "Disable the leaked key" once the new key works, and audit usage (Gemini API keys). Keys created in Google Cloud can also be rotated from the console's Credentials page with Rotate key (Google Cloud: API keys).
- Spend caps and alerts: project spend caps are set in AI Studio "on the Spend page under Monthly spend cap > Edit spend cap." The feature is experimental, and the docs warn of overages during a roughly 10-minute delay (Gemini API billing). Billing account tiers also have monthly caps (Gemini API billing).
- Usage per key: we didn't find per-key usage in the docs we checked. Google says API keys "have no independent billing settings" and usage from all keys in a project counts toward that project's spend cap (Gemini API billing). Check project-level usage in AI Studio under Dashboard > Usage (Gemini API billing). If you're not sure which key was exposed, rotate every key in that project.
- Spotting unexpected charges: "Check billing logs and API usage" in the Google Cloud console, and set billing alerts (Gemini API keys). In Cloud Billing Reports, group by SKU and filter to the Gemini API (Gemini API billing).
Google's docs now call Vertex AI "Gemini Enterprise Agent Platform (formerly Vertex AI)" (Cloud Billing spend caps).
- Revoke or rotate: Google recommends API keys for testing and application default credentials for production (Agent Platform: API keys). For Google Cloud API keys, use Rotate key on the Credentials page, then delete the old key. Deleted keys can be restored within 30 days (Google Cloud: API keys). For service account keys, disabling a key doesn't revoke short-lived credentials already issued from it (Disable service account keys).
- Spend caps and alerts: Cloud Billing spend cap budgets support the Agent Platform service. In Budgets & alerts, choose Create new budget, then Spend cap enforcement, then one project and one service, and set the target amount. Usage pauses once the cap is reached, but enforcement "isn't instant" (Cloud Billing spend caps). Ordinary alerts-only budgets don't cap spending (Cloud Billing budgets).
- Usage per key: we didn't find per-key usage or cost in the docs we checked. The closest equivalent is Cloud Billing reports grouped by project, service or SKU (Cloud Billing reports).
- Spotting unexpected charges: spend cap budgets send alerts at 50%, 80% and 100% (Cloud Billing spend caps). Actual costs can take more than 24 hours to appear in reports (Cloud Billing spend caps).
Keep provider keys server-side
Most leaks in AI-built apps come from the same place: a key in code that runs in the browser. OpenAI says not to embed keys "directly in an application" (OpenAI Help). Google's docs warn that client-side apps "risk exposing API keys" (Agent Platform: API keys).
- Call AI providers from a server route or server function, never from the browser.
- Never put provider keys in frontend env vars such as
NEXT_PUBLIC_ or VITE_. Build tools copy those values into the bundle.
- Use one key per app and environment so a leak is easy to trace and rotate.
Our quick check shows how to search your build output: how to check if a secret key is in your frontend bundle.
Related: is the Supabase publishable key safe in the frontend? (why some keys are meant to be public and AI provider keys never are) · secrets and IAM when your AI-built app runs in your own cloud
Your turn
If you've had to rotate a key in a hurry, what slowed you down most: finding where the key was used, or finding the right setting? Tell us. We'll add the common sticking points to this guide.
This guide is educational and based on the vendor's public docs as of the review date. Platforms change: check the linked sources. Not a security audit. Disclaimer.