rotate-api-keys
Original:🇺🇸 English
Translated
Replace old API keys with new ones across multiple configuration files, keystores, and logs. Use this skill when the user asks to rotate, replace, update, or refresh API keys across their system. Supports .env files, JSON keystores, and log files. Automatically creates backups before making changes.
4installs
Sourcedalehurley/phpbot
Added on
NPX Install
npx skill4agent add dalehurley/phpbot rotate-api-keysTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Rotate API Keys
Input Parameters
| Parameter | Required | Description | Example |
|---|---|---|---|
| Yes | The API key to be replaced (the old or compromised key) | sk-old-abc123 |
| Yes | The new API key to replace the old one with | sk-new-xyz789 |
| No | Directories to search for .env files and keystores (defaults to home directory and common project paths) | ~/Herd ~/Code |
Procedure
-
Ask for the old and new API keys if not provided
-
Identify all target files — .env files, keystore files (), and logs containing credentials:
keys.jsonbashfind {{SEARCH_PATH}} -name "*.env" -o -name "keys.json" -o -name "*.log" -
Create backups and replace the key in each file:bash
sed -i.bak "s|{{OLD_KEY}}|{{NEW_KEY}}|g" {{FILE_PATH}} -
Verify the replacement in a sample of updated files:bash
grep -o "sk-[a-zA-Z0-9-]*" {{FILE_PATH}} | head -1 -
Report a summary of all updated files, backup locations, and verification results
Notes
- Backups are created automatically using the flag before any changes
-i.bak - Verify replacements before confirming completion
- Revoke the old key in the API provider's dashboard after rotation
- Large log files may take time to process
Example
rotate my API key across all my projects and config files
replace my old OpenAI key with a new one in all .env files
update this API key everywhere it appears on my system
rotate my compromised API key across all config files and keystores
refresh my API credentials across my development environment