Skip to main content

MixrPay Agent SDK - Enable AI agents to make x402 payments with session keys

Project description

MixrPay Agent SDK for Python

Enable AI agents to make autonomous payments.

Installation

pip install mixrpay

Setup

export MIXRPAY_SESSION_KEY=sk_live_...

Session keys are created by wallet owners at mixrpay.com/wallet/sessions.

Basic Usage

from mixrpay import AgentWallet

wallet = AgentWallet(session_key="sk_live_...")

# Call a paid API
response = await wallet.call_merchant_api(
    url="https://api.merchant.com/generate",
    merchant_public_key="pk_live_...",
    price_usd=0.05,
    json={"prompt": "Hello world"}
)

data = response.json()

Session Management

# Sessions are handled automatically, but you can manage them:
session = await wallet.get_or_create_session(
    merchant_public_key="pk_live_...",
    spending_limit_usd=25,
    duration_days=7,
)

# List sessions
sessions = await wallet.list_sessions()

# Revoke when done
await wallet.revoke_session(session.id)

Error Handling

from mixrpay import (
    AgentWallet,
    InsufficientBalanceError,
    SessionLimitExceededError,
)

try:
    response = await wallet.call_merchant_api(...)
except InsufficientBalanceError as e:
    print(f"Low balance. Top up: {e.top_up_url}")
except SessionLimitExceededError:
    print("Session limit exceeded")

Spending Controls

wallet = AgentWallet(
    session_key="sk_live_...",
    max_payment_usd=1.0,  # Client-side safety limit
    on_payment=lambda p: print(f"Paid ${p.amount_usd}"),
)

# Check balance
balance = await wallet.get_balance()
stats = wallet.get_spending_stats()

Context Manager

async with AsyncAgentWallet(session_key="sk_live_...") as wallet:
    response = await wallet.call_merchant_api(...)

LangChain Integration

from langchain.tools import BaseTool
from mixrpay import AgentWallet

class PaidSearchTool(BaseTool):
    name = "paid_search"
    description = "Premium search ($0.05/query)"
    
    def __init__(self, session_key: str):
        super().__init__()
        self.wallet = AgentWallet(session_key=session_key)
    
    async def _arun(self, query: str) -> str:
            response = await self.wallet.call_merchant_api(
                url="https://api.search.com/query",
                merchant_public_key="pk_live_...",
                price_usd=0.05,
                json={"query": query}
            )
            return response.json()["results"]

Documentation

Full documentation at mixrpay.com/docs

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mixrpay-0.6.0.tar.gz (32.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mixrpay-0.6.0-py3-none-any.whl (30.5 kB view details)

Uploaded Python 3

File details

Details for the file mixrpay-0.6.0.tar.gz.

File metadata

  • Download URL: mixrpay-0.6.0.tar.gz
  • Upload date:
  • Size: 32.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for mixrpay-0.6.0.tar.gz
Algorithm Hash digest
SHA256 3ab1606c27d3a6fb2b86c7eb6fe6bbe9dd5a930e078bb55cc76019a5de847916
MD5 1637c01c31f3e9ff17b569be52e4dc56
BLAKE2b-256 4fc88ae8be8240974750e667c239345b68192c2c51c9f644f6862c54e2325c5f

See more details on using hashes here.

File details

Details for the file mixrpay-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: mixrpay-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 30.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for mixrpay-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b914f2f63d1a30269d06f7e8a027bb4c184e182bdae5d6851eee580d6f473b71
MD5 801b2abbd4d1f2f9fb0e942c6c0dfacf
BLAKE2b-256 14e31654ef7499a5bfeae4792a09a212a04f0cc318ee7769e9b435cd9ce06897

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page