Skip to main content

Overview

x402 is an HTTP-native payment protocol that enables pay-per-request API access using USDC on Base Mainnet. With x402, you can access Messari endpoints without a Messari account or API key — simply pay per request with crypto. When to use x402:

AI Agents

Autonomous agents that need to query Messari data without managing API keys or subscriptions

Automated Pipelines

Data pipelines that require one-off or sporadic queries billed directly on-chain

One-Off Queries

Quick queries without signing up for an account or committing to a subscription

Supported Endpoints

The following endpoints accept x402 payments:
EndpointMethodPrice
/ai/v2/chat/completionsPOST$0.25 / request

Prerequisites

Before making a payment, ensure you have:
  • An EVM-compatible wallet (e.g. MetaMask, Coinbase Wallet)
  • USDC on Base Mainnet — a minimum of ~$1 is recommended to start
  • A small amount of ETH on Base Mainnet for gas fees

Bridge to Base

Use bridge.base.org to move USDC from Ethereum or another chain onto Base Mainnet.

How It Works

x402 follows a simple 3-step flow: Step 1: Make a request Send your request to the Messari API without an API key. The gateway responds with HTTP 402 Payment Required along with payment requirements (amount, currency, recipient address, network). Step 2: Sign & pay Your x402-enabled client signs a USDC TransferWithAuthorization EIP-3009 message using your wallet’s private key. No gas is required for the authorization itself — the gateway submits the on-chain transaction on your behalf. Step 3: Request fulfilled The gateway verifies the signed authorization, collects the USDC payment, and proxies your original request. The API response is returned as normal.

Quick Start (TypeScript)

Install the x402 fetch wrapper:
npm install @x402/fetch @x402/evm viem
Make your first pay-per-request call:
import { wrapFetchWithPaymentFromConfig } from '@x402/fetch';
import { ExactEvmScheme } from '@x402/evm';
import { privateKeyToAccount } from 'viem/accounts';

const account = privateKeyToAccount('0xYOUR_PRIVATE_KEY');

const fetchWithPayment = wrapFetchWithPaymentFromConfig(fetch, {
  schemes: [{ network: 'eip155:8453', client: new ExactEvmScheme(account) }],
});

const response = await fetchWithPayment('https://api.messari.io/ai/v2/chat/completions', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    messages: [{ role: 'user', content: 'What is the latest on Bitcoin?' }],
    verbosity: 'succinct',
    response_format: 'markdown',
    stream: false,
  }),
});

const data = await response.json();
console.log(data);
Never hardcode your private key in source code. Use environment variables: privateKeyToAccount(process.env.PRIVATE_KEY as \0x$`)`.

Troubleshooting

“Payment verification failed” Your wallet does not have sufficient USDC on Base Mainnet. Check your balance and ensure you have enough USDC plus a small amount of ETH for gas. “Unsupported network” You must use eip155:8453 (Base Mainnet). Payment sent but no response received On-chain confirmation can take ~30 seconds. If you do not receive a response after 60 seconds, check the transaction status on Basescan. If the transaction is confirmed but you still received no response, contact api@messari.io.