DEV Community

Yaqing2023
Yaqing2023

Posted on

Give Your AI Agents a Wallet: MoltsPay + CrewAI in 10 Lines

Your CrewAI agents can research, write, and code. But can they pay for services?

Today I'll show you how to give your agents the ability to purchase AI services autonomously using crypto — in about 10 lines of code.

The Problem

You're building a multi-agent system. One agent needs to generate a video, another needs to transcribe audio, a third needs real-time data. These services cost money.

Traditional approach: hardcode API keys, prepay credits, manage billing manually.

Better approach: let the agent pay per use, autonomously.

Enter MoltsPay + x402

MoltsPay implements the x402 protocol — HTTP-native payments. When an agent calls a paid API:

  1. Server responds 402 Payment Required with a price
  2. Agent signs a USDC payment
  3. Server verifies, delivers result
  4. Payment settles on-chain

No API keys. No prepaid credits. Pay-for-success.

Setup (2 minutes)

# Install
pip install moltspay

# Initialize wallet
npx moltspay init --chain base

# Fund with USDC (or use testnet)
npx moltspay fund
Enter fullscreen mode Exit fullscreen mode

CrewAI Integration (10 lines)

from crewai import Agent, Task, Crew
from crewai.tools import BaseTool
from moltspay import MoltsPay

class MoltsPayTool(BaseTool):
    name = "pay_service"
    description = "Pay for AI services (video, transcription, etc.) with USDC"

    def _run(self, provider: str, service: str, prompt: str) -> str:
        client = MoltsPay()
        return client.x402(f"{provider}/v1/{service}", data={"prompt": prompt})

# Create an agent with payment capability
creator = Agent(
    role="Video Producer",
    goal="Create engaging video content",
    tools=[MoltsPayTool()]
)

# This task will automatically pay for video generation
task = Task(
    description="Generate a video of a cat dancing on a rainbow",
    agent=creator
)

crew = Crew(agents=[creator], tasks=[task])
result = crew.kickoff()
Enter fullscreen mode Exit fullscreen mode

That's it. Your agent can now spend money.

What Just Happened?

When the agent runs this task:

  1. It recognizes it needs to generate a video
  2. Calls MoltsPayTool with the Zen7 video service
  3. MoltsPay sends request → gets 402 → signs payment → retries
  4. Video generates, agent receives URL
  5. $0.99 USDC transferred, zero gas fees

The agent made an autonomous financial decision. No human approval required (though you can add spending limits).

LangChain Version

Same logic, different wrapper:

from langchain.tools import BaseTool
from moltspay import MoltsPay

class MoltsPayTool(BaseTool):
    name = "moltspay"
    description = "Pay for AI services with USDC"

    def _run(self, provider: str, service: str, prompt: str) -> str:
        return MoltsPay().x402(f"{provider}/v1/{service}", data={"prompt": prompt})
Enter fullscreen mode Exit fullscreen mode

AutoGPT / Generic Python

No framework? Even simpler:

from moltspay import MoltsPay

client = MoltsPay()
video_url = client.x402(
    "https://juai8.com/zen7/v1/text-to-video",
    data={"prompt": "a dragon flying over mountains"}
)
print(f"Video ready: {video_url}")
Enter fullscreen mode Exit fullscreen mode

Spending Limits

Don't want your agent going bankrupt:

npx moltspay config --max-per-tx 5 --max-per-day 50
Enter fullscreen mode Exit fullscreen mode

Now your agent can spend max $5 per transaction, $50 per day.

Available Services

What can your agents buy?

Service Provider Price
Text-to-Video Zen7 $0.99
Image-to-Video Zen7 $1.49
More coming... moltspay.com/services

Why This Matters

We're moving toward agentic commerce — AI agents that don't just think, but transact. An agent that can:

  • Pay for compute when it needs more
  • Purchase data from other agents
  • Hire specialized services on-demand

...is fundamentally more capable than one that can't.

x402 is the HTTP of payments. MoltsPay makes it accessible today.

Links


Building something cool with MoltsPay? Drop a comment — I'd love to see it.

Top comments (0)