DEV Community

Cover image for Claude Pays Its Own Bills: MCP x402-fetch Tool for Autonomous API Payments
Wallet Guy
Wallet Guy

Posted on

Claude Pays Its Own Bills: MCP x402-fetch Tool for Autonomous API Payments

Claude agents can now autonomously pay for API calls using the x402-fetch tool in WAIaaS's MCP server. Instead of hitting rate limits or requiring manual API key management, your Claude agent automatically pays for premium services using cryptocurrency micropayments through the HTTP 402 payment protocol.

Why AI Agent Payments Matter

Today's AI agents hit API rate limits constantly. Whether calling premium data feeds, advanced AI models, or specialized services, agents either fail with 402 Payment Required errors or rely on pre-funded API keys that expire and need manual renewal. This breaks autonomous workflows and limits what agents can accomplish independently.

The x402 HTTP payment protocol solves this by letting agents pay per request automatically. When an API returns a 402 status, the agent pays the requested amount and retries the call seamlessly. No API keys, no rate limits, no human intervention.

WAIaaS MCP Integration: Claude + Crypto Payments

WAIaaS provides 45 MCP tools for Claude, including x402-fetch — a drop-in replacement for HTTP fetch that handles 402 payments automatically. Your Claude agent gets a self-custody wallet and can pay for any x402-enabled API using SOL, ETH, or other tokens.

Here's the complete setup:

1. Quick MCP Setup

npm install -g @waiaas/cli
waiaas init --auto-provision
waiaas start
waiaas quickset --mode mainnet
waiaas mcp setup --all
Enter fullscreen mode Exit fullscreen mode

This creates wallets on Ethereum and Solana, generates session tokens for Claude, and automatically configures your claude_desktop_config.json.

2. Claude Desktop Configuration

The setup command adds this to your Claude config:

{
  "mcpServers": {
    "waiaas": {
      "command": "npx",
      "args": ["-y", "@waiaas/mcp"],
      "env": {
        "WAIAAS_BASE_URL": "http://127.0.0.1:3100",
        "WAIAAS_SESSION_TOKEN": "wai_sess_eyJhbGciOiJIUzI1NiJ9...",
        "WAIAAS_DATA_DIR": "~/.waiaas"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Restart Claude Desktop, and your agent now has access to all 45 WAIaaS MCP tools including wallet management, DeFi actions, and autonomous payments.

3. How x402-fetch Works

When Claude needs to call a premium API, it uses the x402_fetch tool instead of regular HTTP requests:

User: "Get real-time Bitcoin price from this premium API: https://premium-api.example.com/btc"

Claude: I'll fetch the Bitcoin price and handle any payment requirements automatically.

[Claude calls x402_fetch tool with URL and headers]
→ API returns 402 Payment Required with payment details
→ WAIaaS pays the required amount (e.g., 0.001 SOL)
→ API returns the Bitcoin price data
→ Claude presents the result to user
Enter fullscreen mode Exit fullscreen mode

The payment happens transparently. Claude sees the API response, not the payment mechanics.

Policy-Controlled Spending

Since AI agents could potentially rack up unlimited API costs, WAIaaS uses policy controls to limit x402 spending:

# Set spending limits for x402 payments
curl -X POST http://localhost:3100/v1/policies \
  -H 'Content-Type: application/json' \
  -H 'X-Master-Password: <password>' \
  -d '{
    "walletId": "<wallet-uuid>",
    "type": "X402_ALLOWED_DOMAINS",
    "rules": {
      "domains": ["premium-api.example.com", "*.openai.com"]
    }
  }'

# Combine with spending limits
curl -X POST http://localhost:3100/v1/policies \
  -H 'Content-Type: application/json' \
  -H 'X-Master-Password: <password>' \
  -d '{
    "walletId": "<wallet-uuid>",
    "type": "SPENDING_LIMIT",
    "rules": {
      "instant_max_usd": 1,
      "daily_limit_usd": 10,
      "monthly_limit_usd": 50
    }
  }'
Enter fullscreen mode Exit fullscreen mode

This allows Claude to pay for API calls up to $1 instantly, with daily/monthly caps and domain restrictions. Higher amounts require approval through your configured notification channels.

Real-World Use Cases

Data Analysis Agent: Claude autonomously purchases premium market data, weather APIs, and satellite imagery to complete complex research tasks without hitting free tier limits.

AI-to-AI Services: Your Claude agent pays other AI services (GPT-4 vision, specialized models, computation resources) directly with cryptocurrency, enabling multi-agent workflows.

Dynamic API Access: Instead of managing dozens of API keys with different billing cycles, Claude pays per request only for what it needs, when it needs it.

Multi-Chain Payment Support

WAIaaS supports payments on 18 networks across Ethereum and Solana ecosystems. The x402-fetch tool automatically selects the appropriate token based on the API's payment requirements:

  • Ethereum: ETH, USDC, USDT
  • Solana: SOL, USDC
  • Layer 2s: Polygon, Arbitrum, Optimism, Base

Payment amounts are typically small (cents to dollars per API call), making this practical for high-frequency agent usage.

Security and Monitoring

All x402 payments go through WAIaaS's 7-stage transaction pipeline with policy enforcement, real-time monitoring, and approval workflows. You can track agent spending in the Admin Web UI at http://localhost:3100/admin and receive notifications for payments above your instant thresholds.

The default-deny policy system means agents can only pay whitelisted domains unless you explicitly configure broader access.

Quick Start: Give Claude Payment Powers

  1. Install WAIaaS: npm install -g @waiaas/cli && waiaas init --auto-provision
  2. Start daemon: waiaas start
  3. Create wallets: waiaas quickset --mode mainnet (creates ETH + SOL wallets)
  4. Setup MCP: waiaas mcp setup --all (auto-configures Claude)
  5. Fund wallet: Transfer some ETH/SOL to your agent wallet addresses
  6. Test: Ask Claude to "fetch data from any premium API URL" and watch it handle 402 payments automatically

Your Claude agent now autonomously pays for API access using its own cryptocurrency wallet, with policy controls ensuring responsible spending.

For more advanced MCP configurations and payment policies, check out How to Give Claude Desktop a Crypto Wallet in 60 Seconds and Build Trading Bots That Actually Work: WAIaaS Policy Engine Deep Dive.

What's Next

Start with x402 payments for your Claude workflows, then explore WAIaaS's full DeFi toolkit including automated trading, yield farming, and cross-chain bridging. The same MCP tools that enable autonomous payments also give Claude complete onchain capabilities.

Ready to try autonomous AI payments? Get started at GitHub or learn more at waiaas.ai.

Top comments (0)