> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ceramic.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Agentic Payments

> Pay for each Ceramic Search request with x402 through the Cloudflare Monetization Gateway, with no account or API key.

AI agents can pay for Ceramic Search per request, with no account and no API key. The Search API accepts payment through the [Cloudflare Monetization Gateway](https://blog.cloudflare.com/monetization-gateway/) using [x402](https://x402.org), an open protocol for paying over HTTP. Payments are made in USDC on Base.

## Prerequisites

To try the example, you need:

* Node.js 20 or later
* A wallet with USDC on **Base mainnet**. USDC on another chain or a testnet won't work.

<Card title="x402 Search Agent" icon="github" href="https://github.com/CeramicTeam/ceramic-x402-search-agent" arrow="true" horizontal>
  A complete example with a research agent, spending caps, and a step-by-step `curl` demo.
</Card>

## How it works

1. You send a search request without an API key.
2. The Gateway responds with `402 Payment Required` and a `PAYMENT-REQUIRED` header describing the price, network, and recipient.
3. Your client signs a USDC authorization for exactly that amount and retries the request with a `PAYMENT-SIGNATURE` header.
4. The Gateway verifies the payment, forwards the request to Ceramic, and returns the search results with a `PAYMENT-RESPONSE` receipt.

```mermaid theme={null}
sequenceDiagram
  participant Agent
  participant Gateway as Cloudflare Monetization Gateway
  participant API as Ceramic Search API
  Agent->>Gateway: POST /search
  Gateway-->>Agent: 402 + PAYMENT-REQUIRED
  Note over Agent: Sign USDC authorization
  Agent->>Gateway: POST /search + PAYMENT-SIGNATURE
  Gateway->>API: POST /search (paid)
  API-->>Gateway: 200 results
  Note over Gateway: Settle on Base
  Gateway-->>Agent: 200 results + PAYMENT-RESPONSE
```

A few things to know:

* **Failed searches cost nothing.** The Gateway only settles payment after a successful response.
* **You don't need ETH for gas.** The Gateway submits and pays for the on-chain transfer.
* **Your private key never leaves your client.** It signs a one-time authorization for the quoted amount, valid for a limited window.
* **The price comes from the `402` response.** Check the `PAYMENT-REQUIRED` header for the current price per search.
