In this categoryTroubleshooting ยท 27
- How to Fix an OpenAI 401 'Invalid API Key' ErrorStart
- How to Fix OpenAI 429 Rate Limit Errors With Backoff
- How to Fix Anthropic Claude API 401 Authentication Errors
- How to Fix Google Gemini 'API Key Not Valid' Errors
- How to Fix an API Key That Loads as Undefined
- How to Handle Anthropic 529 'Overloaded' Errors
- How to Fix Rate Limit Errors from an AI API
- How to Fix CORS Errors When Calling an AI API From the Browser
- How to Fix 'Model Not Found' and Deprecated Model Errors
- How to Rotate a Leaked API Key Without Downtime
- How to Fix SSL Certificate Errors When Calling AI APIs
- How to count tokens before sending a prompt to Claude
- How to Fix 'Context Length Exceeded' Token Limit Errors
- How to fix a context length exceeded error in the Claude API
- How to fix a Claude response that gets cut off mid-sentence
- How to reduce Claude hallucinations by grounding answers in your documents
- How to keep a long Claude conversation under the context limit
- How to stop Claude from calling tools when it should not
- How to handle a Claude Fable 5 refusal with a fallback model
- How to choose the right Claude model for cost and quality
- How to cut Claude API costs with prompt caching
- How to halve Claude costs for bulk jobs with the Batch API
- How to cap spend on a Claude agent with a task budget
- How to Debug an MCP Server That Will Not Connect
- How to Ask an Agent to Explain a Bug Before Fixing It
- How to Roll Back a Bad Deploy Quickly
- How to Fix Cursor Not Indexing Your Codebase
How to Rotate a Leaked API Key Without Downtime
Respond to a committed or exposed API key safely by rotating it and purging it from history.
If a key landed in a public repo, a screenshot, or a log, treat it as compromised immediately. Bots scan GitHub for keys within minutes and will run up charges. The goal is to revoke the old key, deploy a new one, and remove the key from your git history so it cannot be recovered.
- Access to the provider dashboard to create and revoke keys
- Your deploy platform or secret store
- git, and optionally the git filter-repo tool
Step 1: Create a replacement key first
To avoid downtime, generate the new key before you revoke the old one. Add the new key to your secret store and deploy it, so the moment you revoke the leaked key the app is already using the new one.
Step 2: Revoke the leaked key
Once the new key serves traffic, revoke the leaked one in the dashboard. From that moment the exposed key is dead even if it is still floating around in a cache or a fork.
Step 3: Purge the key from git history
Deleting the line in a new commit leaves the key visible in older commits. Rewrite history to remove it, then force push. Coordinate with collaborators because this changes commit hashes.
Step 4: Prevent the next leak
Add the secret file to .gitignore and install a pre-commit secret scanner so a key never gets committed again. Many teams add a CI check that fails the build if a key pattern appears.
.env
.env.local
*.pem
secrets/Result
By creating and deploying the new key first, the app never lost a request, the leaked key stopped working the instant it was revoked, and the rewritten history removed it from every commit. A pre-commit hook now blocks the mistake from happening again.
Watch related tutorials
12:47
18:33
15:21
15:22
1:02:14
18:05New guides in your inbox
Fresh step-by-step how-to guides as we publish them. One email a week, no more.