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

# Pay per request with x402

> Call DexPaprika endpoints without an API key by paying per request in USDC on Base with the x402 protocol. Read the 402 challenge, cap what your client may spend, and pay from TypeScript.

`x402.dexpaprika.com` serves the DexPaprika REST endpoints for a payment per request, in USDC on Base. There is no API key, account or signup: the endpoint answers your first request with HTTP `402 Payment Required`, your client signs a USDC payment, sends the request again, and gets the data.

It is built for AI agents and scripts that hold a wallet and call now and then, and for reaching endpoints that need a paid plan on the REST API, such as [token OHLCV](https://docs.dexpaprika.com/tutorials/token-ohlcv.md), [token indicators](https://docs.dexpaprika.com/tutorials/technical-indicators.md) and [pool transactions](https://docs.dexpaprika.com/tutorials/pool-transactions.md), without a subscription. If you call DexPaprika every day, a [free API key](https://console.dexpaprika.com) or a [plan](https://dexpaprika.com/api/pricing) fits better. To pay on Tempo instead of Base, see [MPP](https://docs.dexpaprika.com/ai-integration/mpp.md).

## What you need

* A wallet with USDC on Base. You don't need ETH for gas: you sign a USDC transfer authorization and the facilitator submits it on chain.
* Node.js 18 or later for the TypeScript example.

> [!WARNING]
>
> Use a separate wallet that holds only what you are willing to spend, and set a spending cap in your client. The cap is shown in [step 2](#step-2-pay-from-typescript).

## Endpoints and price

The paths, parameters and JSON responses are the same as on `api.dexpaprika.com`, so every [tutorial](https://docs.dexpaprika.com/tutorials/tutorial_intro.md) and the [API reference](https://docs.dexpaprika.com/api-reference/introduction.md) apply. Swap the host and the payment replaces the key.

> [accordion] Paid endpoints
>
> * `GET /networks`
> * `GET /search`
> * `GET /stats`
> * `GET /pools/search`
> * `GET /tokens/search`
> * `GET /networks/{network}/dexes`
> * `GET /networks/{network}/multi/prices`
> * `GET /networks/{network}/pools/search`
> * `GET /networks/{network}/pools/{pool_address}`
> * `GET /networks/{network}/pools/{pool_address}/ohlcv`
> * `GET /networks/{network}/pools/{pool_address}/transactions`
> * `GET /networks/{network}/pools/{pool_address}/indicators`
> * `GET /networks/{network}/tokens/search`
> * `GET /networks/{network}/tokens/{token_address}`
> * `GET /networks/{network}/tokens/{token_address}/ohlcv`
> * `GET /networks/{network}/tokens/{token_address}/indicators`

Every 402 states its own price. The current price list is on [x402.dexpaprika.com](https://x402.dexpaprika.com), and agents can read it from:

* [`/openapi.json`](https://x402.dexpaprika.com/openapi.json): the OpenAPI spec with a price on every operation
* [`/.well-known/x402`](https://x402.dexpaprika.com/.well-known/x402): the list of paid resources
* [`/.well-known/agent-payments`](https://x402.dexpaprika.com/.well-known/agent-payments): price, asset and network per endpoint

## Step 1: read the challenge

Request any paid endpoint without paying. The payment terms come back base64-encoded in the `PAYMENT-REQUIRED` header:

```bash theme={null}
curl -s -D - -o /dev/null \
  "https://x402.dexpaprika.com/networks/solana/tokens/So11111111111111111111111111111111111111112" \
  | grep -i '^payment-required:' | cut -d' ' -f2 | tr -d '\r' | base64 --decode | jq '.accepts'
```

```json theme={null}
[
  {
    "scheme": "exact",
    "network": "eip155:8453",
    "amount": "5000",
    "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    "payTo": "0x7eA2dCB09b3eBCFb9Ee1195C9587f944d8067Bc9",
    "maxTimeoutSeconds": 300,
    "extra": { "name": "USD Coin", "version": "2" }
  }
]
```

| Field | Meaning |
| - | - |
| `network` | `eip155:8453` is Base mainnet |
| `asset` | The USDC contract on Base |
| `amount` | The price in USDC base units. USDC has 6 decimals, so `5000` is 0.005 USDC |
| `payTo` | The DexPaprika address that receives the payment |
| `maxTimeoutSeconds` | How long a signed payment stays valid |

The same header carries a `resource` object with a description of what the endpoint returns, and a `bazaar` extension with the input and output schema. Agents can use both to decide whether the call is worth paying for.

## Step 2: pay from TypeScript

Install the x402 client packages and viem:

```bash theme={null}
npm install @x402/fetch @x402/evm viem
```

Save this as `pay.mjs`:

```javascript theme={null}
import { wrapFetchWithPaymentFromConfig, decodePaymentResponseHeader } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.PRIVATE_KEY);

const fetchWithPayment = wrapFetchWithPaymentFromConfig(fetch, {
  schemes: [{ network: "eip155:8453", client: new ExactEvmScheme(account) }],
  // Refuse any single payment above 1 cent.
  spendControls: { maxAmountPerPayment: "$0.01" },
});

const url =
  "https://x402.dexpaprika.com/networks/solana/tokens/So11111111111111111111111111111111111111112";
const res = await fetchWithPayment(url);
const data = await res.json();
console.log(res.status, data.symbol, data.summary?.price_usd);

const receipt = res.headers.get("payment-response");
if (receipt) console.log(decodePaymentResponseHeader(receipt));
```

Run it with the wallet's private key in the environment:

```bash theme={null}
PRIVATE_KEY=0xYOUR_PRIVATE_KEY node pay.mjs
```

```text theme={null}
200 SOL 70.88459090448607
{
  success: true,
  payer: '0xYourWalletAddress',
  transaction: '0x591bd6404567a1bb269c40ccd9eaf98b76e9286eabb6bfc23e17b6040590667b',
  network: 'eip155:8453'
}
```

The wrapper makes the first request, reads the 402, signs the payment and retries. The `payment-response` header on the paid response holds the settlement: `transaction` is the USDC transfer on Base, which you can look up on [BaseScan](https://basescan.org).

`spendControls` is the safety net. If an endpoint asks for more than `maxAmountPerPayment`, the client throws before it signs anything. With the cap set to `$0.001`, below the price:

```text theme={null}
Error: Failed to create payment payload: All payment requirements were rejected by spendControls.maxAmountPerPayment ($0.001, including USDC). Raise maxAmountPerPayment, set it to false to disable, set allowedAssets[].maxAmountPerPayment for a per-asset atomic cap, or set spendControls: false to disable all spend controls.
```

## Errors you don't pay for

A request with a bad parameter or for something that doesn't exist is refused before the payment challenge, so your client never pays for it.

A parameter value that isn't allowed gets `400`:

```json theme={null}
{"error":"invalid_param","message":"invalid query param: interval (must be one of [1m 5m 10m 15m 30m 1h 6h 12h 24h])","param":"interval"}
```

An unknown network, token or pool gets `404`:

```json theme={null}
{"type":"https://dexpaprika.com/problems/upstream-not-found","title":"Upstream Not Found","status":404,"code":"upstream_not_found","detail":"upstream returned 404 for the requested resource","instance":"/networks/solana/tokens/NotARealTokenAddress1111111111111111111111","upstream_status":404}
```

The allowed values for each parameter are in the [API reference](https://docs.dexpaprika.com/api-reference/introduction.md) and in the `bazaar` schema of the 402.

## Next steps

> [card] [Pay with MPP on Tempo](https://docs.dexpaprika.com/ai-integration/mpp.md)
>
> The same endpoints, paid with the Machine Payments Protocol on Tempo.

> [card] [Get an API key](https://console.dexpaprika.com)
>
> For daily use, a free key in the DexPaprika console, with plans on the [pricing page](https://dexpaprika.com/api/pricing).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.