Python SDK for MoltsPay - Agent-to-Agent Payments.
MoltsPay enables AI agents to pay each other for services using the x402 protocol - HTTP-native payments with USDC stablecoins. No gas fees, no complex wallet management.
MoltsPay is blockchain payment infrastructure designed for AI agents. It solves a fundamental problem: how do autonomous AI agents pay for services?
- π€ Agent-to-Agent Commerce - AI agents can autonomously discover, pay for, and use services
- π¨ Gasless Payments - Uses EIP-2612 permits, no ETH needed
- π x402 Protocol - HTTP 402 Payment Required - payments as native HTTP flow
- π Spending Limits - Set per-transaction and daily limits for safety
- π¦ LangChain Ready - Drop-in tools for LangChain agents
pip install moltspayFor LangChain integration:
pip install moltspay[langchain]from moltspay import MoltsPay
# Initialize (auto-creates wallet if not exists)
client = MoltsPay()
print(f"Wallet address: {client.address}")
# Discover services from a provider
services = client.discover("https://juai8.com/zen7")
for svc in services:
print(f"{svc.id}: {svc.price} {svc.currency}")
# Pay for a service
result = client.pay(
"https://juai8.com/zen7",
"text-to-video",
prompt="a cat dancing on the beach"
)
print(result.result)Wallet is automatically created on first run and stored at ~/.moltspay/wallet.json. Compatible with Node.js CLI.
from moltspay import MoltsPay
client = MoltsPay()
print(f"Address: {client.address}")
print(f"Balance: {client.balance()} USDC")Control your agent's spending with built-in limits:
from moltspay import MoltsPay
client = MoltsPay()
# Check current limits
limits = client.limits()
print(f"Max per tx: {limits.max_per_tx}")
print(f"Max per day: {limits.max_per_day}")
print(f"Spent today: {limits.spent_today}")
# Update limits
client.set_limits(max_per_tx=20, max_per_day=200)Full async/await support for high-performance applications:
import asyncio
from moltspay import AsyncMoltsPay
async def main():
async with AsyncMoltsPay() as client:
result = await client.pay(
"https://juai8.com/zen7",
"text-to-video",
prompt="a cat dancing"
)
print(result.result)
asyncio.run(main())Comprehensive exception types for robust error handling:
from moltspay import MoltsPay, InsufficientFunds, LimitExceeded, PaymentError
client = MoltsPay()
try:
result = client.pay(...)
except InsufficientFunds as e:
print(f"Need {e.required} USDC, have {e.balance}")
except LimitExceeded as e:
print(f"Exceeds {e.limit_type} limit: {e.amount} > {e.limit}")
except PaymentError as e:
print(f"Payment failed: {e}")Use MoltsPay as tools in your LangChain agents - let your AI autonomously pay for services!
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
from moltspay.integrations.langchain import MoltsPayTool
llm = ChatOpenAI(model="gpt-4")
tools = [MoltsPayTool()]
agent = initialize_agent(
tools,
llm,
agent=AgentType.OPENAI_FUNCTIONS,
verbose=True
)
# Agent can now pay for AI services!
result = agent.run("Generate a video of a cat dancing on the beach")Two tools available for different use cases:
from moltspay.integrations.langchain import get_moltspay_tools
tools = get_moltspay_tools() # Returns both tools| Tool | Description |
|---|---|
MoltsPayTool |
Pay for and execute services |
MoltsPayDiscoverTool |
Discover available services and prices |
Wallet format is fully compatible with the Node.js CLI:
# Create wallet with Node CLI
npx moltspay init --chain base
# Use same wallet in Python
python -c "from moltspay import MoltsPay; print(MoltsPay().address)"Your Agent Service Provider Blockchain
β β β
β Request service β β
β ββββββββββββββββββββββββββ> β β
β β β
β 402 + price + wallet β β
β <ββββββββββββββββββββββββββ β β
β β β
β [Sign payment - NO GAS] β β
β β β
β Request + signed payment β β
β ββββββββββββββββββββββββββ> β Verify & settle β
β β βββββββββββββββββββββββββ>β
β β β
β 200 OK + result β β
β <ββββββββββββββββββββββββββ β β
Your agent never pays gas - the CDP facilitator handles all on-chain settlement.
- AI Assistants - Let your assistant pay for premium APIs
- Autonomous Agents - Agents that can spend within limits
- Multi-Agent Systems - Agents paying other agents for services
- AI Pipelines - Pay-per-use for expensive compute steps
- moltspay (Node.js) - Node.js SDK and CLI
- x402 Protocol - The HTTP payment standard
- Website: https://moltspay.com
- PyPI: https://pypi.org/project/moltspay/
- npm (Node.js): https://www.npmjs.com/package/moltspay
- GitHub: https://github.com/Yaqing2023/moltspay-python
MIT