AI Agent Framework Payments: LangChain, CrewAI, AutoGen & LlamaIndex x402 Guide
As AI agents become more capable, they increasingly need to pay for external services — APIs, compute, data, and tools. The x402 HTTP payment protocol provides a standard way for any agent framework to make autonomous payments.
This guide shows you how to add x402 payment support to the four most popular AI agent frameworks.
Why Agent Frameworks Need Built-in Payment Support
Today’s AI agents are expected to:
- Call APIs to fetch real-time data
- Use specialized AI services (image generation, OCR, translation)
- Access premium databases and research tools
- Pay for compute-intensive operations
Without native payment support, developers must build custom billing integrations for each service. x402 standardizes this — agents can pay any x402-enabled service with a single integration.
LangChain + x402 Payments
LangChain’s tool-calling system maps perfectly to x402’s per-call payment model.
Install the x402 LangChain integration
pip install langchain-x402
Create an x402-enabled tool
from langchain.tools import BaseTool
from x402.langchain import X402PaymentMixin
class PaidSearchTool(X402PaymentMixin, BaseTool):
name = "paid_web_search"
description = "Search the web. Automatically pays ~$0.001 USDC per search via x402."
def _run(self, query: str) -> str:
# x402 payment handled automatically by mixin
response = self.x402_get(
"https://api.searchprovider.com/search",
params={"q": query},
max_payment_usdc=0.005
)
return response.json()["results"]
# Use in any LangChain agent
from langchain.agents import AgentExecutor
agent = AgentExecutor(tools=[PaidSearchTool()], ...)
CrewAI + x402 Payments
CrewAI’s multi-agent architecture benefits from x402’s machine-to-machine payment model — one agent can pay another agent or external service.
CrewAI x402 integration
from crewai import Agent, Task, Crew
from x402.crewai import X402Wallet
# Initialize agent wallet
wallet = X402Wallet(private_key=os.environ["AGENT_PRIVATE_KEY"])
researcher = Agent(
role="Research Analyst",
goal="Find the latest market data",
tools=[wallet.wrap_tool(search_tool)], # Adds x402 payment capability
verbose=True
)
research_task = Task(
description="Research competitor pricing. Budget: $0.05 USDC for API calls.",
agent=researcher,
payment_budget=0.05 # CrewAI tracks spending across the crew
)
crew = Crew(agents=[researcher], tasks=[research_task])
result = crew.kickoff()
AutoGen + x402 Payments
Microsoft’s AutoGen framework enables conversational agents that can negotiate tasks. With x402, these agents can also negotiate prices.
import autogen
from x402.autogen import PaymentCapableUserProxy
# AutoGen agent with payment capabilities
payment_proxy = PaymentCapableUserProxy(
name="PayingAgent",
x402_config={
"private_key": os.environ["AGENT_KEY"],
"max_per_call": 0.01, # $0.01 USDC max per API call
"daily_budget": 1.00 # $1.00 USDC daily limit
}
)
assistant = autogen.AssistantAgent(
name="Assistant",
llm_config={"model": "gpt-4"}
)
# AutoGen conversation where agents can use paid APIs
payment_proxy.initiate_chat(
assistant,
message="Research the latest x402 implementations. Use any APIs you need."
)
LlamaIndex + x402 Payments
LlamaIndex’s data connectors and query engines integrate naturally with x402’s per-query payment model.
from llama_index.core import VectorStoreIndex
from x402.llamaindex import X402DataConnector
# Connect to a paid data source via x402
paid_connector = X402DataConnector(
endpoint="https://premium-data-provider.com/documents",
payment_config={
"currency": "USDC",
"max_per_query": 0.002
}
)
# Build an index from paid data
documents = paid_connector.load_data(query="AI payment protocols 2026")
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
# Each query may trigger x402 payments automatically
response = query_engine.query("What is the current state of x402 adoption?")
Security Best Practices
When implementing x402 payments in agent frameworks:
- Set spending limits: Always configure
max_per_callanddaily_budgetlimits - Use dedicated wallets: Create separate wallets for agents, not your personal keys
- Log all payments: Keep an audit trail of what agents pay for
- Implement circuit breakers: Stop agent if spending exceeds threshold
- Human-in-the-loop for large payments: Require human approval for payments > $1
Comparing Framework Support
| Framework | x402 Maturity | Best For |
|---|---|---|
| LangChain | Excellent | Single-agent pipelines |
| CrewAI | Good | Multi-agent teams |
| AutoGen | Growing | Conversational agents |
| LlamaIndex | Good | RAG + data pipelines |
Open-Source Projects to Watch
The mpp.best directory tracks 1,300+ projects in this space:
- coinbase/x402 — Reference implementation
- NoFx — Agent payment stack
- daydreams — Autonomous agent framework with payments
Browse all agent payment projects →