Check Your API Keys in CI With a GitHub Action
Catch Dead Keys Before You Deploy
A deploy with a revoked key looks like a successful deploy until the first request fails. Checking your keys in CI turns that into a failed build with a clear message instead.
Api Key Chain's open-source command-line tool and GitHub Action do exactly that. They use the same provider list as the website and send each key only to its own provider. Full keys are never printed.
The GitHub Action
Pass the secrets you want to check as environment variables and list their names:
- uses: actions/checkout@v4
- uses: UsmanSanawar/Api-Key-Chain@v1
with:
env-names: OPENAI_API_KEY,STRIPE_SECRET_KEY
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
STRIPE_SECRET_KEY: ${{ secrets.STRIPE_SECRET_KEY }}
To check a file instead, use file: .env.ci. Add strict: 'true' if provider outages and unrecognised keys should also fail the build.
The Command-Line Tool
From a clone of the GitHub repository:
npm run build:cli
node bin/apikeychain.mjs .env
node bin/apikeychain.mjs --env --only OPENAI_API_KEY,STRIPE_SECRET_KEY
| Option | What it does |
|---|---|
--env | Check environment variables instead of a file |
--only A,B | Only check these variable names |
--json | Machine-readable output |
--strict | Also fail on provider errors and unrecognised keys |
--quiet | Only print problems |
Exit codes: 0 when every key is valid, 1 when a key is invalid, 2 for a usage or file error.
Prefer a Browser?
Paste a whole .env file into the .env checker to test every key in it at once.
💻 Tip: CI checks run when you deploy. To hear about a key that dies between deploys, watch it and get an email.
Related Posts
Get an Email When Your API Key Stops Working
API keys get revoked, expire or run out of credit without warning. Here is how to watch a key and get an email when it fails, and again when it works.
How to Check If Your OpenAI API Key Is Still Valid
Learn how to quickly verify if your OpenAI API key is still active, what different error codes mean, and how to avoid common pitfalls.
How to Test a Stripe API Key (Without Making a Real Charge)
Learn how to safely verify your Stripe secret key is valid — without creating test charges, customers, or risking your live account.