Skip to main content

AgentPay Logo

Open AgentPay Python SDK (`open-agentpay`)

The Open-Source Financial Firewall & Micro-Payment Infrastructure for Autonomous AI Agents

PyPI Version Documentation Follow @OpenAgentPay License: Apache-2.0 x402 V2 Python 3.10+ Circle USDC

📚 Documentation • 💻 GitHub Repository • 🐦 Follow on X (@OpenAgentPay) • 🐛 Report Issue


💡 What is AgentPay?

AgentPay equips autonomous AI agents with micro-payments (Circle USDC on Arbitrum Sepolia & Base) governed by an in-process, non-custodial Financial Firewall. It transparently intercepts HTTP 402 Payment Required responses, validates policy limits, and signs off-chain authorizations—protecting agent wallets against runaway loops and LLM hallucinations.

📦 Package Name Note: The canonical PyPI distribution is open-agentpay (official aliases: agentpay-core, agent-pay, agentpay-firewall). Regardless of which package you install, you import agentpay in Python code.


⚡ Quickstart

1. Installation

pip install open-agentpay

(Optional LangChain support):

pip install "open-agentpay[langchain]"

2. Basic Usage: On-Chain Mode with Financial Firewall

Transparently intercepts HTTP 402 challenges, enforces local policy limits, and signs off-chain EIP-712/EIP-3009 authorizations:

from agentpay import AgentPayClient, LocalSigner
from agentpay.policy import SQLitePolicyEngine, PolicyConfig

# 1. Initialize local signer (non-custodial private key, 0 gas required)
signer = LocalSigner("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")

# 2. Configure local financial firewall
policy = SQLitePolicyEngine.create_in_memory(
    PolicyConfig(
        id="agent_firewall",
        wallet_address=signer.address,
        max_per_tx_base_units=100_000,  # Max $0.10 per call
        rolling_budget_24h_base_units=1_000_000,  # Daily cap $1.00
        circuit_max_rpm=5,  # Trip circuit breaker if > 5 calls/min
    )
)

# 3. Create client with automatic x402 challenge negotiation
client = AgentPayClient(signer=signer, policy=policy)

# 4. Transparent call (auto-pays 402 challenge via EIP-712 off-chain signature)
response = client.get("https://api.seller.com/v1/market-data?ticker=NVDA")
print(response.json())

3. Virtual Wallet Mode (API Key Path)

For sub-millisecond execution using a pre-funded virtual ledger:

from agentpay import AgentPayClient, LocalSigner
from agentpay.policy import SQLitePolicyEngine, PolicyConfig

client = AgentPayClient(
    signer=LocalSigner("0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"),
    policy=SQLitePolicyEngine.create_in_memory(PolicyConfig(...)),
    headers={"Authorization": "Bearer agp_live_your_api_key"},
)

response = client.get("https://gateway.seller.com/v1/compute")

4. LangChain Tool Integration (@paid_tool)

Convert any Python function into a paid LangChain tool protected by the financial firewall:

from agentpay.integrations.langchain import paid_tool


@paid_tool(name="fetch_stock_quote", description="Fetch real-time stock prices", client=client)
def fetch_stock_quote(ticker: str) -> dict:
    resp = client.get(f"https://api.seller.com/v1/market-data?ticker={ticker}")
    return resp.json()


# Invoked seamlessly by LangChain agents
result = fetch_stock_quote.invoke({"ticker": "NVDA"})

5. Async Client (AsyncAgentPayClient)

For high-concurrency agent workflows:

import asyncio
from agentpay import AsyncAgentPayClient, LocalSigner
from agentpay.policy import SQLitePolicyEngine, PolicyConfig


async def main():
    async with AsyncAgentPayClient(signer=signer, policy=policy) as client:
        response = await client.get("https://api.seller.com/v1/market-data?ticker=NVDA")
        print(response.json())


asyncio.run(main())

🛡️ Core Capabilities

Pillar Description
Zero-Trust Financial Firewall Enforces per-transaction caps, 24-hour rolling budgets, lifetime limits, and payee whitelists outside the LLM prompt.
Autonomous Circuit Breaker Automatically halts agent loops and freezes spending when request frequency exceeds safety thresholds (circuit_max_rpm).
Gasless Off-Chain Settlements AI Agents hold only Circle USDC; gas is sponsored on Arbitrum Sepolia & Base via EIP-3009 off-chain authorizations.
Agent Session & Audit Observability Automatic tracking headers (X-Agent-Session-ID, X-Agent-Task-ID) connect tool spending to tasks in the AgentPay Console.
Fail-Closed Guarantees Any policy violation, budget overrun, or upstream failure aborts safely with zero funds deducted.

📖 Documentation & Community


📄 License

Apache-2.0 License. See LICENSE for details.

Metadata

Release files for open-agentpay 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for open-agentpay 0.2.0
File Size Uploaded Provenance
open_agentpay-0.2.0.tar.gz 59.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for open-agentpay 0.2.0
File Interpreter ABI Platform
open_agentpay-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 138.1 kB

Release files / open_agentpay-0.2.0.tar.gz

Download URL open_agentpay-0.2.0.tar.gz
Size 59.0 kB
Tags Source
SHA-256 checksum
How to use checksums
616a518ddf6b99a6ada4c156874f2f0f8116bbed95a534a6f262195bef1fe582
BLAKE2b-256 checksum
How to use checksums
71387fed0cce1a74e24f1bcb1acccec466261ce1a105e7eff52c37a9ab6d84ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.7

Release files / open_agentpay-0.2.0-py3-none-any.whl

Download URL open_agentpay-0.2.0-py3-none-any.whl
Size 79.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a84fc2681f28f36a3f316ac6f3b2da8c4889772e1fd628a07fcd2a736daf4f0
BLAKE2b-256 checksum
How to use checksums
e0caef6e24555d2c16ac7cdcdada19eefca7bdf84e621729b4ee585864ad4970
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.7

Security for open-agentpay 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page