# How to pay the DeFi Intel Agent Gateway (x402 v2)

All services are paid micro-payments in USDC. Accepted on SEVEN EVM chains
(Base 8453, Ethereum 1, Polygon 137, Arbitrum 42161, Optimism 10, Avalanche 43114,
HPP 190415 — USDC.e) PLUS Stellar (stellar:pubnet, USDC SEP-41) — pick the
network you hold USDC on. There are NO accounts and NO API keys required for
per-call payment — you pay with any USDC wallet you already hold. The
`accepts[].network/asset/extra` + `eip712ByChain` in the 402 manifest tell
you exactly which USDC contract and EIP-712 domain to use per chain (Stellar
settles via the Built on Stellar / OpenZeppelin facilitator — Soroban auth).

## 1. Detect the 402 (read this first)

Every endpoint returns HTTP 402 + a base64 `PAYMENT-REQUIRED` header the first
time it is called without payment:

```bash
curl -s -i https://defi-intel-agent-gateway.gg-neo15.workers.dev/v1/text/language-tone-detect
# HTTP/2 402
# payment-required: <base64 x402 v2 manifest>
```

Decode the header (it is the canonical manifest; the JSON body is a copy):

```bash
curl -s https://defi-intel-agent-gateway.gg-neo15.workers.dev/v1/text/language-tone-detect | jq -r '.accepts[0]'
# { scheme:"exact", network:"eip155:8453", asset:"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
#   amount:"1000" (atomic: 1000000 = 1 USDC), payTo:"0x9625...7785" }
# .eip712  → the exact EIP-712 domain + types to sign (no ABI needed)
```

### MPP (Machine Payments Protocol) — pay with any MPP/x402 client
Every 402 also carries the standardized `WWW-Authenticate: Payment` header with
a full `evm.charge` challenge (mppx format): `Payment id=..., method="evm",
intent="charge", request="<base64url PaymentRequest>"`. MPP-native clients
(mppx, Cloudflare Agents `withX402Client` / `Mppx.create`) detect payment via
this header and pay directly — zero custom code. Pay by sending the signed MPP
Credential in the `Authorization: Payment <base64url>` header (or the same
EIP-3009 payload in `PAYMENT-SIGNATURE`); a successful payment returns a
`Payment-Receipt` header (tx hash) for audit. The `request` value mirrors the
x402 manifest (amount, USDC asset, recipient, chainId), so both surfaces stay
in sync.

## 2. Pay (three equivalent ways)

### A) Direct EIP-3009 (any EVM wallet, ~10 lines)
Sign a `TransferWithAuthorization` exactly as described by the manifest's
`.eip712` (domain + types), then resend the request with the base64
PaymentPayload in the `PAYMENT-SIGNATURE` header. Working clients: the shipped
SDK/plugins (defi-intel-agent-tools, agents/elizaos, agents/goat) and
`GET /v1/discovery` for the full catalog.

### B) Prepaid credits (no crypto — best for agents without a wallet)
POST /v1/keys/starter — pay $0.01 via the payment link in the 402 body, receive
an API key preloaded with $0.05 credit for ANY product. Then call with
`x-api-key: <key>`. No per-call signing.

### C) Facilitator (payAI / Dexter / CDP / HPP / Stellar)
POST /v1/facilitator/verify then /v1/facilitator/settle with the PaymentPayload
(scheme/network/asset/amount taken from the 402). The facilitator relays
settlement to the payTo address. Public facilitators:
- payAI: https://facilitator.payai.network
- Dexter (free, zero fee, gas sponsored): https://x402.dexter.cash
- HPP (EVM, USDC.e, exact+upto, gasless): https://facilitator.hpp.io
- Built on Stellar (Soroban, needs API key): https://channels.openzeppelin.com/x402

### D) Session (pay-as-you-go — best for recurring/polling agents)
POST /v1/session — pay a top-up once (default $0.05 USDC, via any of the three
methods above), get a session token, then call any product with
`x-session: <token>` (or `Authorization: Session <token>`). Each call debits
its price — NO per-call signing/settlement. Perfect for a poller (e.g.
base-gas-oracle every N minutes): fund once, then poll.

## 3. Free samples before paying
Send the `X-Trial: 1` header (or `?trial=1`) to get up to 5 free calls/day/IP
per product, so you can validate the output before spending USDC.

## Catalog
GET /v1/discovery (HTTP + MCP tools) — 40 products, prices in `price.amount` (USD).
MCP: connect to `https://defi-intel-agent-gateway.gg-neo15.workers.dev/.mcp` (streamable-http, initialize + tools/list).
