API Error: a similar object exists in test mode, but a live mode key was used
You’re using an ID, key or URL from one environment (test/sandbox) with credentials from another (live/production), or vice versa.
a similar object exists in test mode, but a live mode key was useda similar object exists in live mode, but a test mode key was usedtest mode keylive mode keysandbox credentials Meaning
Payment and SaaS APIs keep test and live data completely separate. Stripe says “No such customer: 'cus_x'; a similar object exists in test mode, but a live mode key was used to make this request”. Other providers return 401 “invalid key for this environment” or simply “not found”.
It typically happens after going live: the keys were swapped but IDs (prices, plans, webhooks, customers) saved in the database or config are still test-mode IDs — or the frontend uses a test publishable key while the backend uses a live secret key.
Common causes
- Test-mode IDs (price, plan, product, customer) stored in config after switching to live keys
- Frontend and backend use keys from different modes
- Sandbox base URL with production credentials (or the reverse)
- Data copied from staging to production
⚡ Quick fix
- Use keys and IDs from the same mode everywhere
- Recreate products/prices/webhooks in live mode and update stored IDs
- Keep mode-specific settings in per-environment config
Detailed fix by platform
Node.js
- javascript
// fail fast if keys from different modes are mixed const live = process.env.STRIPE_SECRET_KEY.startsWith('sk_live_'); if (live !== process.env.STRIPE_PUBLISHABLE_KEY.startsWith('pk_live_')) throw new Error('Stripe keys are from different modes');
How to diagnose
- Keys — Prefixes of secret and publishable keys (sk_live/sk_test)
- IDs — Where were stored IDs created?
- URLs — Sandbox vs production base URL
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in API
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 14 Oct 2026