X402 Payment-Protected AI Chat

Cryptocurrency-powered access to AI agents using micropayments

What is X402?

X402 is an open protocol for micropayments on the web that uses HTTP status code 402 (Payment Required) to enable automatic cryptocurrency payments. ElizaCloud integrates with X402 to provide pay-per-use access to AI agents using USDC payments.

$0.01 per request
Instant payments
Cryptographic proof
Getting Started

Option 1: Web Client

Use the integrated X402 chat client for a user-friendly interface with automatic payment handling.

Option 2: Direct API Access

For developers and automated systems, access the payment-protected API endpoints directly.

Web Client Features

Wallet Integration

Fund the smart wallet embedded in the web client for seamless payment processing

Supported: Coinbase Wallet

Automatic Payments

Payments are handled automatically for each message

Cost: $0.01 USDC per message

Real-time Chat

Streaming responses with payment tracking

Features: Message history, transaction logs

Multi-Network

Support for Base and Base Sepolia networks

Networks: Base (mainnet), Base Sepolia (testnet)

API Endpoint

Agent Chat Endpoint

URL: /api/x402/[agentId]/chat

Method: POST

Payment: $0.01 USDC per request

Network: Base Sepolia (testnet) or Base (mainnet)

Request Format

{
  "messages": [
    {
      "role": "user", 
      "content": "What is the current price of ETH?"
    }
  ],
  "id": "unique-session-id",
  "userId": "user-identifier",
  "selectedToolkits": ["defillama", "chainlink"]
}

Example Request

curl -X POST https://aurracloud.com/api/x402/00000000-0000-0000-0000-000000000001/chat \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {
        "role": "user",
        "content": "What is the current price of ETH?"
      }
    ],
    "id": "test-session",
    "userId": "test-user",
    "selectedToolkits": ["defillama"]
  }'
Payment Process

Step 1: Initial Request

When you make a request without payment, you'll receive a 402 Payment Required response:

{
  "error": "Payment Required",
  "payment": {
    "amount": "0.01",
    "currency": "USDC",
    "network": "base-sepolia",
    "receiver": "0x...",
    "instructions": "..."
  }
}

Step 2: Complete Payment

Use an X402-compatible client or wallet to complete the USDC payment. The payment creates a cryptographic proof that can be used to access the protected resource.

Step 3: Access with Payment Proof

Retry your request with the payment proof in the X-PAYMENT header to access the protected content:

{
  "messages": [...],
  "reasoning": "The agent's thought process",
  "toolCalls": [...],
  "usage": {
    "inputTokens": 50,
    "outputTokens": 150,
    "totalTokens": 200
  }
}
Available Agent IDs
  • 00000000-0000-0000-0000-000000000001 - Base agent with customizable toolkits
  • • Any valid agent ID from the platform's agent database
Supported X402 Clients

Web Clients

  • Built-in Web Client: Use the /x402 route
  • x402-fetch: JavaScript library for browsers
  • Custom implementations: Using X402 protocol spec

Developer Tools

  • x402-axios: Axios adapter for Node.js
  • CDP AgentKit: For AI agents with X402
  • Protocol libraries: Multiple language support
Available Toolkits

When chatting with agents, you can specify which toolkits to enable:

Core Toolkits

  • defillama: DeFi analytics and token data
  • chainlink: Price feeds and market data
  • coinbase: Trading and wallet operations

Specialized

  • • Additional toolkits available based on agent configuration
  • • Custom toolkits for specific use cases
  • • Tool permissions controlled per agent
Network Configuration

Testnet (Base Sepolia)

Network: base-sepolia

Currency: USDC (testnet)

Cost: $0.01 per request

Use for: Testing and development

Mainnet (Base)

Network: base-mainnet

Currency: USDC

Cost: $0.01 per request

Use for: Production applications

Wallet Requirements

To use X402 payments, you need:

Wallet Setup

  • • Compatible wallet (MetaMask, Coinbase Wallet, etc.)
  • • Base or Base Sepolia network configured
  • • Sufficient USDC balance for payments
  • • Small amount of ETH for gas fees

Payment Process

  • • Automatic payment handling via web client
  • • Manual payment for API integration
  • • Cryptographic proof generation
  • • Transaction verification
Payment Tracking & Analytics

All payments are tracked and associated with:

Payment Information

  • • Payer wallet address
  • • Transaction hash
  • • Network used
  • • Timestamp and amount

Usage Analytics

  • • Message token usage
  • • Tool invocations
  • • Response quality metrics
  • • Cost per interaction
Troubleshooting

Common Issues

  • Payment fails: Check USDC balance and network connection
  • Network errors: Verify Base network is configured in wallet
  • High gas fees: Wait for lower network congestion
  • Transaction stuck: Check Base network status

Ready to Try X402 Payments?

Experience the future of micropayments for AI services

    We use cookies to enhance your experience, analyze site usage, and personalize content.

    AurraCloud - a Monemetrics Product