x402-compatible payment integration guide for AI agents
Base URL: https://api.agentaigateway.com/v1
Network: Base Mainnet (eip155:8453) | Asset: USDC | Min Deposit: 20 USDC
This gateway is focused on Moltbot/OpenClaw agents using the xclaw02 skill.
XCLAW02_PRIVATE_KEYQuick setup:
npx xclaw02 openclaw init
# or
pip install xclaw02
xclaw02 openclaw init
This creates (or reuses) a wallet and saves config to ~/.openclaw/skills/xclaw02/.
Probe and pay x402 endpoints with the CLI:
xclaw02 probe https://api.agentaigateway.com/v1/deposit
xclaw02 pay https://api.agentaigateway.com/v1/deposit --max-amount 20
Here's the typical flow for an AI agent integrating with the gateway:
Check what models are available and their pricing:
curl -s https://api.agentaigateway.com/v1/models | jq '.data[0]'
Query your current credit balance (replace with your wallet address):
curl -s https://api.agentaigateway.com/v1/balance/0xYourWalletAddress
If your balance is insufficient, fund your wallet via x402. The first request returns 402 Payment Required with payment details in the Payment-Required header (V2 spec) or X-Payment-Required header (legacy). Sign the payment and retry with the X-Payment header:
# Step 1: Get payment requirements (returns 402)
curl -X POST https://api.agentaigateway.com/v1/deposit \
-H "Content-Type: application/json" \
-d '{"amount_usdc": 20}'
# Step 2: Sign and submit payment (handled automatically by x402 clients)
curl -X POST https://api.agentaigateway.com/v1/deposit \
-H "Content-Type: application/json" \
-H "X-Payment: <base64-signed-payment>" \
-d '{"amount_usdc": 20}'
With credits in your account, request a short-lived auth challenge, sign it, then call the chat completions endpoint:
# Step 4a: Request auth challenge
curl -s https://api.agentaigateway.com/v1/auth/challenge \
-H "X-Wallet-Address: 0xYourWalletAddress"
# Step 4b: Sign typed data (domain + types + payload) and call completions
curl -s https://api.agentaigateway.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-Wallet-Address: 0xYourWalletAddress" \
-H "X-Auth-Payload: <base64-auth-payload>" \
-H "X-Auth-Signature: <0x-signature>" \
-d '{
"model": "anthropic/claude-sonnet-4-20250514",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Tip: Check the X-Credits-Remaining response header to monitor your balance after each request.
For real-time output, add "stream": true to your request. The response uses Server-Sent Events (SSE) format:
SSE Format: Each chunk is prefixed with data: followed by a JSON object. The stream ends with data: [DONE].
# Streaming with curl (add -N for unbuffered output)
curl -N https://api.agentaigateway.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "X-Wallet-Address: 0xYourWalletAddress" \
-H "X-Auth-Payload: <base64-auth-payload>" \
-H "X-Auth-Signature: <0x-signature>" \
-d '{
"model": "anthropic/claude-sonnet-4-20250514",
"messages": [{"role": "user", "content": "Write a haiku about coding"}],
"stream": true
}'
The xclaw02 skill handles streaming automatically when integrated with agents.
| Endpoint | Method | Description |
|---|---|---|
/v1/models |
GET | List available models and pricing |
/v1/balance/:wallet |
GET | Check credit balance for a wallet address |
/v1/deposit |
POST | Fund wallet via x402 payment (returns 402 with requirements) |
/v1/auth/challenge |
POST | Get a short-lived nonce for signed completions auth |
/v1/chat/completions |
POST | OpenAI-compatible inference endpoint |
Official xclaw02 skill for OpenClaw agents
NPM package for xclaw02 CLI
Python package for xclaw02 CLI
Source code and documentation
Official x402 protocol specification
Coinbase Developer Platform x402 documentation
Machine-readable API documentation
Agent skill documentation