XenarchCrewaiPay.
Setup
XENARCH_API_TOKEN for this example. See the warning on the CrewAI page.
Code
main.py
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
CrewAI agent example: a research crew that uses the XenarchCrewaiPay tool to pay x402-gated content in USDC on Base.
XenarchCrewaiPay.
pip install 'xenarch[crewai]'
export XENARCH_PRIVATE_KEY=0xYOUR_PRIVATE_KEY
export OPENAI_API_KEY=sk-...
XENARCH_API_TOKEN for this example. See the warning on the CrewAI page.
"""CrewAI crew with the Xenarch payment tool."""
import os
import sys
from decimal import Decimal
from crewai import Agent, Crew, Task
from xenarch.tools import XenarchBudgetPolicy, XenarchCrewaiPay
pay = XenarchCrewaiPay(
private_key=os.environ["XENARCH_PRIVATE_KEY"],
budget_policy=XenarchBudgetPolicy(
max_per_call=Decimal("0.05"),
max_per_session=Decimal("0.50"),
),
)
researcher = Agent(
role="Research Agent",
goal="Read and summarize web pages, paying for them when required",
backstory=(
"You fetch pages with the xenarch_pay tool. It pays in USDC on Base "
"when a page answers HTTP 402, and returns the page content."
),
tools=[pay],
verbose=True,
)
url = sys.argv[1] if len(sys.argv) > 1 else "https://example.com/premium-article"
task = Task(
description=f"Fetch {url} with the xenarch_pay tool and summarize it.",
expected_output="A short summary, plus the amount paid and transaction hash if a payment was made.",
agent=researcher,
)
crew = Crew(agents=[researcher], tasks=[task], verbose=True)
if __name__ == "__main__":
print(crew.kickoff())
python main.py https://example.com/premium-article