Getting the error ‘API Key Expired’ while testing your Stripe integration using the stripe cli? Here’s how to update the keys.

Stripe

Stripe is integrated into my apps for payments and subscription plans. I also use a concept of AI credits for my apps and so those need to be refreshed for each active subscription period.

I was adding some new functionality to ArchitectFWD Enterprise (check out ArchitectFWD Enterprise Platform - Software as a Service) and so to test the AI credits and Stripe subscriptions, I started up the stripe cli listener from the command line.

FATAL Error while authenticating with Stripe: Authorization failed, status=401, body={ “error”: { “code”: “api_key_expired”, “doc_url”: “https://stripe.com/docs/error-codes/api-key-expired”, “message”: “Expired API Key provided: rk_test_*********************************….”, “type”: “invalid_request_error” } }

The fix

Log back into the Stripe dashboard and enable test mode. I’ve not yet set up the new sandbox functionality but test mode still works so I continued to set the new API keys in test mode.

Go to API Keys in the Stripe dashboard and under the standard API Keys, rotate the keys Publishable Key and Secret Key.

Then also refresh the webhook key on the Stripe developer console in the dashboard.

Go back to the command line and type

stripe config –set test_mode_pub_key pk_test_XXXXXXXX

Then the other key

stripe config –set test_mode_api_key sk_test_XXXXXXXX

These keys you should have from having performed the key rotations.

Then try start up the CLI again

stripe listen –forward-to http://localhost:8000/stripe/webhook

You should see this

Ready! You are using Stripe API Version [2024-06-20]. Your webhook signing secret is XXXXX

Set your webhook signing secret in your app and give it a test. I just created a new subscription in test mode in the Stripe dashboard.

Start up the Stripe cli -

2025-10-23 21:11:32 –> setup_intent.created [evt

looking at my logs for testing I can see

local.INFO: [StripeWebHookListener] Stripe Event setup_intent.created Payload: {“id”:”evt_…”

Architect Forward (architectFWD™) Enterprise test subscription active after using stripe cli in test mode

Looking good.

Closing thoughts

The test keys seem to have a maximum expiry length of 7 days, so get to testing and ship that feature!

Quintes van Aswegen

Quintes van Aswegen

24+ years experience in solving business problems and maximising opportunities through technology in a variety of industries, public and private sector internationally. I founded architectFWD™ to provide knowledge and trusted advice in the areas of strategy, technology, cloud and digital to enable organisations to become Digital Leaders.