# Give Your AI Agent Pay-Per-Use Access to the Cambrian API By using x402, agents like Claude Code, Codex, Hermes, and OpenClaw can access the Cambrian API without an API key. All Cambrian endpoints and the Cambrian CLI support pay-per-request via the [x402 payment protocol (v2)](https://x402.org/) with USDC on Base. x402 enables instant, low-cost payments for digital services. It’s designed for API monetization, agentic commerce, paywalled content, and any scenario where traditional payment methods are too slow or expensive. ## How it works 1. An AI agent sends an HTTP request and receives `402 Payment Required` 2. The AI agent pays using USDC on Base (chain ID 8453) 3. API access is immediately granted **Price**: $0.05 per request ## Quick start: Use the Cambrian API & pay with x402 ### Typescript ```bash npm install @x402/core @x402/fetch @x402/evm viem npm pkg set type=module export EVM_PRIVATE_KEY="0xYOUR_PRIVATE_KEY" ``` ```tsx import { x402Client } from "@x402/core/client"; import { ExactEvmScheme } from "@x402/evm/exact/client"; import { wrapFetchWithPayment } from "@x402/fetch"; import { privateKeyToAccount } from "viem/accounts"; const signer = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`); const client = new x402Client(); client.register("eip155:*", new ExactEvmScheme(signer)); const fetchWithPayment = wrapFetchWithPayment(fetch, client); const response = await fetchWithPayment( "https://x402.cambrian.org/evm/price-current" ); const data = await response.json(); console.log(data); ``` Run it: ```bash npx tsx index.ts ``` (Or `node index.ts` on Node.js ≥ 22.18, which runs TypeScript natively.) ### Python ```bash pip install "x402[httpx,evm]" ``` ```python import asyncio, os from eth_account import Account from x402 import x402Client from x402.http.clients import x402HttpxClient from x402.mechanisms.evm import EthAccountSigner from x402.mechanisms.evm.exact.register import register_exact_evm_client async def main(): client = x402Client() account = Account.from_key(os.getenv("EVM_PRIVATE_KEY")) register_exact_evm_client(client, EthAccountSigner(account)) async with x402HttpxClient(client) as http: response = await http.get("https://x402.cambrian.org/evm/price-current") print(response.json()) asyncio.run(main()) ``` ### Payment flow 1. Send a normal request to the endpoint (no API key needed) 2. Server returns `402 Payment Required` with payment details 3. The x402 SDK automatically signs a payment authorization with your wallet 4. The SDK resubmits the request with the signed payment 5. The server verifies payment and returns the API response The x402 SDK handles steps 2–5 automatically.