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 Sepolia) 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, 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:

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

# 1. Initialize local signer (non-custodial private key, 0 gas required)
# ⚠️ TESTNET DEVELOPMENT ONLY: This fallback key is Hardhat/Anvil's public Account 0 key.
# NEVER transfer mainnet funds to this address! In production, inject via environment variable:
private_key = os.getenv("AGENT_PRIVATE_KEY", "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
signer = LocalSigner(private_key)

# 2. Configure local financial firewall
policy = SQLitePolicyEngine.create_in_memory(
    PolicyConfig(
        id="agent_firewall",
        name="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:

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

private_key = os.getenv("AGENT_PRIVATE_KEY", "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80")
signer = LocalSigner(private_key)
client = AgentPayClient(
    signer=signer,
    policy=SQLitePolicyEngine.create_in_memory(
        PolicyConfig(
            id="wallet_firewall",
            name="Wallet Firewall",
            wallet_address=signer.address,
            max_per_tx_base_units=100_000,
            rolling_budget_24h_base_units=5_000_000,
            whitelist_domains=frozenset(["gateway.seller.com"]),
        )
    ),
    headers={"Authorization": "Bearer agp_live_your_api_key"},
    wallet_challenge_mode=True,
)

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 Sepolia 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.5

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.5
File Size Uploaded Provenance
open_agentpay-0.2.5.tar.gz 67.6 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 156.0 kB

Release files / open_agentpay-0.2.5.tar.gz

Download URL open_agentpay-0.2.5.tar.gz
Size 67.6 kB
Tags Source
SHA-256 checksum
How to use checksums
923a07b0f95f8eea0335e40290911b06a52d9a22bee6fc74c72dfa5bd96f418e
BLAKE2b-256 checksum
How to use checksums
d95d2129c11be5b09c8f2b480ba7ad428919180ed7c48b2761d7a53021501176
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.5-py3-none-any.whl

Download URL open_agentpay-0.2.5-py3-none-any.whl
Size 88.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d7664fa0293ecaf7c781cb55588411df426d11d087f2a36b20445d14c629e7fd
BLAKE2b-256 checksum
How to use checksums
d74b78e6000b56f2987f7709273f522af74567d3d4cb20354b8f77d27bdcd2d1
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.5

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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