Let a LangChain agent find and pay for APIs
Give a LangChain or LangGraph agent tools to search thousands of paid x402 APIs and pay for them from its own wallet, in Python or TypeScript.
4 min read · updated Nov 26, 2026
Most agents are limited to the tools someone wrote for them. With x402 an agent can find a paid API it has never seen, read the price and pay for one call. Fourohtwo packages that as four LangChain tools: search_apis, get_api, call_api and wallet_status.
Python
Terminal
pip install "fourohtwo[langchain]" langgraph
Python
from langgraph.prebuilt import create_react_agent
from fourohtwo import create_payer
from fourohtwo.langchain import fourohtwo_tools
pay = create_payer(private_key="0x...", max_per_call_usd="0.05", max_daily_usd="2")
agent = create_react_agent(llm, fourohtwo_tools(pay))
agent.invoke({"messages": [("user", "Find a weather API on Base and get tomorrow's forecast for London")]})TypeScript
Terminal
npm install fourohtwo zod @langchain/core @langchain/langgraph
TypeScript
import { createReactAgent } from "@langchain/langgraph/prebuilt";
import { createPayer } from "fourohtwo";
import { fourohtwoTools } from "fourohtwo/langchain";
const agent = createReactAgent({ llm, tools: fourohtwoTools(createPayer({ privateKey: process.env.AGENT_KEY!, maxPerCallUsd: "0.05" })) });What the agent sees
- search_apis: Fourohtwo APIs and the x402 directory, with price, networks and whether each answered our last check
- get_api: price, parameters, uptime and rating of one Fourohtwo API
- call_api: calls any x402 URL and pays within your limits, using free trial calls first
- wallet_status: address, balances on Robinhood Chain and Base, and today's spend
Limits live in your code and in the spending rules on fourohtwo.xyz/agents, not in the prompt, so a confused model can't overspend.
APIs in this guide
Try it freeQuestions
- Does it work with the Vercel AI SDK too?
- Yes: import { fourohtwoTools } from "fourohtwo/ai" and pass it as tools to generateText or streamText.
- Can it pay any API?
- Any x402 API that takes USDC on Base or USDG on Robinhood Chain. Fourohtwo's own APIs charge only when they answer.
- Is there an MCP server?
- Yes: npx fourohtwo-mcp gives Claude, Cursor and Codex the same four tools.
More guides
- Give your AI agent live stock prices
- Check a token for rug risk from an AI agent
- Pay for x402 APIs from Python
- Let an AI agent pay for APIs with USDC
- x402 on Base vs Robinhood Chain: which should your agent pay on?
- Track whale trades and DEX volume on Robinhood Chain
- Add paid APIs to Claude, Cursor or Codex with MCP
