DEV Community

ntriq-gh
ntriq-gh

Posted on

HTTP 402 + USDC: Pay-per-use AI APIs for Autonomous Agents

The Problem with API Keys for AI Agents

AI agents need to call external APIs autonomously. But traditional API key auth has a fundamental mismatch:

  • Who manages the keys? The agent can't sign up for accounts
  • How does billing work? Subscription tiers don't fit pay-per-task usage
  • What about multi-agent systems? Keys get shared, leaked, revoked

There's a better way: let agents pay directly, per request, with crypto.

x402: HTTP 402 as a Payment Protocol

The HTTP 402 status code has been "reserved for future use" since 1991. x402 finally uses it.

The flow:

Agent → POST /document-intel
Server → 402 Payment Required
        { amount: "0.05", currency: "USDC", network: "eip155:8453" }
Agent → EIP-3009 signature (gasless transfer authorization)
Server → Facilitator validates → 200 OK + result
Enter fullscreen mode Exit fullscreen mode

No API keys. No subscriptions. No gas fees. The payment IS the authentication.

ntriq AgentShop: 6 Endpoints, $0.01–$0.05

We built a document intelligence server on this protocol, running 100% local inference on a Mac Mini.

Endpoint Price Model
/document-intel $0.05 qwen2.5vl:7b
/invoice-extract $0.03 qwen2.5vl:7b
/screenshot-data $0.02 qwen2.5vl:7b
/alt-text $0.01 qwen2.5vl:7b
/pii-detect $0.02 qwen2.5:7b
/sentiment $0.01 qwen2.5:7b

Cost to run: $0 (local inference). Margin: ~100%.

Try It

# Step 1: Hit the endpoint — you'll get a 402 back
curl -X POST https://x402.ntriq.co.kr/sentiment \
  -H 'Content-Type: application/json' \
  -d '{"text": "This product is amazing"}'

# Response:
# { "x402Version": 1, "accepts": [{ "amount": "10000", "currency": "USDC" }] }

# Step 2: Sign with EIP-3009 and retry
# The x402 client library handles this automatically
Enter fullscreen mode Exit fullscreen mode

Why Local Inference?

  • Zero marginal cost: Every request is pure profit
  • No rate limits: Mac Mini handles concurrent requests
  • Privacy: Documents never leave our infrastructure
  • Speed: No network hop to OpenAI

qwen2.5vl:7b handles documents, invoices, and screenshots with accuracy comparable to GPT-4V for structured extraction tasks.

MCP Integration

ntriq-agentshop is available as a ClawHub skill. Any agent using OpenClaw or Claude can discover and use these endpoints automatically.

# Install via ClawHub
clawhub install ntriq-document-intelligence-mcp
Enter fullscreen mode Exit fullscreen mode

Links


Built on Mac Mini M4, running 24/7. No cloud bills.

Top comments (0)