Skip to main content
HomeLanding pagesHow to add payments to a CrewAI agent
LANDING PAGE

How to add payments to a CrewAI agent

8 min read·Last updated May 15, 2026

Subclass CrewAI's BaseTool, wrap the run method with Blockchain0x's require_payment helper, and add the wrapped tool to your Agent's tools list. Calls return a 402 until the wallet settles; settlement is USDC on Base in 2-5 seconds. The Crew's planner sees a normal tool and never reasons about payment directly.

What you will build

A CrewAI crew where every paid tool a member agent calls settles automatically in USDC on Base. The agent's reasoning loop does not change. The crew's manager does not change. You add a wrapped tool to the agent's tools list, set a spend policy on the agent's wallet, and the rest is identical to the unpaid version.

This is the CrewAI-specific path through the Blockchain0x payment API. The underlying mechanics are the same as the LangChain integration (an x402-based wrapper around a tool handler), but CrewAI's Tool, Agent, and Crew primitives have their own ergonomics that this guide walks through directly. The CrewAI integration page is the broader reference; this LP is the focused 15-minute integration walkthrough.

Prerequisites

Have these ready before you start:

  • A working CrewAI crew with at least one Agent and one Tool. If you have not built a crew yet, the CrewAI quickstart gets you to a working Crew object in about 20 minutes.
  • A Blockchain0x account with one agent profile per CrewAI Agent you want to make payment-capable. Creating an agent profile is a single API call; the add-payments-to-agent guide covers it end-to-end.
  • A test API key (sk_test_).
  • Python 3.11+, matching CrewAI's runtime requirements.
  • A clear sense of which CrewAI tool you want the agent to pay for. Common picks: market-data APIs, premium search providers, paid MCP servers your crew calls into, custom internal services that have their own per-call costs.

Install the SDK

Two packages:

BASH
pip install blockchain0x blockchain0x-crewai

Set two environment variables:

BASH
BLOCKCHAIN0X_API_KEY=sk_test_01J9...
BLOCKCHAIN0X_AGENT_ID=agt_01J9...

BLOCKCHAIN0X_AGENT_ID is the Blockchain0x profile for the CrewAI Agent that will be paying. If you have multiple agents in your crew that need to pay independently, use different env vars per agent (e.g. RESEARCHER_AGENT_ID, WRITER_AGENT_ID) and read the right one inside each tool.

Wrap a CrewAI tool

CrewAI tools are BaseTool subclasses with a name, description, and either _run (sync) or _arun (async). Wrap the run method with require_payment and the rest of the tool is unchanged.

PYTHON
from crewai.tools import BaseTool
from blockchain0x_crewai import require_payment
from pydantic import Field
import os, json

class RealtimeQuoteTool(BaseTool):
    name: str = "get_quote_realtime"
    description: str = "Fetch a real-time quote for a stock ticker."

    @require_payment(
        agent_id=os.environ["BLOCKCHAIN0X_AGENT_ID"],
        api_key=os.environ["BLOCKCHAIN0X_API_KEY"],
        price_usdc="0.005",
        reason="Real-time quote",
    )
    def _run(self, ticker: str, receipt=None) -> str:
        quote = fetch_live_quote(ticker)
        return json.dumps(quote)

What the wrapper does:

  1. The CrewAI agent calls the tool with ticker="TSLA".
  2. require_payment checks whether the agent already has a valid receipt for this tool in the cache window.
  3. If yes, it invokes _run with receipt= set to the cached receipt and returns the quote.
  4. If no, it returns a 402-shaped payment-required response. The Blockchain0x wallet runtime intercepts it, settles $0.005 in USDC on Base, and retries the call with the receipt attached. _run runs once payment is confirmed.

The tool's description is what CrewAI's planner sees when deciding whether to call it. The price is not in the description by default; the wallet handles authorization invisibly.

Attach the tool to an agent

The wrapped tool plugs into a CrewAI Agent the same way an unpaid tool would:

PYTHON
from crewai import Agent, Crew, Task

researcher = Agent(
    role="Market researcher",
    goal="Get real-time quotes and produce a 1-line summary.",
    backstory="An equity research analyst.",
    tools=[RealtimeQuoteTool()],
    verbose=True,
)

task = Task(
    description="Get the real-time quote on TSLA and summarise it.",
    agent=researcher,
    expected_output="A 1-line markdown summary with the price.",
)

crew = Crew(agents=[researcher], tasks=[task])
result = crew.kickoff()
print(result)

When kickoff() runs, the planner asks for the quote, the tool returns a 402, the wallet settles, and the tool returns the actual quote. From the crew's perspective the only observable difference is a 1-2 second delay on the first call to that tool per session.

Per-agent vs per-crew billing

A common decision in the first hour: should every CrewAI Agent get its own Blockchain0x wallet, or should the whole crew share one?

The right answer is almost always per-agent. The crew is a logical grouping; the agent is the unit of work that decides to spend. Per-agent gives you:

  • Isolation. A prompt-injection attack that hijacks one agent only burns that agent's daily cap. The rest of the crew keeps working.
  • Attribution. When the dashboard shows a $4.20 spend on agent researcher_v2 and $0.30 on agent summariser_v1, you can tune the policy per role and price the crew correctly.
  • Independent spend policies. A researcher agent that calls premium data APIs has different per-call ceilings than a summariser agent that just calls an LLM. Per-agent policies match per-agent work.

The exception is small internal crews where everyone has the same risk profile and you want one consolidated invoice. In that case, share a wallet at the crew level; the dashboard still attributes spend per tool call, so you do not lose all attribution.

Add a spend policy

Once paid tools work, give every agent a spend policy. The policy lives in the wallet API, not in the agent's prompt - which is the only layer that survives prompt injection.

PYTHON
from blockchain0x import Client
import os

client = Client(api_key=os.environ["BLOCKCHAIN0X_API_KEY"])

client.agents.update_spend_policy(
    os.environ["BLOCKCHAIN0X_AGENT_ID"],
    daily_cap_usdc="20.00",
    per_payment_cap_usdc="0.50",
    allowed_counterparties=[
        "0xPaidMcpServerA...",
        "0xPaidDataApiB...",
    ],
)

The wallet enforces this on every payment intent. A tool call that would exceed the cap fails with a policy_violation error before any money moves. The CrewAI agent sees the error, the planner can adapt, and your audit log gets a clean entry. The agent-spend-controls guide covers tuning the numbers based on real usage. Pricing across tiers is documented at /pricing/; the per-agent spend policy itself is a Pro-tier feature.

Common pitfalls

Five things to get right in the first week of CrewAI-with-payments.

One Blockchain0x agent profile for the whole crew. Tempting because it is simpler, costly because you lose isolation. Create one profile per CrewAI Agent that makes paid calls.

Hardcoding the agent ID in the tool class. The tool should read the agent ID from environment or pass it in via the constructor, so the same tool class can be reused across different CrewAI Agents that have their own wallets. Hardcoding it makes the tool single-tenant.

Letting the planner see the price in the description. "Costs $0.05 per call" in the description biases the planner toward avoiding the tool. Leave price out of the description; let the spend policy bound risk at the wallet layer.

Forgetting that CrewAI tools can be called multiple times per task. A CrewAI Agent may invoke the same tool many times in one task's execution. The receipt cache (default 1-hour TTL) means subsequent calls in the same task reuse the same receipt, but if your TTL is too short you will pay multiple times for what should be one logical session. Tune TTL to the tool's freshness needs.

Skipping verification badges on the agent's profile. The wallet works without them, but counterparties (paid MCP servers, other agents) decide whether to trust your payments partly based on the verification badges on the agent's public page. Earn the GitHub and domain badges via the verify-agent-identity guide; they take ~5 minutes each and dramatically improve first-contact trust.

What to ship today

The shortest path from "I have a CrewAI crew" to "my CrewAI crew can pay for tools":

  1. Install blockchain0x and blockchain0x-crewai.
  2. Wrap one BaseTool's _run with require_payment.
  3. Add the wrapped tool to the Agent's tools list.
  4. Set a spend policy via update_spend_policy.
  5. Test on Base Sepolia with sk_test_ keys; flip to sk_live_ when comfortable.

That is the integration. Everything else - dashboards, audit logs, verification badges, webhooks for async tools - is layered on top. If your CrewAI crew is itself a paid service (charging external callers), see the related crewai-payment-integration page for the reverse direction. For the LangChain version of this same pattern, how-to-add-payments-to-langchain-agent walks through the parallel integration.

FAQ

Frequently asked questions.

Do I need a wallet per agent or per crew?

Per agent is the right granularity for most CrewAI deployments. A crew is a collection of cooperating agents; each agent has its own role, its own tools, and (with Blockchain0x) its own spend envelope. If every agent in a crew shares one wallet, you lose attribution and any prompt-injected agent burns the whole crew's budget. Per agent gives you isolation and per-role budget tuning.

What about hierarchical crews where one agent delegates to others?

Hierarchical crews are an agent-to-agent payment pattern even without external merchants. The manager agent pays delegate agents for sub-tasks the same way it would pay an external paid tool. Each delegate has its own wallet, its own price for the work, and its own spend policy. This is the cleanest way to scale credit attribution in a multi-agent crew without writing a custom billing layer.

Does the require_payment wrapper work with async tools?

Yes. CrewAI tools can implement either `_run` or `_arun`; the wrapper handles both. For long-running async tools you may also want to wire the confirmation webhook so the result can be delivered after the wallet settles, rather than blocking the tool's return. The synchronous path covers most cases and adds about 1-2 seconds for first-call settlement.

How do I charge differently for different inputs?

Pass a callable as `price_usdc` instead of a string. The callable receives the same kwargs the tool's run method will, and returns a price string. The agent's wallet checks the quoted price against the spend policy before paying, so dynamic pricing remains safe. See the CrewAI integration page for a worked example.

Can the same paid tool be used by multiple agents in a crew?

Yes. The receipt cache is keyed per agent, so the wallet ensures every agent in the crew pays separately on first call, then reuses the receipt within the TTL window. If two agents call the same tool concurrently, each gets its own 402 the first time. This keeps attribution clean across the crew.

Is this compatible with CrewAI's planning step?

Yes. The planner sees the tool's description (which you write in the BaseTool subclass) and reasons about whether to call it. The price is not visible to the planner by default; the wallet enforces budget at settlement time. If you want the planner to be price-aware, include the price in the tool's description string explicitly. Most teams find leaving the planner price-blind works better because the spend policy bounds the worst case anyway.

Create your free agent wallet in 5 minutes.

First payment confirmed in under ten minutes. Free to start.