x402 Micropayments for API Services


Most APIs charge money through a familiar ritual: create an account, enter a credit card, get an API key, track usage against a billing tier, worry about overages, maybe set up a Stripe webhook. For a human developer calling one API, this is fine. For an autonomous agent that might need to call dozens of services, it is a bottleneck.

The x402 protocol offers an alternative: pay-per-call pricing using stablecoin micropayments, with no accounts and no API keys. Caliper uses x402 for all paid endpoints. This post explains how x402 works, why it matters for agent-to-service payments, and what it looks like in practice.

The problem with API billing for agents

Traditional API billing assumes a human is in the loop — someone who creates an account, reviews pricing tiers, and manages credentials. This assumption breaks down with autonomous agents:

Account creation is a barrier. An agent discovering a new service via MCP cannot sign up for an account mid-task. It would need to fill out forms, verify an email, maybe enter payment information — none of which an LLM can do autonomously.

API key management is a liability. Distributing API keys to agents means managing secrets at scale. Keys get leaked, rotated, revoked. Each key needs scoped permissions. This overhead multiplies with every service the agent uses.

Billing tiers misalign with agent usage. Agents make bursty, unpredictable calls. A manufacturing QA agent might analyze 500 files on Monday and zero on Tuesday. Flat-rate tiers either overpay or underpay. Usage-based tiers still require accounts and billing cycles.

Multi-service agents face credential explosion. An agent that uses five services needs five accounts, five API keys, five billing relationships. At twenty services, this is unmanageable.

How x402 works

x402 is an HTTP-native payment protocol. It extends the familiar 402 Payment Required HTTP status code — which has existed since HTTP/1.1 but was never standardized for use — into a machine-readable payment flow.

The payment flow

Step 1: The client makes a request.

POST /tools/caliper_auto_stats HTTP/1.1
Host: caliper.fit
Content-Type: application/json

{"file_url": "https://example.com/model.stl"}

Step 2: The server responds with 402 and payment requirements.

HTTP/1.1 402 Payment Required
X-Payment: {"scheme":"exact","network":"base","maxAmountRequired":"100000",...}

The X-Payment header contains everything the client needs to construct a payment: the network (Base, an Ethereum layer 2), the token (USDC), the amount, and the payment recipient address.

Step 3: The client constructs and signs a payment.

The client (or a payment middleware) creates a USDC transfer on Base for the specified amount, signs it with the agent’s wallet, and includes the signed transaction in a retry of the original request:

POST /tools/caliper_auto_stats HTTP/1.1
Host: caliper.fit
Content-Type: application/json
X-Payment: <signed-payment-payload>

{"file_url": "https://example.com/model.stl"}

Step 4: The server verifies the payment and processes the request.

The server validates the signed payment, settles it on-chain, and returns the API response:

HTTP/1.1 200 OK
Content-Type: application/json

{"format":"stl_binary","vertices":1206,"triangles":2400,...}

The entire flow is two HTTP round trips: one to get the price, one to pay and receive the result.

What the agent needs

To participate in x402, an agent needs:

  • A wallet with USDC on Base (funded by the agent’s operator)
  • A signing capability to authorize payments
  • An x402 client library or middleware that handles the 402 → pay → retry flow

The agent does not need an account, an API key, or any prior relationship with the service. It discovers the price at request time and decides whether to pay.

Why stablecoins on a layer 2

x402 uses USDC (a US dollar stablecoin) on Base (an Ethereum layer 2 network) for practical reasons:

Stablecoins eliminate currency risk. The agent’s operator funds the wallet in dollars and knows what each API call costs in dollars. No cryptocurrency volatility.

Layer 2 fees are negligible. Base transaction fees are typically under $0.01. This makes micropayments viable — you can charge $0.001 per API call without the transaction fee exceeding the payment.

Settlement is fast. Base block times are approximately 2 seconds. The server can verify payment and respond within a single HTTP request-response cycle.

On-chain settlement is auditable. Every payment is recorded on a public blockchain. The agent’s operator can independently verify what was spent, when, and to whom — no vendor-side billing dashboard required.

x402 in Caliper

Caliper’s pricing model is simple:

  • caliper_detect_format — free (no payment required)
  • All analysis endpoints (caliper_auto_stats, caliper_stl_stats, etc.) — paid per call via x402

Format detection is free because it is useful as a routing step: an agent can check what kind of file it has before deciding whether to pay for full analysis. This mirrors how agents should work — gather cheap information first, then commit resources.

When calling a paid endpoint without payment, the server returns:

HTTP/1.1 402 Payment Required

With the payment details in the response. An x402-compatible client handles this automatically — the agent does not need to know about the payment protocol at all if the middleware handles it.

What this means for agent developers

If you are building an agent that calls Caliper (or any x402-enabled service):

No signup flow. Point your agent at the endpoint and go. The first call either succeeds (free endpoint) or returns a 402 with payment instructions.

Budget control at the wallet level. Fund the agent’s wallet with the amount you want to authorize. When the wallet runs dry, calls stop. No surprise invoices.

Per-call cost visibility. Each payment is a discrete transaction. You can compute exact cost per task by summing the payments made during that task’s execution.

Service composability. If your agent uses Caliper for geometry, another x402 service for image analysis, and a third for web search, all three share the same payment mechanism. One wallet, one protocol, no credential management.

The emerging ecosystem

x402 is part of a broader shift toward machine-to-machine payments. As agents become more autonomous — discovering services, evaluating options, executing multi-step workflows — the billing model needs to keep up.

The traditional approach (accounts, API keys, invoices) optimizes for human oversight. x402 optimizes for autonomous operation: the agent pays for what it uses, when it uses it, with no human in the loop.

Caliper is an early adopter of this model because the use case fits perfectly: AI agents making occasional, stateless API calls to analyze files they encounter during a task. No subscription makes sense. Pay-per-call with stablecoin micropayments does.

Try it

Call the free format detection endpoint (no payment needed):

curl -X POST https://caliper.fit/tools/caliper_detect_format \
  -H "Content-Type: application/json" \
  -d '{"file_url": "https://raw.githubusercontent.com/mikedh/trimesh/main/models/featuretype.STL"}'

For paid endpoints, use an x402-compatible client or add x402 middleware to your HTTP stack. The Getting Started with REST guide covers the full setup.