API key leaks cost real money
A leaked AI API key can cost you thousands of dollars in minutes. Bots scan GitHub constantly for exposed keys. Here's how to protect yours.
Rule 1: Never hardcode keys
# β NEVER do this
client = OpenAI(api_key="izzi-sk_live_abc123...")
# β
Always use environment variables
import os
client = OpenAI(api_key=os.environ["IZZI_API_KEY"])Rule 2: Use .env files locally
# .env (add to .gitignore!)
IZZI_API_KEY=izzi-YOUR_KEY
IZZI_BASE_URL=https://api.izziapi.com/v1# Python
from dotenv import load_dotenv
load_dotenv()
# Node.js
import 'dotenv/config';Critical: Add .env to .gitignore immediately:
echo ".env" >> .gitignoreRule 3: Use secret managers in production
| Platform | Secret manager | How to access |
|---|---|---|
| AWS | Secrets Manager | SDK / IAM role |
| Vercel | Environment Variables | Dashboard β Settings |
| Cloudflare | Workers Secrets | wrangler secret put |
| GitHub Actions | Repository Secrets | Settings β Secrets |
| Docker | Docker Secrets | docker secret create |
Rule 4: Rotate keys regularly
- Create a new API key in Izzi API Dashboard
- Update your environment/secret manager
- Verify the new key works
- Delete the old key
Recommended rotation schedule: every 90 days, or immediately if you suspect a leak.
Rule 5: Use multiple keys
Create separate keys for different environments:
- π
izzi-dev-...β Development (low limits) - π
izzi-staging-...β Staging - π
izzi-prod-...β Production
Rule 6: Monitor usage
Check your Izzi API dashboard regularly for:
- π Unexpected spikes in token usage
- π Requests from unknown IP addresses
- π Usage patterns that don't match your application
Emergency: Key leaked?
- Immediately delete the key in your dashboard
- Create a new key
- Update all deployments
- Check your usage logs for unauthorized usage
- Scan your git history:
git log -p | grep "izzi-"
Prevention checklist
- β
.envis in.gitignore - β No API keys in source code
- β Production uses secret manager
- β Keys rotate every 90 days
- β Separate keys per environment
- β Usage alerts configured
