# Pay per call (x402)

An agent doesn't need a Layer account. It can call the API with no key and pay for each answer in USDC on Base, using [x402](https://x402.org). You get the same answer an account with a key gets, and you're charged only when the call succeeds: a `400` or any other error costs nothing.

A [free key](https://uselayer.sh/dashboard) is still the cheaper way for anything you'll call often: it has no per-call price.

## Prices

| Endpoint | What it answers | Price per call |
|---|---|---|
| `GET /v0/match` | One market's twin on another venue, with both venues' live prices | $0.02 |
| `POST /v0/match` | The same for up to 50 markets | $0.25 |
| `GET /v0/matches` | Every live match, with prices and the best trade | $0.10 |
| `GET /v0/settlements` | How matched pairs settled on both venues | $0.05 |
| `POST /v0/profit` | Profit after both venues' fees for prices you send | $0.01 |
| `GET /v0/quote` | The most contracts of one matched market that clear your edge, from both live books | $0.02 |
| `POST /v0/size` | The largest size that clears your edge, from order books you send | $0.02 |

Every other endpoint needs a key. Inputs and answers are the same as in the [API reference](https://uselayer.sh/docs/api.md).

## How it works

1. Call the endpoint with no key. Layer answers `402 payment_required`, with the price, the network (Base) and where to pay in the `PAYMENT-REQUIRED` header.
2. Your x402 client signs a USDC payment for that amount and calls again with it in the `PAYMENT-SIGNATURE` header.
3. Layer answers. Only then is the payment settled; the `PAYMENT-RESPONSE` header carries the transaction.

```bash
curl -i "https://uselayer.sh/v0/match?venue=kalshi&market_id=KXFEDDECISION-26DEC-H0"
# HTTP/2 402
# payment-required: eyJ4NDAyVmVyc2lvbiI6Mi…
```

## From code

Any x402 client works. With [`@x402/fetch`](https://www.npmjs.com/package/@x402/fetch) and a wallet that holds USDC on Base:

```typescript
import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`);
const fetchWithPayment = wrapFetchWithPaymentFromConfig(fetch, {
  schemes: [{ network: "eip155:8453", client: new ExactEvmScheme(account) }],
});

const res = await fetchWithPayment("https://uselayer.sh/v0/matches?category=sports&q=nba");
console.log(await res.json());
```

From an AI assistant, an MCP wallet such as [AgentCash](https://agentcash.dev) pays for you: ask it to call `https://uselayer.sh/v0/match` for a market.

## Where agents find Layer

- [Coinbase's x402 Bazaar](https://docs.cdp.coinbase.com/x402/bazaar), the catalog agents search for paid APIs.
- [x402scan](https://www.x402scan.com/server/ccdd3552-9376-4537-91f0-e112a8bb3f1b), which AgentCash reads.
- [`/openapi.json`](https://uselayer.sh/openapi.json): every paid endpoint, its inputs, an example answer and its price.

Questions, or a price that doesn't work for you: [david@uselayer.sh](mailto:david@uselayer.sh?subject=Pay%20per%20call).
