> ## 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.

# Monetize an existing REST API

> Open a per-call revenue channel against your existing API for agent buyers. Settle in USDC on Polygon.

A SaaS or data company already serves a paying customer base through API keys and contracts. Agent buyers are a new segment that does not sign contracts, does not register, and does not fit a seat or seat-overage plan. With x402 middleware in front of the routes you want priced, an agent making a fresh request sees `402 Payment Required`, signs a payment, and gets the response back. Each settled call lands USDC in a wallet you control.

The motion is additive. Your existing customers see no change. Agent traffic becomes a measurable line item without a procurement cycle.

**Who this is for:**

* SaaS platforms looking to open an agent-buyer channel without disrupting enterprise contracts
* Data and API companies that want a per-call self-serve tier alongside their existing plans
* Product and revenue leaders evaluating whether agentic commerce fits their API surface

***

## 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"}}>Per-call monetization</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"}}>Agent</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"}}>Calls a priced route without a payment header</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:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",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"}}>402 Payment Required with price and accepts block</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:"#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:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",whiteSpace:"nowrap"}}>API</span>
    <span style={{fontSize:"13px",color:"#141635"}}>Retries with PAYMENT-SIGNATURE header</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:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",whiteSpace:"nowrap"}}>API</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"}}>Verifies signature, settles USDC on Polygon</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:"#EAE4F5",color:"#670DE5",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"700",whiteSpace:"nowrap"}}>Facilitator</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"}}>Seller wallet</span>
    <span style={{fontSize:"13px",color:"#141635"}}>USDC settles to payout address</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:"#EEF0F9",color:"#48526F",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"600",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"}}>200 OK with response body and PAYMENT-RESPONSE receipt</span>
  </div>
</div>

Middleware runs after your existing auth. Calls with a valid API key flow through the existing path unchanged. Unauthenticated calls fall through to the x402 path. The Polygon-hosted facilitator (`x402.polygon.technology` for mainnet, `x402-amoy.polygon.technology` for Amoy) handles verification and settlement, so you do not run that infrastructure.

***

## Get started

Add x402 v2 middleware in front of the routes you want priced. The Polygon-hosted facilitator handles verification and settlement, so you do not run that infrastructure. Existing API-key traffic flows through your existing path unchanged.

### 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 route

Each priced route declares an `accepts` block. Amounts are in the smallest unit of the currency (USDC has six decimals, so `1000` = \$0.001).

```json theme={null}
{
  "x402Version": 2,
  "accepts": [
    {
      "scheme": "exact",
      "network": "eip155:137",
      "maxAmountRequired": "1000",
      "description": "Single call to /v1/lookups/company"
    }
  ]
}
```

### Test as a buyer

Verify the loop end-to-end with the Polygon Agent CLI:

```bash theme={null}
polygon-agent x402-pay --url https://your-api.example.com/v1/lookups/company
```

***

## Implementation

<CardGroup cols={2}>
  <Card title="x402 Quickstart for Sellers" icon="code" href="/payment-services/agentic-payments/x402/guides/quickstart-sellers">
    Add x402 v2 middleware to Express, Next.js, or Hono.
  </Card>

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

  <Card title="Polygon Agent CLI" icon="terminal" href="/payment-services/agentic-payments/cli/index">
    Test the loop end-to-end as an agent buyer.
  </Card>

  <Card title="Using the Polygon facilitator" icon="server" href="/payment-services/agentic-payments/x402/guides/using-polygon-facilitator">
    Configure middleware against the Polygon-hosted facilitator.
  </Card>
</CardGroup>
