Skip to main content

CrewAI

Use ampersend Wallets and Guardrails with CrewAI Agents.

This guide shows how to configure a CrewAI agent with an ampersend wallet so it can pay for services using USDC on Base.

In this example, the agent calls a paid joke API via an x402-enabled endpoint. The ampersend client handles payment settlement and automatically retries the request.


How it works

The CrewAI agent uses a tool that wraps an HTTP request with ampersend’s payment client.

  1. The tool sends a request to an x402-enabled endpoint.
  2. The server responds with a 402 Payment Required response and a price in USDC.
  3. The ampersend client intercepts the response.
  4. The client signs the payment using the agent’s session key.
  5. Payment settles on Base.
  6. The client automatically retries the original request.

This flow does not require:

  • API keys
  • OAuth
  • Billing dashboards

The agent uses its wallet to complete the payment handshake through x402.


Prerequisites

Before you begin, make sure you have:

  • Claude Code install
  • The UV package manager will be installed
  • An ampersend agent with a funded smart wallet from the ampersend dashboard

Setup

1. Clone the repository

git clone https://github.com/marcusrein/ampersend-crewai
cd ampersend-crewai
uv sync

2. Configure credentials

Copy the example environment file:

cp .env.example .env

Add the following values to .env:

  • ampersend smart account address
  • session key private key

You can find both values in the ampersend dashboard.


3. Run the agent

uv run python crew.py

The agent calls the paid joke API. If the payment succeeds and the request completes, the API returns a joke.


4. Extend the integration

You can replace the joke API with any x402-enabled service.

Examples include:

  • ZK proof generation
  • Compute services
  • Data feeds

The payment flow remains the same:

  • x402 handles the payment protocol
  • settlement occurs in USDC on Base
  • ampersend manages payment guardrails and execution