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.
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 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.
Report a correction or suggest an improvement
Last updated 7 Oct 2026