Skip to main content
XenarchPay is a LangChain 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

Requires Python 3.12 or later. The extra installs langchain-core 0.2 or later and the x402 payment stack.

Create the tool

The tool keeps the key in memory. It does not read it from a file.
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. For platform caps, use XenarchPayer with agent_control_plane_url="https://api.xenarch.dev" as shown in the Python SDK.

What the tool returns

On success, the JSON has "success": true, amount_usd, pay_to, body and, for Xenarch gates, tx_hash, facilitator and gate_id. A URL that does not ask for payment returns "status": "no_payment_required" with the body. A refusal or failure returns an error key, such as budget_exceeded.

Use it in an agent

Any LangChain chat model with tool calling works in place of ChatOpenAI. LangGraph prebuilt agents accept XenarchPay directly. For a fixed payment step inside a StateGraph, use XenarchLangGraphPay and its as_node() method instead.

Full example

See the LangChain agent example.