# API Error: a similar object exists in test mode, but a live mode key was used

**Code:** `test/live mismatch` · **Category:** API · **Seen on:** REST API

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

1. Use keys and IDs from the same mode everywhere
2. Recreate products/prices/webhooks in live mode and update stored IDs
3. Keep mode-specific settings in per-environment config

## Detailed fix by platform

### Node.js

1. 

```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

1. **Keys** — Prefixes of secret and publishable keys (sk_live/sk_test)
2. **IDs** — Where were stored IDs created?
3. **URLs** — Sandbox vs production base URL

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/api/test-mode-live-mode-mismatch)
