AgnicPay

Pay for Service

Make paid requests to x402-enabled APIs using USDC

Pay for Service

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


Command

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

Options

OptionDescription
<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 payment in USDC atomic units (1000000 = $1.00)
--correlation-id <id>Group related operations
--jsonOutput as JSON

USDC Atomic Units

X402 uses USDC atomic units (6 decimals):

Atomic UnitsUSD
1000000$1.00
100000$0.10
50000$0.05
10000$0.01

  1. Check requirements first (optional but recommended):

    npx agnic@latest x402 details <url>
  2. Verify balance:

    npx agnic@latest balance --network base
  3. Make the paid request:

    npx agnic@latest x402 pay <url> --json

Examples

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

ErrorSolution
"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 payment requirements found"URL may not be an x402 endpoint
Invalid JSON in --dataEnsure the body is valid JSON before passing
HTTP 4xx/5xx from the APICheck the status code and response body

Next Steps

On this page