VibeFix

Guide

api_key_expired: Stripe says the API key has expired

Published by Yosef D., founder of VibeFix

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.

Get it fixed: a free check first confirms the problem on your live app, usually in 4 to 10 minutes.

Free. No account needed. It usually takes 4 to 10 minutes.

Want it fixed? For Lovable apps or code on GitHub, our AI agent fixes it in your code for $79 and tests your live app again. If we can't complete your re-check, you get your money back.

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 seeCauseFix
The key was expired on purpose from the API keys pageSomeone chose Expire key on that keyCause 1
The key was rotated with Expiration set to Now, or to a time that has passedThe old key was deleted, or its time ran outCause 2
The key was rotated more than 7 days ago, or your server still holds the old valueThe grace period for the old key endedCause 3

Cause 1: You expired the key

  1. Open the API keys page. Check whether you are in sandbox mode or live mode, because each mode has its own keys.
  2. 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.
  3. 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.
  4. 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.
  5. 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."

  1. 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.
  2. If your rotation set a time, check the remaining time below the key name. When it reaches zero, the old key stops working.
  3. 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.
  4. 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."
  5. 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.

  1. 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.
  2. 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.
  3. 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?

  1. 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."
  2. 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.
  3. Check the old key's request logs. Confirm that its request volume has reached zero before you expire it.
  4. In live mode, confirm the server uses a key that starts with sk_live_ or rk_live_, not sk_test_ or rk_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

Sources

Last checked: 17 November 2026.

VibeFix is independent. Stripe is a trademark of its owner.

More guides · Shopify store accessibility · About · Your privacy choices