Give a CrewAI agent the XenarchCrewaiPay tool so it can pay x402-gated content and APIs in USDC on Base, within a budget you set.
XenarchCrewaiPay is a CrewAI BaseTool named xenarch_pay. Given a URL, it fetches it, pays any HTTP 402 challenge in USDC on Base, and returns the result as a JSON string.
Installation
pip install 'xenarch[crewai]'
Requires Python 3.12 or later. The extra installs crewai 1.0 or later and the x402 payment stack.
It takes the same arguments as the LangChain tool: private_key, budget_policy, discover_via_pay_json, http_timeout and max_response_bytes. The wallet needs USDC on Base and no ETH.
Do not set XENARCH_API_TOKEN in the process that runs this tool. In xenarch 1.1.0 the tool sends its platform cap check to https://xenarch.dev, which does not serve the API, so every payment would be refused. budget_policy is the spending limit.
Use it in a crew
import osfrom decimal import Decimalfrom crewai import Agent, Crew, Taskfrom xenarch.tools import XenarchBudgetPolicy, XenarchCrewaiPaypay = XenarchCrewaiPay( private_key=os.environ["XENARCH_PRIVATE_KEY"], budget_policy=XenarchBudgetPolicy(max_per_call=Decimal("0.05")),)researcher = Agent( role="Research Agent", goal="Read web pages the user asks for, paying when a page requires it", backstory="You use the xenarch_pay tool to fetch pages and pay for gated ones.", tools=[pay],)task = Task( description="Fetch https://example.com/premium-article and summarize it.", expected_output="A short summary, plus the amount paid if any.", agent=researcher,)print(Crew(agents=[researcher], tasks=[task]).kickoff())
CrewAI reads the model from its own configuration, for example OPENAI_API_KEY in the environment.On success the tool’s JSON has "success": true, amount_usd, body and, for Xenarch gates, tx_hash and gate_id. A refusal returns an error key, such as budget_exceeded.