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

# Pay an x402 endpoint

> Call an x402-protected resource from the CLI. The 402 is auto-paid and the request is retried as part of the same call.

`x402-pay` calls an x402-protected URL on behalf of the smart wallet. When the server returns `402 Payment Required`, the CLI signs the payment using the wallet's session, retries the request, and returns the response body. There is no `--broadcast` flag, payment and the request are one operation, so settlement happens as part of the call.

Use this command to test that a seller's x402 integration is live, to consume paid APIs from scripts, or to demonstrate agent-buyer flows interactively.

***

## 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"}}>x402-pay flow</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"}}>Operator</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"}}>CLI</span>
    <span style={{fontFamily:"'Geist Mono',ui-monospace,monospace",fontSize:"12px",color:"#141635"}}>polygon-agent x402-pay --url ...</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"}}>CLI</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"}}>Initial request (no 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"}}>3</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"}}>CLI</span>
    <span style={{fontSize:"13px",color:"#141635"}}>402 Payment Required with 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"}}>4</span>
    <span style={{background:"#EAE4F5",color:"#670DE5",padding:"2px 8px",borderRadius:"4px",fontSize:"11px",fontWeight:"700",whiteSpace:"nowrap"}}>CLI</span>
    <span style={{fontSize:"13px",color:"#141635",marginLeft:"4px"}}>Signs payment with wallet session, retries with PAYMENT-SIGNATURE</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"}}>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 and settles USDC on Polygon</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"}}>CLI</span>
    <span style={{fontSize:"13px",color:"#141635"}}>200 OK with body + PAYMENT-RESPONSE receipt</span>
  </div>
</div>

There is no separate verify-then-execute step. The CLI receives the 402, signs against the wallet's session, retries, and prints the response body plus the settlement receipt in one call.

***

## Prerequisites

Before calling `x402-pay`, confirm three things:

1. **Wallet exists.** `polygon-agent wallet list`. If missing, run `polygon-agent wallet create`.
2. **USDC balance.** `polygon-agent balances --chain polygon`. The wallet needs enough USDC to cover the price plus gas (keep \~0.1 USDC reserve).
3. **The endpoint actually requires x402.** Curl the URL once; if it returns 200 without a payment header, x402 isn't gating it.

For known endpoints, the [x402 directory](/payment-services/agentic-payments/x402/directory) lists active sellers.

***

## Command

```bash theme={null}
polygon-agent x402-pay --url https://api.example.com/v1/lookups/company
polygon-agent x402-pay \
  --url https://api.example.com/v1/inference \
  --method POST \
  --body '{"prompt":"hi"}' \
  --header "X-Trace-Id:abc"
```

| Flag       | Default  | Purpose                                      |
| ---------- | -------- | -------------------------------------------- |
| `--wallet` | `main`   | Wallet name                                  |
| `--chain`  | none     | Chain to pay on (defaults to wallet's chain) |
| `--url`    | required | Endpoint URL                                 |
| `--method` | `GET`    | HTTP method                                  |
| `--body`   | none     | Request body (JSON string)                   |
| `--header` | none     | Additional header `Key:Value`, repeatable    |

There is **no `--broadcast` flag**. `x402-pay` always settles as part of the call; running the command transfers USDC.

***

## Worked example

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

# 402 Payment Required → signing payment (0.0005 USDC)
# 200 OK
# Response body:
# { "city": "Tokyo", "temperature_c": 24.5, ... }
# Settlement: 0xabc... → https://polygonscan.com/tx/0xabc...
```

For a seller-side integration that returns 402 in front of the route, see the [x402 Quickstart for Sellers](/payment-services/agentic-payments/x402/guides/quickstart-sellers).

***

## Implementation

<CardGroup cols={2}>
  <Card title="x402 Introduction" icon="bolt" href="/payment-services/agentic-payments/x402/intro">
    Protocol overview and facilitator list.
  </Card>

  <Card title="x402 Quickstart for Buyers" icon="code" href="/payment-services/agentic-payments/x402/guides/quickstart-buyers">
    Programmatic buyer integration without the CLI.
  </Card>

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

  <Card title="Balances and funding" icon="wallet" href="/payment-services/agentic-payments/cli/balances-and-funding">
    Confirm USDC balance before calling.
  </Card>
</CardGroup>
