# Pay per call with x402

No key, no account: pay each call in USDC on Base, $0.03 a credit.

## How it works

Call a dataset route without a key. The answer is `402` with the call's price in the `PAYMENT-REQUIRED` header ([x402](https://x402.org/) version 2). Your client signs a USDC payment of exactly that amount on Base, then sends the same request again with it in `PAYMENT-SIGNATURE`. The data comes back with the on-chain receipt in `PAYMENT-RESPONSE`.

```ts
import { wrapFetchWithPayment, x402Client } from "@x402/fetch"
import { registerExactEvmScheme } from "@x402/evm/exact/client"
import { privateKeyToAccount } from "viem/accounts"

const client = new x402Client()
registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.WALLET_KEY) })
const pay = wrapFetchWithPayment(fetch, client)

const response = await pay("https://api.gloom.sh/v1/macro/cpi")
```

Any x402 version 2 client works the same way.

## Price

A call costs its [credits](https://gloom.sh/datasets/docs/credits) at $0.03 each: CPI is 1 credit, $0.03; a company KPI lookup is 2, $0.06. [Price a call](https://api.gloom.sh/v1/datasets/cost?endpoint=kpis.company&symbols=AAPL) for free first. A [plan](https://gloom.sh/datasets/pricing) costs less per credit.

## What settles

- Only answers are paid for. The payment settles after the call has its answer: an error or a [batch](https://gloom.sh/datasets/docs/batches) that reads no listing settles nothing.
- A batch is priced per listing it can read and settles in full.
- One signed payment pays for one call. Sending it again is refused, even when the first call settled nothing: sign a new one for each call.
- A paid call always answers in full. `If-None-Match` is ignored, so there is no free `304`.

## What it reads

- Every dataset a plan reads, [point in time](https://gloom.sh/datasets/docs/point-in-time) (`asOf`) too. News stories come 12 hours late; a plan reads them in real time.
- One wallet pays for up to 300 credits a minute, then `429 rate_limited`.
- Snapshot files, [exports](https://gloom.sh/datasets/docs/bulk), webhooks and the [MCP server](https://gloom.sh/datasets/docs/mcp) need a [key](https://gloom.sh/datasets/docs/authentication).

## Errors

- `402 payment_required`: no key, no payment. `PAYMENT-REQUIRED` says what to pay.
- `402 payment_invalid`: another amount or network, a bad signature, too little USDC, or a payment already used. Nothing was charged.
- `402 payment_failed`: refused at settlement, before any transfer. Nothing was charged; sign a new one.
- `503 payment_unconfirmed`: sent to settle, with no clear answer. The transfer may still land, and no data was sent. If it does, it is recorded under the `Request-Id`: write to hello@gloom.sh with it for a refund.

Each 402 body also says the price, the network and where these docs are, under `payment`. A request with a key never pays with x402.

- [Previous MCP](https://gloom.sh/datasets/docs/mcp)
- [Next Credits and limits](https://gloom.sh/datasets/docs/credits)
