⛩️ tollbooth

Turn any API into a paid x402 API.
One YAML config, zero code.

How it works

1

Write a YAML config

Define upstreams, routes, and pricing rules. Match on request body, query params, or headers using glob patterns.

2

Run tollbooth

npx tollbooth start
3

Accept USDC payments

Your API now requires x402 payment via USDC before forwarding requests upstream. No changes to your existing service.

Config example

Price different models differently. Match on request body, query params, or headers using glob patterns. The whole gateway is a single YAML file — no compilation, no build step.

upstreams:
  anthropic:
    url: "https://api.anthropic.com"
    headers:
      x-api-key: "${ANTHROPIC_API_KEY}"

routes:
  "POST /ai/claude":
    upstream: anthropic
    path: "/v1/messages"
    match:
      - where: { body.model: "claude-haiku-*" }
        price: "$0.005"
      - where: { body.model: "claude-opus-*" }
        price: "$0.075"
    fallback: "$0.015"

Features

📄 YAML-first config

No code, no compilation step. AI-friendly declarative config that fits in a single file. Readable by humans, writable by LLMs.

💰 Dynamic pricing

Match on body fields, query params, or headers with glob patterns. Different prices per model, endpoint, or user tier.

🔀 Multiple upstreams

Proxy Anthropic, OpenAI, Dune, or any HTTP API from a single gateway. One config file, many backends.

🪝 Lifecycle hooks

onRequest, onSettled, onResponse, onError — inject custom logic at any point without forking the gateway.

⚡ x402 V2

Modern payment headers, auto-discovery at /.well-known/x402. Fully spec-compliant out of the box.

🌐 Multi-chain

Base, Solana, and any supported x402 network. Chain-agnostic by design — configure once, settle anywhere.

The x402 flow

Tollbooth sits in front of your API and handles the payment handshake automatically. Clients that can't pay get a 402. Clients that pay get proxied through.

Client───────────────→Tollbooth- - - - - - - -Upstream
GET /ai/claude
Client←───────────────Tollbooth- - - - - - - -Upstream
402 + price info
Client───────────────→Tollbooth───────────────→Upstream
signs USDC paymentforward request
Client←───────────────Tollbooth←───────────────Upstream
responseresponse

Use cases

💸

Monetize your API

Wrap any existing HTTP API with per-request USDC payments. Deploy tollbooth in front of your service in minutes — no changes to your backend required.

🤖

Monetize your AI

Put a tollbooth in front of your fine-tuned model. Let other agents pay per request to use your model. YAML config, running in production, in under five minutes.

🏪

Build an API marketplace

Multiple upstreams, one gateway, dynamic pricing per endpoint. Route to different backends based on the request — all from a single config file.