---
title: Monetize Gateway
description: 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.
---

import { Callout } from "fumadocs-ui/components/callout";
import { Tabs, Tab } from "fumadocs-ui/components/tabs";

# Monetize Gateway

<Callout title="Sell-side, self-serve" type="info">
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](/docs/concepts/facilitator) before the call reaches your backend. Live on
Base mainnet.
</Callout>

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](/docs/concepts/audit-chain). 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](/docs/concepts/authentication).

<Tabs items={["curl"]}>
<Tab value="curl">
```bash
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"
  }'
```
</Tab>
</Tabs>

The response carries the **gateway URL** you share with agents:

```json
{
  "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`

<Callout type="info">
Settlement is **non-custodial** either way — the USDC lands directly at the
destination you name, never in a CodeSpar pooled account.
</Callout>

| `payto.kind` | Money lands in | When to use |
|---|---|---|
| `provisioned` | The CodeSpar-derived wallet of the `consumer_id` you pass | You want a governed wallet you can also spend from, with receipts on both sides |
| `byo` | The `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:

```bash
curl https://api.codespar.dev/v1/paywalls/pw_.../stats \
  -H "authorization: Bearer $CODESPAR_API_KEY"
```

```json
{ "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](/docs/api/paywalls).

## 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.

## Related

- [Pay to Agent](/docs/concepts/pay-to-agent) — the other direction: an agent pays another agent by Agent ID.
- [Facilitator](/docs/concepts/facilitator) — how x402 verification and settlement work.
- [Audit chain](/docs/concepts/audit-chain) — the receipt every settlement seals.
