Loomal

Integrating x402 with CrewAI agents a crew with a budget.

CrewAI crews delegate work across multiple agents. When some of that work runs on paid MCP servers and APIs, the crew needs a wallet, a paying tool, and a budget that survives multi-step tasks.

A CrewAI crew splits a job across specialized agents — a researcher gathers, an analyst synthesizes, a writer produces. The researcher is usually the one who needs paid services: premium search, company enrichment, document parsing. Provisioning API keys for every service each agent might touch is the kind of operational drag crews were supposed to eliminate.

x402 fits the crew model cleanly because payment is per call and self-contained. You define one custom tool that pays from the crew's wallet, assign it to the agents that need it, and a kickoff that makes nine paid lookups costs exactly nine call prices — no subscriptions idling between runs.

One wallet per crew, not per agent

Resist the urge to give every agent its own wallet. A crew is one economic unit: fund a single EVM account with USDC on Base and let every paying tool draw from it. That gives you one balance to monitor, one funding operation, and one place where the hard spending cap lives — the balance itself.

Keep the key in an environment variable and the balance small. At Loomal's minimum price of $0.01 per call, $10 of USDC funds a thousand tool calls, which for most crews is weeks of operation. No ETH is needed; in x402's exact scheme the facilitator submits the transaction, so the payer spends no gas.

Define a paying custom tool

CrewAI's @tool decorator turns a function into something agents can invoke. Inside the function, an x402-aware requests session handles the 402 handshake — the agent that calls the tool never sees a payment, just a result. State the price in the tool description so the LLM weighs cost when choosing tools.

crew_tools.py
import os
from eth_account import Account
from x402.clients.requests import x402_requests
from crewai.tools import tool

wallet = Account.from_key(os.environ["CREW_WALLET_KEY"])
session = x402_requests(account=wallet)

@tool("company_enrichment")
def company_enrichment(domain: str) -> str:
    """Firmographic data for a company domain.
    Paid: $0.02 USDC per lookup via x402."""
    r = session.get(
        f"https://api.example.com/enrich?domain={domain}"
    )
    return r.text

# researcher = Agent(role="Researcher", tools=[company_enrichment], ...)

Budgets across a multi-step task

The crew-specific risk is amplification. A task like 'profile these 50 companies' fans out into 50 enrichment calls before the analyst agent ever runs, and a poorly scoped task description can fan out further. Put a counter in the tool itself: track calls per kickoff and raise once spend crosses a ceiling, so the crew fails loudly instead of draining quietly.

It also pays to make pricing visible in task design. If enrichment costs $0.02 and search costs $0.01, tell the researcher in its backstory to search first and enrich only shortlisted candidates. LLMs respond well to explicit cost hierarchies — it's the same instruction a human manager would give.

Where crews find paid tools

Every x402-priced endpoint works with this pattern, including paid MCP servers exposed over HTTP. The Loomal Index is the practical catalog: listings carry a live tool list, a per-call price, and a payable endpoint, so you can evaluate whether a capability is worth wiring into a crew before spending anything beyond a test call.

And the flow runs both directions — if your crew produces something valuable behind an endpoint, pricing it with x402 on Loomal turns other people's agents into your customers. Loomal's fee is 5% on settled transactions, currently waived.

FAQ

Should each CrewAI agent have its own wallet?

Usually no. A crew is one economic unit — one funded wallet shared by all paying tools means one balance to monitor and one hard cap. Separate wallets only make sense when you need per-agent spend accounting across many concurrent crews.

What happens if the wallet runs out mid-task?

The x402 client fails verification on the next paid call — the payer lacks sufficient USDC — and the tool raises an error. CrewAI surfaces it like any tool failure, so the crew can report partial results. Keeping a balance alert on the wallet avoids the surprise.

Does the agent LLM handle the 402 response itself?

No. The 402 handshake — challenge, signing, retry — happens inside the x402 session within your tool function. The LLM sees only the tool's final output. The model's only payment-related job is choosing tools wisely, which is why prices belong in tool descriptions.

How do I test before funding a real wallet?

Run your tool against an endpoint on Base Sepolia with testnet USDC first, then switch the network and fund a small mainnet balance. Because pay-per-call has no commitment, a production trial costs cents.

Build the tools crews pay for.

Price your API or MCP server per call and meet agent demand.

Open the Loomal console