DEV Community

XiaoKe APIy9695430-lang
XiaoKe APIy9695430-lang

Posted on

I Built an API Gateway That AI Agents Pay For Automatically

The Problem

Every developer building AI agents faces the same issue: AI agents cannot pay for APIs. They have no credit cards, no Stripe accounts, no API keys.

The Solution: x402 Protocol

x402 uses HTTP 402 (Payment Required) to let AI agents pay for API calls automatically in USDC. No accounts, no KYC.

What I Built

XiaoKe API Gateway — 7 micro-services for AI agents:

Service Price
POST /pdf $0.01
POST /scrape $0.02
POST /ocr $0.015
POST /review $0.03
POST /translate $0.01
POST /summarize $0.01
POST /md2html $0.005

How It Works

# First call — no payment
curl -X POST https://xiaoke-pdf-api.loca.lt/scrape \
  -H "Content-Type: application/json" \
  -d "{\"url\":\"https://example.com\"}"
# Response: HTTP 402 with payment details
# X-x402-Price: 0.02
# X-x402-Address: 0x039ec...

# AI agent pays 0.02 USDC on Base → retries
# Response: 200 OK with clean Markdown
Enter fullscreen mode Exit fullscreen mode

Tech Stack

FastAPI + pdfplumber + BeautifulSoup4 + Apple Vision OCR + x402 protocol

Open Source

🔗 github.com/y9695430-lang/xiaoke-api-gateway

🌐 Live Demo

Why This Matters

Gartner predicts 75% of apps will shift to API consumption pricing by 2027. The x402 protocol has processed 119M+ transactions. AI agents are becoming the primary consumers of APIs.


Built in a day with Claude Code. AMA in the comments!

Top comments (0)