Skip to main content

Agent Payments

BKey enables AI agents to autonomously pay for API access when they encounter HTTP 402 responses. The agent never handles money directly — BKey authorizes and signs payments on the user’s behalf, with biometric approval for anything above the spending limit.

Two protocols, one approval layer

Both x402 and MPP use the HTTP 402 pattern, but they serve different purposes: BKey is the authorization layer on top of both. Regardless of which protocol the API uses, BKey handles spending limits, biometric approval, and key management. Your agent code stays the same — only the payment header differs.

When to use which

Super-simple integration — pick your path

Three entry points. All of them auto-detect the protocol from the 402 response, so your agent never has to know whether the merchant speaks x402 or MPP.

Path A — Zero-code (CLI proxy)

Example session:
If the payment needs biometric approval, the CLI prints 📱 Biometric approval required — check your phone. and waits. You can combine vault-backed headers too: bkey proxy GET <url> --header "Authorization: Bearer {vault:api-key}".

Path B — Programmatic (TypeScript SDK)

One reusable paidFetch() wrapper handles both protocols. Drop it anywhere you use fetch:

Path C — Python (shell out to the CLI)

Python mirrors the same detect-first logic. The idiomatic pattern is to delegate to the CLI:
For a fully programmatic Python version, see examples/python/agent-checkout.

How auto-detection works

Inside the CLI proxy, the skill, and the SDK’s authorize methods, BKey inspects the 402 response and picks the right protocol:
Selection order:
  1. x402 first, if advertised. No percentage fee, fast finality.
  2. MPP second, if x402 isn’t advertised but MPP is.
  3. Fail if neither header is present.

Per-transaction cost

A 10–100x difference at typical microtransaction amounts: x402 has no percentage fee. USDC is 1:1 with USD, no FX loss. Settlement is final in ~2 seconds on Base. For pay-per-call APIs and microtransactions, x402 is almost always cheaper — which is why the proxy picks it when both are on offer.

Under the hood

x402 path

  1. Agent makes a request → server returns HTTP 402 with PAYMENT-REQUIRED: <base64 JSON>.
  2. BKey decodes: { maxAmountRequired, payTo, network, description, resource }.
  3. BKey calls POST /v1/x402/authorize with the amount + recipient.
  4. If within the per-agent spending limit → auto-approved, BKey signs an EIP-3009 ReceiveWithAuthorization payload with the user’s on-device secp256k1 key.
  5. If above the limit → BKey sends a biometric push; after the user approves with facial biometrics, the same signed payload is produced.
  6. Agent retries with PAYMENT-SIGNATURE: <base64 EIP-3009>.
  7. Server verifies via the Coinbase facilitator, settles on-chain, returns the resource.

MPP path

  1. Agent makes a request → server returns HTTP 402 with X-Payment-Required: <JSON>.
  2. BKey decodes: { amount, currency, paymentMethodId, merchantName, description }.
  3. BKey calls POST /v1/mpp/authorize with the amount + payment method.
  4. Auto-approved or biometric (same rules as x402).
  5. BKey returns a Shared Payment Token (SPT) scoped to this merchant + amount.
  6. Agent retries presenting the SPT in whatever format the merchant expects (typically a JSON body field).
  7. Merchant captures via standard Stripe APIs.
The user’s private key never leaves the phone in either path — BKey is a courier for the signed authorization, not a custodian of funds.

Spending limits

Users configure per-agent spending limits in the BKey mobile app. Limits apply to both x402 and MPP payments: Payments within limits are auto-approved (no phone notification). Payments above limits trigger biometric approval via push notification.

OAuth scopes

Agent payment capabilities are controlled by three protocol-neutral scopes: These scopes are included by default when running bkey auth setup-agent.

Security

  • Private keys never leave the phone — payments are signed on-device using biometric-derived keys
  • Spending limits prevent unauthorized charges — configurable per agent, per protocol
  • CIBA biometric approval ensures human-in-the-loop for large payments
  • EIP-3009 ReceiveWithAuthorization (x402) prevents front-running by requiring the recipient to submit the transaction
  • Scoped SPTs (MPP) are merchant-locked, time-limited, and amount-capped
  • Short validity windows (< 5 minutes) limit exposure of signed payloads
See the encryption guide for how payload secrecy is enforced end-to-end.

See also