Network Tokens Setup
Network Tokens is an Enterprise feature and the onboarding process is different between TEST and PRODUCTION Tenants. Start by requesting access from your test tenant in the Basis Theory Portal under Settings → Quotas.
Test Tenant Onboarding
Once enabled, your test tenant will be configured to use the Network Tokens sandbox, providing stubbed responses without forwarding requests to card networks. See Network Tokens Testing for more information.
Production Tenant Onboarding
Once access is enabled, merchants are created and onboarded directly in the Portal. See Onboard a Merchant for the full walkthrough, including the business information and per-network identifiers (Amex Direct SE Number, Discover MID) you will need to collect before you start.
Network Tokens on American Express is limited to merchants on a Direct SE relationship.
Tenant Configuration
The following configuration applies to both TEST and PRODUCTION Tenants after onboarding is completed.
Access Controls
Refer to the implementation guides to learn which Access Controls (applications, permissions, etc.) are required for your use case.
Webhook Configuration
You need to configure a webhook endpoint to receive real-time notifications for critical Network Token lifecycle events. This enables proactive monitoring and automated response to Network Token status changes.
Use the webhook management API or the Portal to register an endpoint URL to receive one or more of the following Network Token events:
network-token.created: Triggered when a Network Token is created. Asynchronous provisioning from a card token also emits it when it matches an existing Network Token, withdeduplicated: truein the payloadnetwork-token.cryptogram.created: Triggered when a cryptogram is generated for a Network Tokennetwork-token.deleted: Triggered when a Network Token is permanently deletednetwork-token.provisioning.failed: Triggered when Basis Theory stops trying to provision a Network Token for a card token through automatic provisioningnetwork-token.updated: Triggered when the card network changes the Network Token's status, expiry or card details, or when you suspend or resume it. See Lifecycle Updates
Automatic Provisioning Enterprise
Turn new card tokens into payment-ready Network Tokens without building a separate provisioning flow. Basis Theory handles provisioning and retries in the background, so a Network Token can be ready for the first customer-initiated charge. With an event encryption key, Basis Theory also generates a cryptogram and sends both to you in the network-token.created webhook.
Automatic provisioning is available as an add-on. Contact sales to enable it for your Tenant.
Every new card token starts Network Token provisioning automatically, whether created through the API or a Proxy. No call to the Create a Network Token API is needed.
Basis Theory enables automatic provisioning per Tenant. You can also request it under Settings → Quotas in the Basis Theory Portal.
Provisioning and retries
Basis Theory retries transient errors, including card network rate limits and timeouts. If a Network Token already exists for the same card and merchant, Basis Theory reuses it and sets deduplicated: true on network-token.created. If it belongs to a different merchant, provisioning fails with MERCHANT_MISMATCH.
Receive payment details
To charge with the Network Token right after provisioning, register an event encryption key. Basis Theory then generates a cryptogram for each Network Token and sends the Network Token number, expiration, cryptogram, and ECI in network-token.created, encrypted with your key in payment_details.
The key is optional. Without one, Basis Theory does not generate a cryptogram, and network-token.created arrives without payment_details. Retrieve the Network Token data and generate a cryptogram when you charge, as described in Charge with the Network Token.
Each card token produces at most one provisioning outcome event. In rare failure cases no event is sent, so if no event arrives by the time you charge, charge with the card.
| Event | Outcome | Next step |
|---|---|---|
network-token.created with payment_details and no cryptogram_error | The Network Token and cryptogram are ready. | Decrypt payment_details and charge with the Network Token and cryptogram. |
network-token.created with payment_details and cryptogram_error | The Network Token is ready, but cryptogram generation failed. payment_details contains no cryptogram. | Generate a cryptogram before charging, or charge with the card. |
network-token.created without payment_details | The Network Token is ready. Your Tenant has no event encryption key. | Retrieve the Network Token and generate a cryptogram when you charge. |
network-token.provisioning.failed | No Network Token was provisioned. Basis Theory does not retry after this event. | Charge with the card. |
Generate a key pair
Generate an X25519 key pair and keep the private key in your own key management system. For example, with OpenSSL:
openssl genpkey -algorithm X25519 -out private.pem
openssl pkey -in private.pem -pubout -out public.pem
Register the key
Send the public key to Register an Event Encryption Key with a Management Application that has the network-token:manage-event-encryption-key permission. The response includes the key's kid. Network Tokens provisioned after the key is registered include payment_details. A new key can take a few seconds to apply.
If the registered key can't be used, provisioning fails with ENCRYPTION_KEY_UNAVAILABLE and no Network Token is created. Register a new key to resolve it.
Decrypt payment details
payment_details is a compact JWE with these header values:
| Header | Value |
|---|---|
alg | ECDH-ES |
enc | A256GCM |
kid | The kid of the key used to encrypt it |
epk | The ephemeral X25519 public key used for the key agreement |
Decrypt it with your private key using a JOSE library that supports ECDH-ES with X25519 keys. Not every JOSE library supports X25519. For example, with jose in Node.js or jwcrypto in Python:
- Node
- Python
import { readFileSync } from "node:fs";
import { compactDecrypt, importPKCS8 } from "jose";
const privateKey = await importPKCS8(readFileSync("private.pem", "utf8"), "ECDH-ES");
const { plaintext } = await compactDecrypt(paymentDetails, privateKey);
const details = JSON.parse(new TextDecoder().decode(plaintext));
import json
from jwcrypto import jwe, jwk
with open("private.pem", "rb") as f:
private_key = jwk.JWK.from_pem(f.read())
token = jwe.JWE()
token.deserialize(payment_details, key=private_key)
details = json.loads(token.payload)
The decrypted content is a JSON object:
{
"number": "4335610000002426",
"expiration_month": 12,
"expiration_year": 2030,
"cryptogram": "2z8pd6WGPUi/BBesvjJcyw==",
"eci": "07"
}
| Name | Type | Description |
|---|---|---|
number | String | The Network Token number. |
expiration_month | Number | The Network Token expiration month. |
expiration_year | Number | The four-digit Network Token expiration year. |
cryptogram | String | (Optional) A single-use cryptogram for the Network Token. Missing when cryptogram_error is sent. |
eci | String | (Optional) The ECI value for the cryptogram. Missing when cryptogram_error is sent. |
The decrypted content is card data. Handle it with the same controls you apply to card numbers, and never log it.
Rotate the key
Registering a new key replaces the previous one. Events already sent or retried with the previous key still carry its kid, so keep the previous private key until you stop receiving events with that kid. Use the kid in the JWE header to choose which private key to decrypt with.
You can't retrieve or remove a registered key through the API. To stop receiving payment_details, contact us.
Charge with the Network Token
Charge with the Network Token number and expiration, along with a cryptogram and ECI. You can get them in these ways:
- From
payment_details: decryptpayment_detailsfromnetwork-token.created. It contains the number, expiration, cryptogram, and ECI. - Directly: retrieve the Network Token number and expiration with Get a Network Token, using an Application with the
network-token:revealpermission, and generate a cryptogram. You can store the number and expiration after the first retrieval and reuse them for later charges, or retrieve them before each charge. See Processing Payment for examples. - Through a Proxy: send the transaction through a Proxy and use a Network Token expression to insert the Network Token number.
Cryptograms are single use. The cryptogram in payment_details covers the first customer-initiated charge. For later customer-initiated charges, generate a new cryptogram. For merchant-initiated transactions, see Subsequent Charges. Do not store the cryptogram.
Basis Theory also sends network-token.cryptogram.created when a cryptogram is generated. This event contains only the Network Token id and is not a provisioning outcome event.
Test your integration
In TEST Tenants, automatic provisioning uses the Network Tokens sandbox. Use the test cards to reproduce the same outcomes as calling the Create a Network Token API.