# x402

The Vaults.fyi API supports the [x402 payment protocol](https://www.x402.org/) for keyless, pay-per-request access using USDC on Base. This is ideal for AI agents and autonomous systems that need programmatic access without managing API keys.

## How it works

1. Send a request with the `x-402-auth: true` header (no API key needed)
2. Receive a `402 Payment Required` response with payment details
3. Sign a USDC payment on Base using your wallet
4. Resend the request with the `X-Payment` proof header
5. Receive a `200` response with data

{% hint style="info" %}
Use the [`x402`](https://www.npmjs.com/package/x402) Python or JS library to handle the payment flow automatically.
{% endhint %}

## Quick start

Install the x402 client library and make your first request:

{% tabs %}
{% tab title="JavaScript" %}

```javascript
import { wrapAxios } from "x402/axios";
import axios from "axios";
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";

const account = privateKeyToAccount(process.env.PRIVATE_KEY);
const walletClient = createWalletClient({
  account,
  chain: base,
  transport: http(),
});

const client = wrapAxios(axios, walletClient);

const response = await client.get("https://api.vaults.fyi/v2/vaults", {
  headers: { "x-402-auth": "true" },
});
```

{% endtab %}

{% tab title="Python" %}

```python
from x402.client import Client

client = Client(private_key=PRIVATE_KEY, chain="base")

response = client.get(
    "https://api.vaults.fyi/v2/vaults",
    headers={"x-402-auth": "true"},
)
```

{% endtab %}
{% endtabs %}

For a complete working example, see the [Agentic DeFi repo](https://github.com/WallfacerLabs/agentic_defi).

## Pricing

All prices are in USDC on Base, charged per request.

| Price  | Endpoints                                                                                |
| ------ | ---------------------------------------------------------------------------------------- |
| $0.005 | `/v2/networks`, `/v2/vaults`, `/v2/tags`, `/v2/assets`, `/v2/curators`                   |
| $0.01  | `/v2/vaults/{network}/{address}`, `/v2/vaults/{network}/{address}/performance`           |
| $0.02  | `/v2/detailed-vaults/{network}/{address}`, `/v2/positions/{address}`                     |
| $0.025 | `/v2/deposit-options/{address}`, `/v2/idle-assets/{address}`, `/v2/best-vault/{address}` |
| $0.05  | `/v2/transactions/*`, `/v2/transactions/rewards/claim/{address}`                         |
| $0.75  | `/v2/detailed-vaults` (paginated list of all vaults)                                     |
| Free   | `/v2/health`                                                                             |

{% hint style="warning" %}
`/v2/historical/*` endpoints are not available via x402 and require an API key.
{% endhint %}

Payment is in USDC raw units (6 decimals). For example, `5000` = $0.005 USDC. The `402` response always contains the current `maxAmountRequired`. Prices are subject to change.
