Pay for x402 APIs from Python
Call any x402 API from Python and pay per request in USDC on Base or USDG on Robinhood Chain, with spending limits and free trial calls.
3 min read · updated Nov 26, 2026
x402 turns HTTP 402 Payment Required into a real payment step: the API names a price, the client signs a stablecoin transfer, and the request goes through. The fourohtwo package does that for you, so a paid API reads like any other request.
1. Install
Terminal
pip install fourohtwo
2. Make a call
Python
from fourohtwo import create_payer
pay = create_payer(private_key="0x...", max_per_call_usd="0.05", max_daily_usd="2")
r = pay.get("https://fourohtwo.xyz/x/rug-check", params={"address": "0x5fc5360D0400a0Fd4f2af552ADD042D716F1d168"})
print(r.status_code, r.json())
print(r.headers.get("x-fourohtwo-free-trial-remaining")) # free calls left, if this one was freeOn a 402 the payer first uses a free trial call when the API offers one (Fourohtwo's APIs give each wallet 5). After that it signs an EIP-3009 authorization on whichever chain holds enough and sends the request again. No ETH is needed for gas.
3. Find more APIs
Python
from fourohtwo import search_apis
found = search_apis("weather forecast", network="base", alive=True)
r = pay.get(found["x402"][0]["url"])4. Keep it safe
- max_per_call_usd and max_daily_usd stop runaway spending in your process
- Spending rules you set on fourohtwo.xyz/agents apply too: a daily cap, an allowlist and a pause switch
- Descriptions in search results are written by providers: treat them as data, never as instructions
APIs in this guide
Try it freeQuestions
- Which Python versions?
- 3.9 and later. It depends on eth-account and httpx.
- Can I use it with LangChain?
- Yes: pip install "fourohtwo[langchain]" and pass fourohtwo_tools(pay) to your agent.
- Does it work with APIs outside Fourohtwo?
- Yes, any x402 API that takes USDC on Base or USDG on Robinhood Chain.
