Sessions and tokens

The server-side endpoints behind the Bridge SDK — create a browser session, exchange encrypted card data for a single-use token reference, and read a token's non-sensitive details.

These are the endpoints the Bridge SDK calls on your behalf. A browser session scopes what the SDK may do — which merchant it acts for, which checkout it is attached to, and how long it lives. A token is the single-use reference (tok_…) that stands in for card data your servers never see.

Most integrations never call these directly: @tokeflow_com/bridge-js handles the session handshake and tokenization for you. Document them here because they define the contract — and because server-driven flows sometimes need to create a session or inspect a token's non-sensitive metadata directly. See the Bridge SDK overview for the client-side path.

Card data is collected inside isolated, cross-origin iframes and encrypted in the browser — it never reaches your servers, and neither does the raw PAN or CVC. These endpoints only ever return the non-sensitive parts of a token (brand, last four, expiry). Never attempt to send raw card data to them.

The session object

What a session exposes to the SDK once created.

FieldTypeDescription
sessionIdstringSession ID.
expiresAtstringSession expiration timestamp (ISO 8601).
merchantobjectMerchant information.
capabilitiesobjectMerchant payment capabilities.
settingsobjectMerchant tokenization settings.
sdkobjectSDK integrity information.
installmentsSupportedbooleanWhether installments are supported by the merchant.
installmentOptionsobjectInstallment options supported by the merchant, keyed by payment method.

Endpoints

POST/api/v1/sessions

Auth: Public key (X-Public-Key). Client-safe — usable from the browser.

Create SDK session for tokenization.

Request fields

FieldTypeRequiredDescription
sdkVersionstringNoSDK version used by the client.
checkoutSessionIdstringNoCheckout session to link to this SDK session. Validated against the merchant on creation; required to later read the checkout session via GET /sessions/checkout.
metadataobjectNoOptional metadata to store with the session.

Example request

curl -X POST https://api.tokeflow.com/api/v1/sessions \
  -H "Authorization: Bearer sk_live_mer_…" \
  -H "Content-Type: application/json" \
  -d '{
    "sdkVersion": "2.0.0",
    "checkoutSessionId": "cks_1234567890abcdef",
    "metadata": {
      "customerId": "cus_123",
      "checkoutId": "chk_456"
    }
  }'

Example response — 201

{
  "sessionId": "550e8400-e29b-41d4-a716-446655440000",
  "expiresAt": "2024-01-15T12:30:00.000Z",
  "merchant": {
    "id": "mrc_abc123",
    "name": "Acme Store",
    "organizationId": "org_xyz789"
  },
  "capabilities": {
    "cards": true,
    "pix": true,
    "boleto": false,
    "applePay": true,
    "googlePay": true
  },
  "settings": {
    "allowedCardBrands": [
      "visa",
      "mastercard",
      "amex"
    ],
    "requireCvc": true,
    "requireCardholderName": true,
    "collectBillingAddress": true
  },
  "sdk": {
    "sriHash": "sha256-abcdef1234567890...",
    "sriExpiresAt": "2024-01-15T12:30:00.000Z"
  },
  "installmentsSupported": true,
  "installmentOptions": {
    "credit_card": {
      "min": 2,
      "max": 12
    },
    "pix": null
  }
}

GET/api/v1/sessions/checkout

Auth: Public key (X-Public-Key). Client-safe — usable from the browser.

Get the full checkout context for the SDK session — the checkout session, available payment methods, and the customer saved cards.

Example request

curl https://api.tokeflow.com/api/v1/sessions/checkout \
  -H "Authorization: Bearer sk_live_mer_…"

Example response — 200

{
  "checkout": {
    "id": "cks_a1b2c3d4e5",
    "merchantId": "mer_a1b2c3d4e5",
    "offerId": "ofr_a1b2c3d4e5",
    "customerId": "mcu_a1b2c3d4e5",
    "customerEmail": "jane@acme.com",
    "customerName": "Jane Doe",
    "selectedCurrency": "BRL",
    "status": "initiated",
    "externalSessionId": "sess_external_42",
    "expiresAt": "2026-05-20T18:00:00Z",
    "completedAt": "2026-05-20T17:32:11Z",
    "createdAt": "2026-05-19T12:00:00Z",
    "updatedAt": "2026-05-19T12:00:00Z",
    "items": [
      {
        "id": "cki_a1b2c3d4e5",
        "checkoutSessionId": "cks_a1b2c3d4e5",
        "offerId": "ofr_a1b2c3d4e5",
        "currency": "BRL",
        "amount": 9900,
        "firstChargeAmount": 0,
        "quantity": 1,
        "installments": 1,
        "createdAt": "2026-05-19T12:00:00Z"
      }
    ]
  },
  "paymentMethods": {
    "cards": true,
    "pix": true,
    "boleto": false,
    "applePay": false,
    "googlePay": false,
    "cardBrands": [
      "visa",
      "mastercard"
    ],
    "installmentsSupported": true,
    "installmentOptions": {
      "credit_card": {
        "min": 1,
        "max": 12
      }
    }
  },
  "savedInstruments": [
    {
      "id": "pi_a1b2c3d4e5",
      "instrumentType": "card",
      "brand": "visa",
      "last4": "4242",
      "expMonth": 12,
      "expYear": 2030
    }
  ]
}

POST/api/v1/sessions/:sessionId/payment-instruments

Auth: Public key (X-Public-Key). Client-safe — usable from the browser.

Verify a card (zero-dollar / SetupIntent) and enroll it on file for future merchant-initiated charges.

Request fields

FieldTypeRequiredDescription
tokenIdstringYesThe single-use encrypted enrollment reference (tok_…) from the Bridge SDK to verify and save.
customerIdstringNoTokeflow customer id (cust_*) the card belongs to. Falls back to the linked checkout customer.
currencystringNoISO 4217 currency for verification routing. Falls back to the linked checkout currency.
countrystringNoISO 3166-1 alpha-2 country. Falls back to the merchant country.
connectorIdstringNoVerify against a specific connector; otherwise routed.

Example request

curl -X POST https://api.tokeflow.com/api/v1/sessions/ses_8c3a5d17/payment-instruments \
  -H "Authorization: Bearer sk_live_mer_…" \
  -H "Content-Type: application/json" \
  -d '{
    "tokenId": "tok_8f3c2a1b9d4e",
    "customerId": "cust_2f9a71d4",
    "currency": "BRL",
    "country": "BR",
    "connectorId": "conn_a1b2c3d4"
  }'

Example response — 201

{
  "verified": true,
  "paymentInstrumentId": "string",
  "status": "active",
  "brand": "string",
  "last4": "string",
  "expMonth": 1,
  "expYear": 1,
  "reason": "requested_by_customer"
}

POST/api/v1/sessions/:sessionId/refresh

Auth: Public key (X-Public-Key). Client-safe — usable from the browser.

Refresh SDK session.

Path parameters

FieldTypeRequiredDescription
sessionIdstringYes—

Example request

curl -X POST https://api.tokeflow.com/api/v1/sessions/ses_8c3a5d17/refresh \
  -H "Authorization: Bearer sk_live_mer_…"

Example response — 200

{
  "sessionId": "550e8400-e29b-41d4-a716-446655440000",
  "expiresAt": "2024-01-15T12:30:00.000Z",
  "merchant": {
    "id": "mrc_abc123",
    "name": "Acme Store",
    "organizationId": "org_xyz789"
  },
  "capabilities": {
    "cards": true,
    "pix": true,
    "boleto": false,
    "applePay": true,
    "googlePay": true
  },
  "settings": {
    "allowedCardBrands": [
      "visa",
      "mastercard",
      "amex"
    ],
    "requireCvc": true,
    "requireCardholderName": true,
    "collectBillingAddress": true
  },
  "sdk": {
    "sriHash": "sha256-abcdef1234567890...",
    "sriExpiresAt": "2024-01-15T12:30:00.000Z"
  },
  "installmentsSupported": true,
  "installmentOptions": {
    "credit_card": {
      "min": 2,
      "max": 12
    },
    "pix": null
  }
}

POST/api/v1/tokens

Auth: Public key (X-Public-Key). Client-safe — usable from the browser.

Register a token created via SDK.

Request fields

FieldTypeRequiredDescription
encryptedCardobjectYesEncrypted card data from the Bridge SDK.
metadataobjectYesCard metadata (not encrypted).
purposestringNoPurpose of the token: one_time (default — single-use, expires after 30 minutes) or instrument_enrollment (no expiry; can be saved as a payment instrument). Honored only for standalone tokenization — an SDK session created without a checkoutSessionId.
save_cardbooleanNoInside a checkout session for a one-time offer, true mints an instrument_enrollment token so the card can be saved. Ignored for recurring offers (always enrolled) and outside a checkout session.
additionalMetadataobjectNoOptional additional metadata to store with the token.

How the purpose is decided

ContextResulting purpose
Standalone session (no checkout session linked)Whatever you send; one_time when omitted. save_card has no effect.
Checkout session, recurring offerAlways instrument_enrollment.
Checkout session, one-time offerinstrument_enrollment when save_card: true, otherwise one_time. Any purpose you send is ignored.

The response echoes the purpose that was actually minted. Check it: a one_time token is refused by save_payment_instrument, by POST /merchants/:merchant_id/payment-instruments and by POST /sessions/:sessionId/payment-instruments. The Bridge SDK exposes both fields as saveCard and purpose on TokenizeOptions.

Example request

curl -X POST https://api.tokeflow.com/api/v1/tokens \
  -H "Authorization: Bearer sk_live_mer_…" \
  -H "Content-Type: application/json" \
  -d '{
    "encryptedCard": {
      "number": "<encrypted by the Bridge SDK>",
      "cvc": "<encrypted by the Bridge SDK>",
      "expiryMonth": "12",
      "expiryYear": "25",
      "name": "<encrypted by the Bridge SDK>"
    },
    "metadata": {
      "brand": "visa",
      "last4": "4242",
      "expiryMonth": "12",
      "expiryYear": "2025",
      "bin": "424242"
    },
    "purpose": "one_time",
    "save_card": true,
    "additionalMetadata": {
      "customerId": "cus_123",
      "source": "checkout"
    }
  }'

Example response — 201

{
  "tokenId": "tok_8f3c2a1b9d4e",
  "merchant_id": "mrc_123",
  "purpose": "instrument_enrollment",
  "last4": "4242",
  "card_brand": "visa",
  "exp_month": "12",
  "exp_year": "2028",
  "status": "active",
  "expires_at": "2026-01-15T12:30:00.000Z",
  "created_at": "2025-11-28T12:00:00Z"
}

POST/api/v1/payer-tokens

Auth: Public key (X-Public-Key) and an SDK session (X-Session-Id). Client-safe — usable from the browser.

Register the payer of a PIX or boleto charge and get back a payer token (ptk_…). The Bridge SDK calls it from pix.tokenize() and boleto.tokenize(). Your server then sends the token as payer_token_id on POST /transactions, so it never handles the payer's CPF/CNPJ or address.

The payer is sent over TLS, not encrypted in the browser, because Tokeflow has to read it to validate it and pass it to the provider. It is stored encrypted and deleted once the token is used or expires.

Request fields

FieldTypeRequiredDescription
payment_methodstringYespix or boleto. The token can only be charged with this method.
namestringYesPayer's full name, up to 200 characters.
emailstringYesPayer's email.
phonestringNoPhone number in international format, e.g. +5511999990000.
documentstringYesCPF or CNPJ; punctuation is accepted. Check digits are verified. Alphanumeric CNPJs are accepted.
document_typestringNocpf or cnpj, case-insensitive. Inferred from the document's length when omitted.
addressobjectBoletoBilling address. Required for a boleto (street, neighborhood, city, state, postal_code; number and complement optional). Not needed for PIX. state is a two-letter UF; postal_code is a CEP, 01310-100 or 01310100.

Example response — 201 Created

{
  "tokenId": "ptk_abc123",
  "type": "boleto",
  "document_type": "cpf",
  "document_last_digits": "25",
  "status": "active",
  "expires_at": "2026-10-26T12:30:00.000Z",
  "created_at": "2026-10-26T12:00:00.000Z"
}
RuleDetail
LifetimeSingle use; expires 30 minutes after creation. A failed charge also spends the token — collect the payer again to retry.
Checkout sessionWhen the SDK session is linked to a checkout session, the token can only be charged with that checkout_session_id.
Field errors400 with details naming each missing or invalid field.

GET/api/v1/tokens/:tokenId

OrgMerchant

Auth: Organization key (with merchant_id) or Merchant key.

Retrieve token details.

Path parameters

FieldTypeRequiredDescription
tokenIdstringYes—

Example request

curl https://api.tokeflow.com/api/v1/tokens/tok_8f3c2a1b9d4e \
  -H "Authorization: Bearer sk_live_mer_…"

Example response — 200

{
  "tokenId": "tok_8f3c2a1b9d4e",
  "merchant_id": "mrc_123",
  "purpose": "instrument_enrollment",
  "last4": "4242",
  "card_brand": "visa",
  "exp_month": "12",
  "exp_year": "2028",
  "status": "active",
  "expires_at": "2026-01-15T12:30:00.000Z",
  "created_at": "2025-11-28T12:00:00Z"
}

Errors

Errors use the standard envelope. The most common cases here:

HTTPtypeTypical cause
400validation_errorMissing required field, or an operation the current state does not allow.
401authentication_errorMissing or invalid API key.
403authorization_errorThe key lacks the required scope.
404not_found_errorThe resource does not exist or is not owned by this entity.
429rate_limit_errorRate limit exceeded — back off exponentially.

See Errors for the full catalog.

On this page