payagent
Universal Payment & Monetization Engine for AI Agents
Enable AI agents to pay each other for APIs, data, and compute — and let developers monetize MCP tools / endpoints with a one-line decorator.
pip install payagent
# or
uv add payagent
pip install 'payagent[fastapi]' # seller extras + uvicorn
payagent doctor # env health
payagent demo # mock pay + escrow
payagent version
Architecture
Agent A ── AgentPayClient ──► HTTP 402 ──► @paywall Agent B
│
AgentWallet + SpendingPolicy
├── x402 (Base / EVM) [mock or custom signer]
├── Solana [mock or custom signer]
└── Fiat REST [mock or API key]
| Capability | What you get |
|---|---|
| HTTP 402 | Auto-detect, pay, retry with X-PAYMENT-PROOF |
| Multi-rail wallet | x402, Solana, fiat via one interface |
| Guardrails | Per-tx / daily / monthly, allowlist, HITL |
| Escrow | Lock → job → validate → release / refund |
@paywall |
Monetize FastAPI / Starlette / MCP HTTP routes |
| Audit | wallet.payments() journal (memory / SQLite) |
| Env config | AgentWallet.from_env() + payagent doctor |
60-second quickstart
Buyer (auto-pay on 402)
import asyncio
from payagent import AgentPayClient, AgentWallet, SpendingPolicy
async def main():
# Safe mock wallet — no keys required
wallet = AgentWallet.from_env() # or AgentWallet.mock()
async with AgentPayClient(wallet) as client:
resp = await client.get("https://api.seller.example/premium")
print(resp.status_code, resp.json())
print(client.last_payment)
print(wallet.payments())
asyncio.run(main())
Seller (2 lines)
from fastapi import FastAPI, Request
from payagent import paywall
app = FastAPI()
@app.get("/premium")
@paywall(price_usd=0.05, recipient_address="0xYourAddress", currency="USDC")
async def premium(request: Request):
return {"data": "secret"}
Guardrails + escrow
from payagent import AgentWallet, EscrowSession, SpendingPolicy
wallet = AgentWallet.mock(
policy=SpendingPolicy(max_per_tx=0.5, daily_limit=10, monthly_limit=100),
)
escrow = EscrowSession(wallet, validator_fn=lambda r: r.get("ok") is True)
result = await escrow.run(
job=lambda: {"ok": True, "answer": 42},
amount=0.25,
currency="USDC",
recipient="0xProvider",
)
Custom testnet / live signer
from payagent import X402Provider, PaymentResult, AgentWallet, SpendingPolicy
async def my_signer(recipient, amount, currency, **kw) -> PaymentResult:
# broadcast on Base Sepolia / etc, then:
return PaymentResult(
tx_hash="0x…", amount=amount, currency=currency,
recipient=recipient, provider="x402", network="base-sepolia",
)
wallet = AgentWallet(
providers=[X402Provider(mock=False, private_key="0x…", signer=my_signer)],
policy=SpendingPolicy(max_per_tx=1.0, daily_limit=5.0),
)
Test that everything works
pip install -e ".[dev]"
pytest -q
python examples/e2e_local_loop.py # full 402 + escrow + budgets
python examples/e2e_testnet_skeleton.py
payagent demo
See docs/TESTING.md for unit / local E2E / testnet / mainnet canary.
Configuration
Copy .env.example → .env. Defaults are mock + testnet RPCs (Base Sepolia, Solana devnet).
| Variable | Meaning |
|---|---|
PAYAGENT_MOCK=1 |
Mock payments (default, safe) |
PAYAGENT_MAX_PER_TX |
Per-payment cap |
PAYAGENT_DAILY_LIMIT / MONTHLY_LIMIT |
Budgets |
PAYAGENT_SPEND_DB |
SQLite spend + payment journal |
BASE_PRIVATE_KEY / SOLANA_PRIVATE_KEY |
Optional keys for live mode |
PAYMAN_API_KEY |
Fiat REST adapter |
Feature matrix
| Rail | Module | Mock | Live |
|---|---|---|---|
| x402 / Base | X402Provider |
default | signer= or extend |
| Solana | SolanaProvider |
default | signer= or extend |
| Fiat | FiatProvider |
default | REST + API key |
| Client | AgentPayClient |
yes | any wallet |
| Seller | @paywall |
yes | PaymentVerifier |
Project layout
src/payagent/
client.py config.py wallet.py guardrails.py escrow.py
paywall.py history.py headers.py cli.py exceptions.py
providers/ base x402 solana fiat
Develop & release
uv venv -p 3.13 .venv && source .venv/bin/activate
uv pip install -e ".[dev]"
pytest -q && mypy src/payagent && python -m build
- GitHub: https://github.com/pomoq-dev/payagent
- PyPI: https://pypi.org/project/payagent/
- Changelog: CHANGELOG.md
License
MIT © poqdev
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file payagent-0.2.0.tar.gz.
File metadata
- Download URL: payagent-0.2.0.tar.gz
- Upload date:
- Size: 31.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d098b03c4f93f23a9756a2b707f6a51c964eaffcfd0d8f5fd53df235073e543
|
|
| MD5 |
03179f940e2d6af047fd217fde4b8d83
|
|
| BLAKE2b-256 |
b0c3e6affc64793d5c0d25de92feaf2d2367a6dd6776a2a041a162b3b5688bde
|
File details
Details for the file payagent-0.2.0-py3-none-any.whl.
File metadata
- Download URL: payagent-0.2.0-py3-none-any.whl
- Upload date:
- Size: 30.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbd4367a74297eba07ad155c6c7769714d5d36be2ea4bdf0455025530b1441f4
|
|
| MD5 |
05b5fe281530f9107adef63e02847729
|
|
| BLAKE2b-256 |
2d79dad0f013f5c7c1956cf6edf0ec99a43fd737a2d71dc9210b5dc8708ec39f
|