Skip to main content
A SaaS product is sold by seat with annual contracts and metered overage. Agent customers do not fit a seat model: they consume in bursts, will not sign contracts, and need to pay only for actions taken. By layering x402 middleware after existing auth on the same API, agents can transact per action while seat customers see no change. Both channels charge the same per-action units, so finance gets one ledger sliced by channel. Three channels run in parallel against the same product surface. Who this is for:
  • SaaS platforms with an API surface consumed by customer agents
  • Pricing and product leaders evaluating per-action billing for the agent segment
  • Finance and operations teams designing one ledger across multiple billing motions

How it works

Layered billing channels
1CallerAPIPOST /v1/documents/process
2APIValid API key + in plan? → serve, increment seat usage
3APIValid API key + over plan? → charge overage on existing path
4APIAgentNo API key? → 402 with per-action price
5AgentFacilitatorRetries with PAYMENT-SIGNATURE; facilitator verifies and settles
6APILedgerWrite billable event tagged with channel (seat / overage / x402)
The same action taxonomy you already meter for overage billing also drives x402 pricing. Each priced action maps to a maxAmountRequired in USDC. Finance pulls one report; channel becomes a column, not a separate ledger. For variable-cost actions (output-size or compute-driven), use the x402 v2 upto scheme described in Per-inference billing.

Get started

Layer x402 v2 middleware after your existing auth. Seat customers and overage customers flow through the existing path. Unauthenticated calls fall through to x402 and pay per action using the same action taxonomy you already meter.

Install

bun install @x402/express @x402/core @x402/evm express
Full middleware setup, including configuration and the facilitator client, is in the x402 Quickstart for Sellers.

Price a metered action

Each priced action declares its own accepts block. Reuse your existing action taxonomy so finance can pull one ledger sliced by channel.
{
  "x402Version": 2,
  "accepts": [
    {
      "scheme": "exact",
      "network": "eip155:137",
      "maxAmountRequired": "100000",
      "description": "Document processed"
    }
  ]
}

Test as a buyer

polygon-agent x402-pay --url https://api.example.com/v1/documents/process \
  --method POST \
  --body '{"document":"..."}'

Implementation

x402 Quickstart for Sellers

Add the middleware behind your existing auth.

Per-inference billing

For variable-cost actions, use the upto scheme.

Monetize an existing API

The general pattern this scenario specializes.

x402 How It Works

Protocol mechanics and receipts.