Check Your API Keys in CI With a GitHub Action

2026-11-27·
DevOpsCI/CDTutorial

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
OptionWhat it does
--envCheck environment variables instead of a file
--only A,BOnly check these variable names
--jsonMachine-readable output
--strictAlso fail on provider errors and unrecognised keys
--quietOnly 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