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

# Pay-per-call Setup

> Make your first pay-per-call request in TypeScript or Python.

## Base URL

All examples use the dedicated x402 host:

```
https://x402-data-tools.prd.arrays.org
```

<Warning>
  Do not point x402 clients at `data-tools.prd.arrays.org`. That host is API-key auth and answers a bare `GET` with `401`, so the SDK never sees the 402 challenge. (It does return 402 if you add `Accept-Payment: x402`, but stock SDKs don't send that header.)
</Warning>

## Prerequisites

* An EVM wallet
* Funds on one of the supported rails: USDC deposited via [Circle Gateway](https://www.circle.com/gateway) (settles on Base), or USDC / USDT / USD1 in your wallet on BNB Chain
* `x402-fetch` (Node) or `x402-requests` (Python) installed — any x402 v2 client works

## Step 0 — See the 402 challenge (no wallet needed)

```bash theme={null}
curl -i "https://x402-data-tools.prd.arrays.org/api/v1/crypto/funding-rate?symbol=BTCUSDT"
```

```http theme={null}
HTTP/2 402
payment-required: eyJhY2NlcHRzIjpb...        (base64 x402 v2 payload)

{
  "success": false,
  "error": { "code": "PAYMENT_REQUIRED", "message": "x402 payment required for this endpoint" },
  "request_id": "...",
  "x402Version": 2,
  "accepts": [
    { "scheme": "exact", "network": "eip155:8453", "amount": "8000",
      "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
      "payTo": "0x9548E84DA0713a5c06b5D2CBB48d9670f1e27632", "maxTimeoutSeconds": 345600,
      "extra": { "name": "GatewayWalletBatched", "version": "1",
                 "verifyingContract": "0x77777777Dcc4d5A8B6E418Fd04D8997ef11000eE" } },
    { "scheme": "exact", "network": "eip155:56", "amount": "8000000000000000",
      "asset": "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
      "extra": { "name": "USD Coin", "assetTransferMethod": "permit2-exact", "..." : "..." } }
  ],
  "resource": { "url": "/api/v1/crypto/funding-rate", "mimeType": "application/json" }
}
```

Pick one `accepts` entry, sign it, and retry with the `PAYMENT-SIGNATURE` header. The SDKs below do this for you.

## TypeScript example

```bash theme={null}
npm install x402-fetch viem
```

```typescript theme={null}
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";
import { wrapFetchWithPayment } from "x402-fetch";

const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const client = createWalletClient({ account, chain: base, transport: http() });

// Wrap fetch with x402 payment support
const fetchWithPayment = wrapFetchWithPayment(fetch, client);

// Make a paid call — no API key needed
const res = await fetchWithPayment(
  "https://x402-data-tools.prd.arrays.org/api/v1/crypto/funding-rate?symbol=BTCUSDT"
);

console.log(await res.json());
```

That's it. The first call returns 402; `wrapFetchWithPayment` automatically signs, retries, and returns the data. The settlement result (tx, network, payer) is in the `PAYMENT-RESPONSE` header of the 200.

## Python example

```bash theme={null}
pip install x402-requests
```

```python theme={null}
import os
from x402_requests import X402Session
from eth_account import Account

account = Account.from_key(os.environ["PRIVATE_KEY"])
session = X402Session(account=account, chain="base")

res = session.get(
    "https://x402-data-tools.prd.arrays.org/api/v1/crypto/funding-rate",
    params={"symbol": "BTCUSDT"},
)
print(res.json())
```

## Cost math

How much will it actually cost?

| Use case | Calls / month | Tier | Cost |
| - | - | - | - |
| Daily funding-rate snapshot | 30 | \$0.008 | **\$0.24** |
| Hourly funding-rate for 10 pairs | 7,200 | \$0.008 | **\$57.60** |
| Crypto screener every 5 min | 8,640 | \$0.03 | **\$259.20** |

<Tip>
  At sustained high volume, a [subscription plan](/pricing) usually becomes cheaper than per-call nanopayment. Mix both: subscription for steady workloads, Nanopayment for spikes.
</Tip>

## Troubleshooting

Errors come back as `402` with the standard envelope; the facilitator's message is forwarded in `error.message`.

<AccordionGroup>
  <Accordion title="`401 UNAUTHORIZED` — API key is required">
    You are calling `data-tools.prd.arrays.org`. Switch to `x402-data-tools.prd.arrays.org`, or add `Accept-Payment: x402`.
  </Accordion>

  <Accordion title="`404 X402_NOT_SUPPORTED`">
    The route is not one of the 15 priced endpoints. See the [list](/nanopayment/overview#pricing-today).
  </Accordion>

  <Accordion title="`402 INSUFFICIENT_BALANCE`">
    Base rail: deposit USDC into Circle Gateway. BNB Chain rail: fund the signing wallet with the chosen asset.
  </Accordion>

  <Accordion title="`402 PAYMENT_ALREADY_USED`">
    Nonce reuse. Generate a fresh 32-byte nonce for every call.
  </Accordion>

  <Accordion title="`402 PAYMENT_VALIDITY_TOO_SHORT`">
    `validBefore - validAfter` must be at least `maxTimeoutSeconds` from the 402 (345600s on Base).
  </Accordion>

  <Accordion title="`402 PAYMENT_INVALID_SIGNATURE`">
    Signer must equal the token holder, and the EIP-712 domain must match the `extra` block of the `accepts` entry you chose (on Base that is the Gateway Wallet contract, not the USDC contract).
  </Accordion>

  <Accordion title="`400 PAYMENT_INVALID`">
    `PAYMENT-SIGNATURE` is not valid base64 or does not decode to an x402 v2 payload. Make sure `x402Version` is `2` — v1 clients fall back to the `X-PAYMENT` header, which is not accepted.
  </Accordion>
</AccordionGroup>


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