Skip to main content

Monetize Gateway

Charge AI agents per call for your API, MCP server, or any REST endpoint. Put a paywall in front of it, share a gateway URL, get paid in USDC over x402 — no signup, no card, no session.

2 min read
View MarkdownEdit on GitHub

Monetize Gateway

Sell-side, self-serve

The Monetize Gateway is how you charge agents. Put a paywall in front of an endpoint you own; an agent that calls it pays per request in USDC over x402 before the call reaches your backend. Live on Base mainnet.

A paywall is a thin x402 seller in front of one of your endpoints. You declare a price and where the money should land; CodeSpar issues an HTTP 402 challenge on every unpaid call, verifies the agent's signed payment, settles it on-chain, seals a receipt, and only then proxies the request to your upstream. Private headers stay private; there is no order, no session, and no account for the caller to create.

The flow

agent ──GET──▶ gw.codespar.dev/<slug> ──▶ 402 (price, payTo, network)
      ◀────────────────────────────────────┘
agent ──GET + X-PAYMENT──▶ gw.codespar.dev/<slug>
                            │ verify signature
                            │ settle USDC on Base  ──▶ your payTo
                            │ seal receipt
                            └──▶ proxy to your upstream ──▶ 200 + data

Every paid call settles USDC to the address you chose and closes with a hash-chained receipt. A caller that does not pay gets the 402 back; nothing reaches your upstream until the payment verifies.

Create a paywall

Admin auth required. See Authentication.

curl -X POST https://api.codespar.dev/v1/paywalls \
  -H "authorization: Bearer $CODESPAR_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "slug": "market-data",
    "name": "Market data API",
    "upstream_url": "https://api.yourservice.com/quote",
    "price": "0.01",
    "payto": { "kind": "provisioned" },
    "consumer_id": "your-consumer"
  }'

The response carries the gateway URL you share with agents:

{
  "id": "pw_...",
  "slug": "market-data",
  "price": "0.01",
  "currency": "USDC",
  "gateway_url": "https://gw.codespar.dev/market-data",
  "payto_kind": "provisioned",
  "active": true
}

Who gets paid: payto

Settlement is non-custodial either way — the USDC lands directly at the destination you name, never in a CodeSpar pooled account.

payto.kindMoney lands inWhen to use
provisionedThe CodeSpar-derived wallet of the consumer_id you passYou want a governed wallet you can also spend from, with receipts on both sides
byoThe payto.address you pass (a 0x EVM address)You already have a wallet and want the funds there directly

Pricing

price is a decimal string of USDC per call, minimum "0.01". Endpoint-level pricing: one paywall, one price. Charge different prices by creating more paywalls in front of different upstream paths.

Path passthrough

gw.codespar.dev/<slug> and gw.codespar.dev/<slug>/<path> both dispatch to the paywall; the trailing path is forwarded to your upstream_url. So a single paywall can front a whole API surface, charging the same price per call.

Earnings

Read what a paywall has earned — an aggregate over its settled payments:

curl https://api.codespar.dev/v1/paywalls/pw_.../stats \
  -H "authorization: Bearer $CODESPAR_API_KEY"
{ "settled_count": 128, "gross": "1.28", "last_settled_at": "2026-07-10T21:04:11Z" }

The dashboard's Machine payments page shows the same figure inline on each paywall.

Manage

  • GET /v1/paywalls — list your project's paywalls.
  • PATCH /v1/paywalls/:id — change name, upstream_url, price, or active (pause/resume).
  • DELETE /v1/paywalls/:id — remove it.

Full field and error reference: Paywalls API.

Also settles in Pix

The same per-call idea runs on the LATAM lane: a paywall priced in BRL settles in Pix under the same mandate and receipt model. USDC/x402 is the global, developer-facing slot; Pix is the Brazil slot of the same runtime.

  • Pay to Agent — the other direction: an agent pays another agent by Agent ID.
  • Facilitator — how x402 verification and settlement work.
  • Audit chain — the receipt every settlement seals.
Monetize Gateway | CodeSpar