Skip to main content

CrewAI Integration

Add Lightning payment capability to any CrewAI crew. Agents can access L402-protected APIs with automatic micropayments.

Install

pip install l402-requests[crewai]

Set your wallet:

export STRIKE_API_KEY="your-strike-api-key"

Quick Start

from crewai import Agent, Crew, Task
from l402_requests import L402Client, BudgetController
from l402_requests.integrations.crewai import L402GetTool, L402PostTool, L402SpendingTool

# Shared client for the whole crew
client = L402Client(
budget=BudgetController(max_sats_per_request=500, max_sats_per_hour=5000),
)

# Tools
get_tool = L402GetTool(client=client)
post_tool = L402PostTool(client=client)
spending_tool = L402SpendingTool(client=client)

# Agent
researcher = Agent(
role="API Researcher",
goal="Fetch data from L402-gated APIs and summarize findings.",
backstory="Expert at accessing Lightning-gated APIs.",
tools=[get_tool, spending_tool],
)

# Task
task = Task(
description="Get SEC filing data for Tesla from agent-commerce.store/api/edgar/company/TSLA",
expected_output="Summary of Tesla's recent SEC filings.",
agent=researcher,
)

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

Tools

L402GetTool

HTTP GET with automatic L402 payment.

  • Input: url (str)
  • Returns: Response body as text

L402PostTool

HTTP POST with automatic L402 payment.

  • Input: url (str), body (optional JSON string)
  • Returns: Response body as text

L402SpendingTool

Session spending summary.

  • Input: None
  • Returns: JSON with total sats, per-domain breakdown

Shared Client

Always pass the same L402Client to all tools. This ensures:

  • Credential cache is shared (no double-payments)
  • Budget is enforced across all tools as one limit
  • Spending log is unified