✦ Cloudflare Workers · Durable Objects · MPP
Spin up a fully-featured pay-per-call agent API in 2 minutes. Auth, billing, reputation — all in one file.
click to copy
What makes it different
Every design decision optimises for autonomous agents calling your API at scale — zero human in the loop, zero trust violations.
All charging happens inside a single Durable Object with blockConcurrencyWhile. Ten concurrent calls on a 100mc balance? Exactly one wins. Every time.
Raw bearer tokens are never persisted. A full KV or DO dump exposes zero live keys. The token lives only at mint time and in the holder's memory.
One /v1/signup endpoint accepts Tempo stablecoin, Stripe card, or both simultaneously via Machine Payments Protocol. x402 clients work unchanged.
A key minted without explicit scopes can call nothing. Every endpoint maps to exactly one scope. No implicit all-access, ever.
The Worker never decides cost. It passes call_type to the DO which owns the price table. No split billing authority. No future maintainer footguns.
Agents pay via MPP → verify on-chain → auto-mint key → start calling. No signup form, no email, no admin needed between deploy and first revenue.
The architecture
The Durable Object is the single source of truth for auth, pricing, scoping, and charging. The Worker is a thin router that converts HTTP → DO RPC.
// 1. Validate body first — no charge on bad shape const body = await parseBody(req); if (!body.query) return error(400, "no charge"); // 2. Auth + atomic charge via DO const auth = await authAndCharge(req, env, "search"); if (auth instanceof Response) return auth; // 3. Do the actual work const result = await doSearch(body.query); return json({ ok: true, result, balance_mcents: auth.record.balance_mcents });
// Single source of truth. Worker never touches this. const PRICE_MCENTS: Record<CallType, number> = { example: 100, // $0.001 search: 250, // $0.0025 read: 0, // free }; // One scope per endpoint. Default-deny. const SCOPE_FOR = { example: "example", search: "search", read: "read", };
Agent payments
Enable /v1/signup with Tempo or Stripe secrets.
Agents discover, pay, and call — fully autonomously via Machine Payments Protocol.
POST /v1/signup
Agent discovers the endpoint, no auth yet.
← 402 WWW-Authenticate: Payment method="tempo"
Server returns MPP challenge. Agent picks Tempo or Stripe.
Agent pays $0.10 on-chain or by card
Sub-second on Tempo. Standard processing on Stripe.
← 200 {"key":"mcp_...","balance_mcents":10000}
Key minted atomically. 100 calls included. Go.
Get started
POST /v1/example — paid endpoint (100mc)POST /v1/admin/mint — key managementPOST /v1/signup — MPP self-serve (opt-in)GET /v1/pricing — public price listGET /v1/health — liveness check100mc per call = $0.001. Mint 10,000mc for $0.10 of API credit. Set any price you want in the DO's PRICE_MCENTS table.
Paste any Cloudflare Worker handler. Claude rewrites it with validate-before-charge, atomic billing, and scoped auth — production-ready.
Powered by Claude via OpenRouter · no account required · your code is never stored
One command. One file. No database setup, no auth service, no payment processor boilerplate.