---
title: Pay for Service
description: Make paid requests to x402-enabled APIs using USDC
---

# Pay for Service

Call x402-enabled API endpoints with automatic USDC authorization on Base.

---

## Command

```bash
npx agnic@latest x402 pay <url> [-X <method>] [-d <json>] [-q <params>] [-h <json>] [--max-amount <n>] [--json]
```

---

## Options

| Option | Description |
|--------|-------------|
| `<url>` | Full URL of the x402-enabled API endpoint |
| `-X, --method <method>` | HTTP method (default: GET) |
| `-d, --data <json>` | Request body as JSON string |
| `-q, --query <params>` | Query parameters as JSON string |
| `-h, --headers <json>` | Custom HTTP headers as JSON string |
| `--max-amount <amount>` | Max amount in USDC atomic units (1000000 = $1.00) |
| `--correlation-id <id>` | Group related operations |
| `--json` | Output as JSON |

---

## USDC Atomic Units

X402 uses USDC atomic units (6 decimals):

| Atomic Units | USD |
|-------------|-----|
| 1000000 | $1.00 |
| 100000 | $0.10 |
| 50000 | $0.05 |
| 10000 | $0.01 |

---

## Recommended Workflow

1. **Check requirements first** (optional but recommended):
   ```bash
   npx agnic@latest x402 details <url>
   ```

2. **Verify balance**:
   ```bash
   npx agnic@latest balance --network base
   ```

3. **Make the paid request**:
   ```bash
   npx agnic@latest x402 pay <url> --json
   ```

---

## Examples

```bash
# Make a GET request (auto-pays)
npx agnic@latest x402 pay https://example.com/api/weather

# Make a POST request with body
npx agnic@latest x402 pay https://example.com/api/sentiment \
  -X POST -d '{"text": "I love this product"}'

# Limit max amount to $0.10
npx agnic@latest x402 pay https://example.com/api/data --max-amount 100000

# Get JSON output
npx agnic@latest x402 pay https://example.com/api/weather --json
```

---

## Prerequisites

- Must be authenticated (`npx agnic@latest status` to check; use `--token`, `AGNIC_TOKEN`, or browser login)
- Wallet must have sufficient USDC balance on Base

---

## Error Handling

| Error | Solution |
|-------|----------|
| "Not authenticated" | Provide `--token`, set `AGNIC_TOKEN`, or run `npx agnic@latest auth login` |
| "Insufficient balance" | Fund wallet with USDC (`npx agnic@latest balance` to check) |
| "No X402 requirements found" | URL may not be an x402 endpoint |
| Invalid JSON in `--data` | Ensure the body is valid JSON before passing |
| HTTP 4xx/5xx from the API | Check the status code and response body |

---

## Next Steps

<Cards>
  <Card title="Search for Service" href="/docs/agentic-wallet/skills/search-for-service">
    Find x402 APIs in the bazaar
  </Card>
  <Card title="Check Balance" href="/docs/agentic-wallet/skills/check-balance">
    Check your balance after transacting
  </Card>
</Cards>
