> ## Documentation Index
> Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt
> Use this file to discover all available pages before exploring further.

# Agentic SaaS metering

> Add a per-action x402 channel to a seat-priced SaaS product. Keep enterprise contracts intact; bill agent traffic by usage.

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

<div style={{border:"1px solid #C8CFE1",borderRadius:"12px",overflow:"hidden",marginBottom:"24px"}}>
  <div style={{background:"linear-gradient(180deg,#EAE4F5 0%,#F6F3FB 100%)",borderBottom:"1px solid #D5C4F2",padding:"10px 16px",fontSize:"11px",fontWeight:"700",color:"#670DE5",letterSpacing:"0.06em",textTransform:"uppercase"}}>Layered billing channels</div>

  <div style={{borderBottom:"1px solid #EEF0F9",padding:"9px 16px",display:"flex",alignItems:"center",gap:"10px"}}>
    <span style={{color:"#929EBA",fontSize:"11px",fontWeight:"700",minWidth:"16px",textAlign:"right"}}>1</span>
    <span style={{background:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",whiteSpace:"nowrap"}}>Caller</span>
    <span style={{color:"#670DE5",fontWeight:"700"}}>→</span>
    <span style={{background:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",whiteSpace:"nowrap"}}>API</span>
    <span style={{fontSize:"13px",color:"#141635"}}>POST /v1/documents/process</span>
  </div>

  <div style={{borderBottom:"1px solid #EEF0F9",padding:"9px 16px",display:"flex",alignItems:"center",gap:"10px"}}>
    <span style={{color:"#929EBA",fontSize:"11px",fontWeight:"700",minWidth:"16px",textAlign:"right"}}>2</span>
    <span style={{background:"#EAE4F5",color:"#670DE5",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"700",whiteSpace:"nowrap"}}>API</span>
    <span style={{fontSize:"13px",color:"#141635",marginLeft:"4px"}}>Valid API key + in plan? → serve, increment seat usage</span>
  </div>

  <div style={{borderBottom:"1px solid #EEF0F9",padding:"9px 16px",display:"flex",alignItems:"center",gap:"10px"}}>
    <span style={{color:"#929EBA",fontSize:"11px",fontWeight:"700",minWidth:"16px",textAlign:"right"}}>3</span>
    <span style={{background:"#EAE4F5",color:"#670DE5",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"700",whiteSpace:"nowrap"}}>API</span>
    <span style={{fontSize:"13px",color:"#141635",marginLeft:"4px"}}>Valid API key + over plan? → charge overage on existing path</span>
  </div>

  <div style={{borderBottom:"1px solid #EEF0F9",padding:"9px 16px",display:"flex",alignItems:"center",gap:"10px"}}>
    <span style={{color:"#929EBA",fontSize:"11px",fontWeight:"700",minWidth:"16px",textAlign:"right"}}>4</span>
    <span style={{background:"#EAE4F5",color:"#670DE5",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"700",whiteSpace:"nowrap"}}>API</span>
    <span style={{color:"#670DE5",fontWeight:"700"}}>→</span>
    <span style={{background:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",whiteSpace:"nowrap"}}>Agent</span>
    <span style={{fontSize:"13px",color:"#141635"}}>No API key? → 402 with per-action price</span>
  </div>

  <div style={{borderBottom:"1px solid #EEF0F9",padding:"9px 16px",display:"flex",alignItems:"center",gap:"10px"}}>
    <span style={{color:"#929EBA",fontSize:"11px",fontWeight:"700",minWidth:"16px",textAlign:"right"}}>5</span>
    <span style={{background:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",whiteSpace:"nowrap"}}>Agent</span>
    <span style={{color:"#670DE5",fontWeight:"700"}}>→</span>
    <span style={{background:"#EAE4F5",color:"#670DE5",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"700",whiteSpace:"nowrap"}}>Facilitator</span>
    <span style={{fontSize:"13px",color:"#141635"}}>Retries with PAYMENT-SIGNATURE; facilitator verifies and settles</span>
  </div>

  <div style={{padding:"9px 16px",display:"flex",alignItems:"center",gap:"10px"}}>
    <span style={{color:"#929EBA",fontSize:"11px",fontWeight:"700",minWidth:"16px",textAlign:"right"}}>6</span>
    <span style={{background:"#EAE4F5",color:"#670DE5",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"700",whiteSpace:"nowrap"}}>API</span>
    <span style={{color:"#670DE5",fontWeight:"700"}}>→</span>
    <span style={{background:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",whiteSpace:"nowrap"}}>Ledger</span>
    <span style={{fontSize:"13px",color:"#141635"}}>Write billable event tagged with channel (seat / overage / x402)</span>
  </div>
</div>

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](/payment-services/agentic-payments/solutions/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

<Tabs>
  <Tab title="Express">
    ```bash theme={null}
    bun install @x402/express @x402/core @x402/evm express
    ```
  </Tab>

  <Tab title="Next.js">
    ```bash theme={null}
    bun install @x402/next @x402/core @x402/evm
    ```
  </Tab>

  <Tab title="Hono">
    ```bash theme={null}
    bun install @x402/hono @x402/core @x402/evm hono @hono/node-server
    ```
  </Tab>
</Tabs>

Full middleware setup, including configuration and the facilitator client, is in the [x402 Quickstart for Sellers](/payment-services/agentic-payments/x402/guides/quickstart-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.

```json theme={null}
{
  "x402Version": 2,
  "accepts": [
    {
      "scheme": "exact",
      "network": "eip155:137",
      "maxAmountRequired": "100000",
      "description": "Document processed"
    }
  ]
}
```

### Test as a buyer

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

***

## Implementation

<CardGroup cols={2}>
  <Card title="x402 Quickstart for Sellers" icon="code" href="/payment-services/agentic-payments/x402/guides/quickstart-sellers">
    Add the middleware behind your existing auth.
  </Card>

  <Card title="Per-inference billing" icon="brain" href="/payment-services/agentic-payments/solutions/per-inference-billing">
    For variable-cost actions, use the `upto` scheme.
  </Card>

  <Card title="Monetize an existing API" icon="layer-group" href="/payment-services/agentic-payments/solutions/monetize-existing-api">
    The general pattern this scenario specializes.
  </Card>

  <Card title="x402 How It Works" icon="book-open" href="/payment-services/agentic-payments/x402/guides/how-it-works">
    Protocol mechanics and receipts.
  </Card>
</CardGroup>
