Rotation Strategy
The safest rotation pattern is create-then-delete:- Create a new key with the same permissions as the old one
- Deploy the new key to your application
- Verify the new key is working
- Delete the old key
Step 1: Create a New Key
Use the Key Management API to create a replacement key:- cURL
- Python
- TypeScript
Step 2: Update Your Application
Update theAROUTER_API_KEY environment variable (or equivalent secret) in your deployment environment:
Step 3: Verify the New Key
Before deleting the old key, confirm the new key is working:- cURL
- Python
Step 4: Delete the Old Key
Once the new key is confirmed working, delete the old one using its key ID:- cURL
- Python
Automated Rotation
For high-security environments, automate rotation on a schedule using your CI/CD system or a secrets manager:GitHub Actions Example
Listing Active Keys
List all active keys to audit what’s in use:Best Practices
- Rotate on a schedule — Monthly rotation is a good baseline for most applications
- Rotate immediately after suspected compromise — Do not wait for the next scheduled rotation
- Use descriptive names — Include version or date in key names (
production-2025-04,production-v3) - Set spending limits — Always configure
spending_limiton production keys to cap exposure - Use separate keys per environment — Never share a key between production and staging
- Audit regularly — Review the key list monthly and delete any keys that are no longer in use
- Store keys in secrets managers — Use AWS Secrets Manager, HashiCorp Vault, or equivalent rather than
.envfiles in version control