Guide
api_key_expired: Stripe says the API key has expired
How this guide was made: Written with AI assistance and checked against the sources linked on this page.
Updated
Short answer: Stripe returns api_key_expired when a request uses a secret or restricted key that has been expired or rotated out. Put the current key in your server's secret settings, then confirm in Workbench request logs that new requests succeed. Publishable keys cannot expire.
What does it mean?
Stripe's error-codes page defines the code as "The API key provided has expired." It then points you to the API keys page in the Dashboard to get your current keys.
Stripe's keys page says that if a request includes an expired key, Stripe returns an authentication error. A request with no valid key gets a different error, an invalid request error. Check which error your logs show before you change anything.
A key expires in two ways from the Dashboard. You can expire a key on purpose. You can also rotate a key, which revokes the old one. Stripe's docs say that after you expire a secret or restricted key, "you must create a new one and update any code that uses the expired key. Code that uses the expired key can no longer make API calls."
Each mode has its own keys. Sandbox keys and live keys are separate, so check which mode the failing request uses.
Which cause is it?
| What you see | Cause | Fix |
|---|---|---|
| The key was expired on purpose from the API keys page | Someone chose Expire key on that key | Cause 1 |
| The key was rotated with Expiration set to Now, or to a time that has passed | The old key was deleted, or its time ran out | Cause 2 |
| The key was rotated more than 7 days ago, or your server still holds the old value | The grace period for the old key ended | Cause 3 |
Cause 1: You expired the key
- Open the API keys page. Check whether you are in sandbox mode or live mode, because each mode has its own keys.
- Find the key that the failing request uses. Click the overflow menu (⋯) for that key and select View request logs. Stripe says this opens Workbench in the Dashboard.
- Create a replacement. Stripe recommends restricted API keys for most use cases. Create one with only the permissions your server needs. If you need a secret key, click Create secret key.
- Copy the new key value when it is shown. In live mode, Stripe says you can't retrieve a key you created yourself after you have seen it once, so save it before you close the dialog.
- Put the new value in your server's secret store, as described in Cause 3, step 2. Then confirm the change in the request logs, as described in "How do I check it's fixed?"
Cause 2: The rotated key timed out
Stripe's keys page says that rotating a key "revokes it and generates a replacement key that's ready to use immediately." In the Expiration dropdown, "If you choose Now, the old key is deleted. If you specify a time, the remaining time until the key expires displays below the key name."
- Open the API keys page in the mode your request uses. Look for the replacement key. A rotated secret key is named Secret key. A rotated restricted key keeps the name of the key it replaced.
- If your rotation set a time, check the remaining time below the key name. When it reaches zero, the old key stops working.
- Get the replacement value. Stripe says that for a manual rotation, "Save the key value. You can't retrieve it later." In live mode, you can reveal a key that Stripe generated for you, including a key generated by a scheduled rotation.
- If you did not save the value, rotate again. Stripe's docs say, "If you lose a key, rotate or delete it and create another." Stripe also says, "We can't recover keys that you've forgotten or lost access to."
- Put the new value in your server's secret store, then confirm the change in the request logs.
Cause 3: Your server still holds the old key
When you rotate a key in the Dashboard, Stripe says that "both the old and new keys work for up to 7 days." That gives time to move over. If you need more than 7 days, Stripe's steps are to create a new key manually, migrate to it, and then expire the old key.
- Find every place the server reads its Stripe key. Stripe says to "Store sensitive keys in a secrets vault provided by your hosting platform." If you can't use a vault, Stripe says to use environment variables. Stripe also says not to put keys in source code or in configuration files checked into version control.
- Replace the old value with the current key from the API keys page. Stripe's go-live steps say to remove any hardcoded API keys from your code before you use a live key in the back end.
- Check the old key's request logs. Stripe advises expiring the old key only after "its request volume has been at zero for a few hours or days."
How do I check it's fixed?
- Open Workbench request logs from the API keys page. Our suggestion: find the newest request from your server and confirm it does not show api_key_expired. Stripe says that "Use Workbench request logs to inspect API requests and troubleshoot errors."
- Our suggestion: repeat the action that failed on your live site, such as a payment or a sign-up that calls Stripe. Confirm that it completes.
- Check the old key's request logs. Confirm that its request volume has reached zero before you expire it.
- In live mode, confirm the server uses a key that starts with
sk_live_orrk_live_, notsk_test_orrk_test_.
FAQ
Why does my publishable key not show this error?
Publishable keys cannot expire. Stripe's keys page says, "You can't expire a publishable key." The api_key_expired error comes from a secret or restricted key.
Is api_key_expired the same as an invalid key error?
No. Stripe's keys page says that a request with no valid key returns an invalid request error, and a request with an expired key returns an authentication error. The error-codes page lists api_key_expired as its own code.
Can the old key keep working after I rotate it?
For up to 7 days, if you rotated it in the Dashboard. Stripe says both keys work during that grace period. If you need longer, create a new key manually, migrate to it, and then expire the old key.
Can I get back a key I expired?
No. Stripe says that code using an expired key "can no longer make API calls." Create a new key and update your code to use it.
Can VibeFix fix it for me?
Yes, for apps built in Lovable or any app whose code is on GitHub. The free check confirms the problem on your live app first. If you want it fixed, our AI agent finds the cause, fixes it in your code for $79 and tests your live app again. See pricing.
Related guides
- secret_key_required: Stripe says you used a publishable key
- Stripe checkout not working on the live site
Sources
- <https://docs.stripe.com/error-codes> (api_key_expired entry)
- <https://docs.stripe.com/keys> (key types, expiring and rotating keys, grace period, reveal rules, request logs, protecting keys)
Last checked: 17 November 2026.
VibeFix is independent. Stripe is a trademark of its owner.
More guides · Shopify store accessibility · About · Your privacy choices