Skip to main content

SDK & Receipts

Every successful payment through x402 Studio returns a signed receipt token (JWT). The x402layer SDK lets you verify these receipts server-side to gate premium content, confirm purchases, or audit payments. 🔗 GitHub: Singularity-SDK 🔑 JWKS Endpoint: api.x402layer.cc/.well-known/jwks.json 📦 All packages: see the platform-wide SDKs & Packages catalog.

How It Works

When a payment is processed through x402, the worker signs a receipt JWT with a private key. The SDK verifies that signature using the corresponding public key from the JWKS endpoint — proving the receipt is genuine and untampered.
  1. Client hits your API — Without a valid receipt token
  2. SDK middleware returns 402 — With x402 payment instructions
  3. Client pays via x402 — Receives a signed receipt JWT
  4. Client retries with receipt — Token in header
  5. SDK verifies receipt — Cryptographic signature check against JWKS public keys → access granted

Installation

Node.js

Python

Dependencies (PyJWT, cryptography) are installed automatically. For FastAPI support: pip install x402layer-sdk[fastapi].

Receipt Token Contract

Receipt tokens are standard JWTs signed with RS256. Public keys are served from the JWKS endpoint for verification.

Receipt Claims

Node.js Quick Start

Manual verification:

Python / FastAPI Quick Start

Where the Token Comes From

After a successful payment, the x402 worker includes the receipt token in the response header:
Your client should extract this token and include it in subsequent requests to your backend, either as an Authorization: Bearer header or the X-X402-Receipt-Token header.

Security Notes

  • 🛡️ Always set requiredSourceSlug in production — prevents a receipt for endpoint A being replayed against endpoint B.
  • 🔄 Key rotation — Publish a new JWKS key with a new kid, then update the worker private key. Old tokens remain verifiable until they expire.
  • Expiration — Receipt tokens have a limited lifetime. Always check the exp claim (the SDK does this automatically).