Skip to content

API Reference

Yaqing2023 edited this page Mar 7, 2026 · 1 revision

API Reference

Complete reference for MoltsPay Python SDK.

MoltsPay

Main synchronous client.

from moltspay import MoltsPay

Constructor

client = MoltsPay(
    chain: str = "base",
    wallet_path: str = None,
    max_per_tx: float = 10.0,
    max_per_day: float = 100.0
)
Parameter Type Description Default
chain str Blockchain to use "base"
wallet_path str Path to wallet file ~/.moltspay/wallet.json
max_per_tx float Max per transaction 10.0
max_per_day float Max per day 100.0

Properties

address

Wallet address.

print(client.address)  # 0xABC123...

Methods

discover(url)

List available services from a provider.

services = client.discover("https://juai8.com/zen7")
for svc in services:
    print(f"{svc.id}: {svc.price} {svc.currency}")

Returns: List[Service]

pay(url, service_id, **params)

Pay for and execute a service.

result = client.pay(
    "https://juai8.com/zen7",
    "text-to-video",
    prompt="a cat dancing"
)
print(result.result)
Parameter Type Description
url str Provider URL
service_id str Service identifier
**params Any Service parameters

Returns: PaymentResult

balance()

Get current USDC balance.

balance = client.balance()
print(f"{balance} USDC")

Returns: float

limits()

Get spending 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}")

Returns: Limits

set_limits(max_per_tx=None, max_per_day=None)

Update spending limits.

client.set_limits(max_per_tx=20, max_per_day=200)

AsyncMoltsPay

Async version of the client.

from moltspay import AsyncMoltsPay

Usage

import asyncio

async def main():
    async with AsyncMoltsPay() as client:
        result = await client.pay(...)

asyncio.run(main())

All methods are the same as MoltsPay but async:

  • await client.discover(url)
  • await client.pay(url, service_id, **params)
  • await client.balance()
  • await client.limits()
  • await client.set_limits(...)

Data Classes

Service

@dataclass
class Service:
    id: str
    name: str
    description: str
    price: float
    currency: str
    input_schema: dict
    output_schema: dict

PaymentResult

@dataclass
class PaymentResult:
    success: bool
    tx_hash: str
    result: Any
    error: str | None

Limits

@dataclass
class Limits:
    max_per_tx: float
    max_per_day: float
    spent_today: float

Exceptions

from moltspay import (
    MoltsPayError,
    InsufficientFunds,
    LimitExceeded,
    PaymentError
)

InsufficientFunds

Raised when wallet balance is too low.

try:
    client.pay(...)
except InsufficientFunds as e:
    print(f"Need {e.required} USDC, have {e.balance}")
Attribute Type Description
required float Amount needed
balance float Current balance

LimitExceeded

Raised when spending limit is exceeded.

try:
    client.pay(...)
except LimitExceeded as e:
    print(f"Exceeds {e.limit_type} limit: {e.amount} > {e.limit}")
Attribute Type Description
limit_type str "per_tx" or "per_day"
amount float Attempted amount
limit float Current limit

PaymentError

General payment failure.

try:
    client.pay(...)
except PaymentError as e:
    print(f"Payment failed: {e}")

Environment Variables

Variable Description
MOLTSPAY_WALLET Custom wallet path
MOLTSPAY_CHAIN Default chain

Clone this wiki locally