XenarchPay.
Setup
XENARCH_API_TOKEN for this example. See the warning on the LangChain page.
Code
main.py
Run
ChatOpenAI for any LangChain chat model that supports tool calling.Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
LangChain agent example: a LangGraph ReAct agent that uses the XenarchPay tool to pay x402-gated content in USDC on Base.
XenarchPay.
pip install 'xenarch[langchain]' langgraph langchain-openai
export XENARCH_PRIVATE_KEY=0xYOUR_PRIVATE_KEY
export OPENAI_API_KEY=sk-...
XENARCH_API_TOKEN for this example. See the warning on the LangChain page.
"""LangChain agent with the Xenarch payment tool."""
import os
import sys
from decimal import Decimal
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent
from xenarch.tools import XenarchBudgetPolicy, XenarchPay
pay = XenarchPay(
private_key=os.environ["XENARCH_PRIVATE_KEY"],
budget_policy=XenarchBudgetPolicy(
max_per_call=Decimal("0.05"),
max_per_session=Decimal("0.50"),
),
)
agent = create_react_agent(
ChatOpenAI(model="gpt-4o-mini", temperature=0),
[pay],
prompt=(
"You are a research assistant. Use the xenarch_pay tool to fetch web "
"pages. It pays in USDC when a page requires payment. Report the "
"amount paid and the transaction hash with your answer."
),
)
if __name__ == "__main__":
url = sys.argv[1] if len(sys.argv) > 1 else "https://example.com/premium-article"
result = agent.invoke(
{"messages": [{"role": "user", "content": f"Fetch {url} and summarize it."}]}
)
print(result["messages"][-1].content)
python main.py https://example.com/premium-article
ChatOpenAI for any LangChain chat model that supports tool calling.