Skip to main content

Overview

ChainStream CLI can automatically purchase a subscription when it encounters a 402 (Payment Required) response. After a successful purchase, the returned API Key is saved to your config — all subsequent calls use the key without further wallet signatures.

How It Works

When any CLI command receives a 402 error, the auto-payment flow activates:
  1. CLI fetches available plans from /x402/pricing and displays a selection table
  2. You choose a plan interactively
  3. CLI asks for payment method: x402 (USDC on Base/Solana) or MPP (stablecoin on Tempo / Stripe card)
  4. If x402: signs and sends payment automatically, saves the returned API Key
  5. If MPP: prints the tempo request command for manual purchase
  6. Retries the original command with the new API Key
$ chainstream token info --chain sol --address So11111111111111111111111111111111111111112

[chainstream] No active subscription. Available plans:

   #  Plan       Price    Quota           Duration
   ── ────────── ──────── ──────────────── ────────
   1  nano       $5             500,000 CU  30 days
   2  starter    $199        10,000,000 CU  30 days
   3  pro        $699        50,000,000 CU  30 days

Select plan (1-3): 1

[chainstream] Choose payment method:
  1. x402 (USDC on Base/Solana)
  2. MPP Tempo (USDC.e on Tempo)

Select method (1-2): 1

[chainstream] Purchasing nano plan via x402...
[chainstream] Subscription activated: nano (expires: 2026-04-25T12:00:00.000Z)
[chainstream] API Key saved to config.
If you only have an API Key (no wallet), the CLI skips x402 and prints MPP instructions instead.

Wallet Setup

x402 payment requires a funded wallet:
# Create a ChainStream TEE wallet (recommended)
chainstream login

# Or import a raw private key (dev/testing only)
chainstream wallet set-raw --chain base

View Plans

chainstream wallet pricing

# Or via curl
curl https://api.chainstream.io/x402/pricing

After Purchase

  1. The API Key (cs_live_...) is automatically saved to ~/.config/chainstream/config.json
  2. The CLI client is re-initialized with the new key
  3. The original command is retried and succeeds
  4. All subsequent commands use the API Key — no further wallet signatures needed

Troubleshooting

IssueSolution
”Insufficient USDC balance”Fund your wallet with USDC on Base or Solana
402 persists after purchaseCheck chainstream config get to verify API Key was saved
Wrong chain selectedUse chainstream config set --key walletChain --value base
Want to change planPurchase a new plan — it replaces the existing subscription

Learn More

x402 Payment Protocol

How the x402 protocol works, detailed flow, and manual integration

MPP Payment Protocol

How MPP works with Tempo stablecoin and Stripe card payments