AgentKit ships an x402 action provider (x402ActionProvider) that reads a 402, pays it from the AgentKit wallet and retries. It gives the agent the actions make_http_request, retry_http_request_with_x402, make_http_request_with_x402 and discover_x402_services. Point it at https://router-production-ab89.up.railway.app/route/paid.
// Coinbase AgentKit + X402 Router. npm i @coinbase/agentkit viem (run with tsx; tested with @coinbase/agentkit 0.10.4)
// Note: strict `tsc` can flag viem type mismatches/depth here (AgentKit pins its own viem); the code runs fine under tsx.
// AgentKit's built-in x402 action provider pays x402 v2 endpoints with your wallet. It gives the agent the actions
// make_http_request, retry_http_request_with_x402, make_http_request_with_x402 and discover_x402_services.
import { AgentKit, ViemWalletProvider, x402ActionProvider } from "@coinbase/agentkit";
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { base } from "viem/chains";
const walletProvider = new ViemWalletProvider(createWalletClient({
account: privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`), chain: base, transport: http(),
}));
const agentKit = await AgentKit.from({ walletProvider, actionProviders: [x402ActionProvider()] });
// (AgentKit's main branch adds x402ActionProvider({ registeredServices: [...], maxPaymentUsdc }) to whitelist services
// and cap spend; use it once it is in a release.)
// Direct call, no LLM: the provider reads the 402, signs 0.01 USDC on Base and retries.
const provider = x402ActionProvider();
console.log(await provider.makeHttpRequestWithX402(walletProvider, {
url: "https://router-production-ab89.up.railway.app/route/paid", method: "POST",
headers: { "content-type": "application/json" }, body: { q: "weather", chain: "Base" },
} as any));
// With an LLM: pass agentKit to a framework extension, e.g. getLangChainTools(agentKit) from @coinbase/agentkit-langchain.
Free trial: 3 free trial calls per wallet per day, no payment needed. Add the header X-402-Trial: <your wallet address> (EVM 0x… or Solana) to /route/paid and you get the same full ranked answer a paid call gets. Limits: 3 per wallet and 3 per IP per UTC day, from a shared pool of 100 a day. After that you get the normal 402. Try it · trial.sh · trial_call.py
Test status (17 Nov 2026): @coinbase/agentkit 0.10.4 with ViemWalletProvider: makeHttpRequestWithX402() was run against a local replay of the router's live unsigned 402 (exact captured PAYMENT-REQUIRED header and body); the client produced a valid x402 v2 payment for 0.01 USDC (amount 10000) on eip155:8453 to the router's payTo. The signed payment was captured locally and never sent, so no funds moved. LLM wiring via @coinbase/agentkit-langchain was not executed. Strict tsc may flag viem types because AgentKit pins its own viem version. The code runs under tsx.
Prices: /route/paid 0.01 USDC, /check/paid 0.002 USDC, /route free. x402 v2 on Base (eip155:8453) or Solana. Machine-readable: OpenAPI · /.well-known/x402 · llms.txt