Stripe: No such token.. a similar object exists in test mode, but a live mode key was used to make this request

Stripe: No such token.. a similar object exists in test mode, but a live mode key was used to make this request

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Stripe: No such token.. a similar object exists in test mode, but a live mode key was used to make this request

This error message is deceptive. It tells you that a token doesn't exist, but it immediately qualifies that by noting a "similar object" exists in test mode. This specific phrasing reveals the root cause: your application logic is treating tokens as reusable identifiers, which is fundamentally incorrect for Stripe's architecture.

When you switch from test to live mode, Stripe keys change, but the semantic meaning of the StripeToken remains consistent. The error occurs because you are passing a client-side token (like tok_...) directly into a server-side API call intended for creating a customer or charging a card. While the code snippet provided works in test mode using public keys, live mode requires strict authentication and specific handling of sensitive data.

Understanding Token Lifecycle and Scope

The core misunderstanding lies in how Stripe tokens are generated versus how they are consumed. A token is an opaque identifier created by your frontend JavaScript or a mobile app to represent card details securely. It acts as a disposable proxy for the actual card number.

In your PHP code, you are attempting to create a customer using this token:

$customer = \Stripe\Customer::create(array(
      'email' => $email,
      'card'  => $token
    ));

This approach is valid in test mode if the public key allows it, but it breaks down in live mode for two critical reasons. First, the tok_... token has a limited lifespan and is strictly bound to the API key that created it or the context in which it was issued. Second, and more importantly, you are not using the token to charge directly; you are attaching it to a customer object first, then attempting a subsequent charge.

Stripe's documentation explicitly states that tokens are not meant to be stored in your database. They are designed to be used once to establish a secure connection between the client and the server. When you pass tok_fgfhn (or any other token) to the live API without the corresponding secret key context, Stripe validates the signature against its internal ledger of active tokens for that specific environment. Since no such token exists in the live environment registry, it throws the "No such token" error.

The Correct Implementation Pattern

To resolve this, you must decouple the customer creation from the token usage. The standard pattern involves attaching the card to the customer during the charge or using the source object, rather than relying on a pre-generated token for customer creation in live environments.

However, if you require the customer object to be created first, you should not pass the raw token string directly to the card parameter in live mode without ensuring the token is valid for that specific key. A more robust approach in live mode is to use the idempotency_key and ensure the token was generated using the correct client-side logic.

If you are building a checkout flow, consider using Stripe Elements or Checkout. These libraries handle the tokenization securely on the client side and return a payment_intent or source ID that can be used immediately on the server. Here is how you should structure the charge creation to avoid token expiration issues:

$customer = \Stripe\Customer::create([
    'email' => $email,
]);

// Instead of passing the raw token to create a customer in live mode,
// you often need to attach the card via a PaymentIntent or Source object.
// However, if you must use tokens for Customer creation:

$customer->source = \Stripe\Source::create([
    'source' => $token,
    'customer' => $customer->id,
]);

// Then proceed with the charge using the customer ID
$charge = \Stripe\Charge::create([
    'customer' => $customer->id,
    'amount'   => $amount,
    'currency' => 'eur',
    'source'   => null // Let Stripe look up the attached source
]);

Handling Token Expiration and Security

The error "a similar object exists in test mode" implies that your test environment accepted the token because the public key was sufficient to create a temporary mapping. Live mode, however, enforces stricter validation. Tokens are often tied to specific sessions or expire quickly if not used immediately.

A common pitfall is storing these tokens in your database. Even though they don't contain raw card numbers, they link back to the customer's payment method. If you store a token and try to use it days later, it will fail. The solution is to always pass the token directly to the API call where it is needed, or better yet, migrate to using PaymentIntent objects which handle client secrets and tokens more gracefully in modern Stripe flows.

For production environments, ensure your frontend generates the token using the published live key only if necessary, though best practice suggests moving entirely to Payment Intents to avoid token management overhead. If you are integrating with Laravel, packages like laravel/stripe can abstract this complexity, ensuring that the lifecycle of the payment method is managed correctly without exposing tokens in your logs or database.

Ultimately, the fix requires shifting away from treating tokens as persistent identifiers and instead utilizing them as one-time credentials to establish a secure link between the customer and their payment source.

Our network