IzziAPI
TipsApr 4, 20267 min read

How to Secure Your AI API Keys in Production

Environment variables, secret managers, key rotation, and scope limiting to protect your API credentials.

Izzi API Team
Engineering & DevRel
securityapi-keysproductionbest-practices
How to Secure Your AI API Keys in Production

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

Text
# ❌ 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

Text
# .env (add to .gitignore!)
IZZI_API_KEY=izzi-YOUR_KEY
IZZI_BASE_URL=https://api.izziapi.com/v1
Text
# Python
from dotenv import load_dotenv
load_dotenv()

# Node.js
import 'dotenv/config';

Critical: Add .env to .gitignore immediately:

Bash
echo ".env" >> .gitignore

Rule 3: Use secret managers in production

PlatformSecret managerHow to access
AWSSecrets ManagerSDK / IAM role
VercelEnvironment VariablesDashboard β†’ Settings
CloudflareWorkers Secretswrangler secret put
GitHub ActionsRepository SecretsSettings β†’ Secrets
DockerDocker Secretsdocker secret create

Rule 4: Rotate keys regularly

  1. Create a new API key in Izzi API Dashboard
  2. Update your environment/secret manager
  3. Verify the new key works
  4. 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?

  1. Immediately delete the key in your dashboard
  2. Create a new key
  3. Update all deployments
  4. Check your usage logs for unauthorized usage
  5. Scan your git history: git log -p | grep "izzi-"

Prevention checklist

  • ☐ .env is in .gitignore
  • ☐ No API keys in source code
  • ☐ Production uses secret manager
  • ☐ Keys rotate every 90 days
  • ☐ Separate keys per environment
  • ☐ Usage alerts configured

Ready to start building?

Access 38+ AI models through a single API. Free tier available β€” no credit card required.

MORE

Related articles