FG
๐Ÿ”Œ APIs & SDKsStripe

A similar object exists in test mode, but a live mode key was used to make this request

Freshabout 21 hours ago
Mar 14, 20260 views
Confidence Score59%
59%

Problem

I didn't know where else to post this, but I'm using this lib on our server. While testing, I had tried to add a real credit card to my account, which failed saying that I was in test mode. Now, both my client and server are running in test mode. And, when I try to add that same came, I get this error from the stripe API: No such token: ......; a similar object exists in test mode, but a live mode key was used to make this request. How can my card object exist in test mode?

Error Output

error from the stripe API: No such token: ......; a similar object exists in test mode, but a live mode key was used to make this request. 

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Switch to Test Mode API Keys

Medium Risk

The error occurs because a live mode API key is being used to access a resource (like a token or card object) that was created in test mode. Stripe maintains separate environments for live and test transactions, and objects created in one mode cannot be accessed using keys from the other mode.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Identify Current API Keys

    Check your server and client configuration to identify which API keys are currently being used. Ensure that both the server and client are using the test mode keys.

    javascript
    console.log(process.env.STRIPE_API_KEY);
  2. 2

    Update API Keys to Test Mode

    Replace any live mode API keys with the corresponding test mode API keys in your server and client configurations. This ensures that all requests are made in test mode.

    javascript
    process.env.STRIPE_API_KEY = 'sk_test_XXXXXXXXXXXXXXXXXXXXXXXX';
  3. 3

    Clear Existing Tokens and Retry

    If there are existing tokens or card objects that were created in test mode, ensure they are cleared from your application state. Attempt to create a new token or card object using the test mode API keys.

    javascript
    stripe.tokens.create({ card: { number: '4242424242424242', exp_month: 12, exp_year: 2023, cvc: '123' } });
  4. 4

    Test the Integration

    Run your application and attempt to add the card again. Monitor the logs for any errors and ensure that the requests are being made with the test mode keys.

    javascript
    console.log('Testing card addition...');

Validation

Confirm that the card object is successfully added without errors. You can check the Stripe dashboard in test mode to verify that the card appears in the test environment.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

stripepaymentsapi