How an AI agent pays per API call with USDC (x402) — complete example

How can an autonomous agent buy data without a credit card, account or human? What does an HTTP 402 x402 flow look like end to end?

The agent requests a priced route. The server answers HTTP 402 with a PAYMENT-REQUIRED header listing accepted rails (USDC on Base eip155:8453, USDC on Solana), amount and payTo. The client signs an EIP-3009 transferWithAuthorization (no gas — the facilitator pays it), retries with PAYMENT-SIGNATURE, and gets 200 plus a PAYMENT-RESPONSE header with the settlement tx hash. @degenscan/intel and degenscan-intel do this automatically from a private key. Alternatively the agent buys a prepaid key once: POST /v1/keys/x402/pack_1k ($5 USDC → 1,000 calls, lifetime) and then sends X-API-KEY.

Price: $0.001 per call · free trial 100/day with X-Free-Trial: 1. Pay in USDC (Base or Solana) via x402, or send X-API-KEY.

curl

# 1) see the 402 requirements
curl -i 'https://intel.degenscan.io/v1/pulse'
# 2) pay it automatically with any x402 client, e.g. @x402/fetch, x402-axios, Coinbase AgentKit, or our SDKs
# 3) or buy a prepaid key once (answer the 402 with USDC):
curl -X POST 'https://intel.degenscan.io/v1/keys/x402/pack_1k'   # → { api_key, total_calls: 1000 }

JavaScript / TypeScript — npm i @degenscan/intel

import { Intel } from "@degenscan/intel";
const intel = new Intel({ privateKey: process.env.AGENT_WALLET_PK }); // wallet with a few USDC on Base
const p = await intel.pulse();                 // 402 → signed USDC transfer → 200, all inside the SDK
console.log(p._billing, p._payment_response); // { tool:"pulse", price_usd:0.001, method:"x402" }, tx receipt
const { api_key } = await intel.buyPack("pack_1k"); // optional: $5 once, then no per-call signatures

Python — pip install degenscan-intel

from degenscan_intel import Intel   # pip install "degenscan-intel[x402]"
intel = Intel(private_key=os.environ["AGENT_WALLET_PK"])
p = intel.pulse()
print(p["_billing"], p.get("_payment_response"))
key = intel.buy_pack("pack_1k")["api_key"]

See also