LangChain tool for PayPack: AI Agent autonomous payments (HTTP 402, x402, AP2)
Project description
PayPack
Universal Payment Middleware for AI Agents
One line of code. Let your AI pay for itself.
The Problem
The HTTP 402 status code has existed in the protocol specification since 1991. For over three decades, it has never been used in practice.
Why? Because when a server returns "Payment Required," there must be a human on the other end of the screen to pull out a credit card.
AI Agents change everything.
An autonomous AI agent can make hundreds of API calls, data purchases, and content subscriptions per hour — with individual amounts as small as $0.001. Traditional payment systems collapse under micro-transaction fees and the need for manual approval.
x402 (proposed by Coinbase) and AP2 (proposed by Google) are solving this: the server returns 402 with a payee address and amount, and the AI agent completes the on-chain payment automatically — all within a single HTTP round trip. No human intervention required.
PayPack's mission: to be the thinnest, most reliable, most indispensable middleware layer in the AI payment stack.
Architecture
AI Agent Application
│
▼
PayPack SDK ◄── You are here
│
┌───────┼───────┐
│ │ │
Protocol Payment Security
Parser Router Fuse
(x402/ (USDC/ (Limits/
AP2) Fiat) Audit)
│ │ │
└───────┼───────┘
│
▼
Settlement Networks
(Base / Solana / Alipay+)
PayPack doesn't invent new protocols. It wraps scattered capabilities into a single agent.pay().
Features
- Multi-Protocol: Supports both x402 and AP2 with automatic detection
- Signer Abstraction: Pluggable signing — LocalSigner for dev, AWSKMSSigner for production (private key never leaves HSM)
- Nano-Payment Optimized: Built for sub-$0.01 transactions with ERC-4337 batch settlement to save gas
- Security Fuse: Daily spend limits, balance checks, auditable receipts
- Full Audit Trail: Every payment generates a queryable JSON receipt
- LangChain Native: Drop-in
PayPackToolfor LangChain agents - Dual Compliance Track: USDC on-chain + Alipay AI Pay (planned)
Installation
pip install https://gitee.com/rhcjw_com/paypack/raw/master/dist/langchain_paypack-0.5.0-py3-none-any.whl
Note: Includes the full
paypackSDK (core + signer + nanopay).
Quick Start
from paypack import AgentPay
# Initialize
pay = AgentPay(
wallet_config={"private_key": "your-key"},
network="base-sepolia",
spend_limit_daily=10.0,
broadcast=False
)
# Scenario 1: Auto-handle HTTP 402
import requests
response = requests.get("https://api.data-provider.com/premium")
if response.status_code == 402:
content = pay.auto_handle_402(response)
# Scenario 2: Direct nano-payment
receipt = pay.send(
to="0xRecipientAddress",
amount=0.001,
currency="USDC"
)
print(receipt["tx_hash"])
LangChain Integration
from langchain_paypack import PayPackTool
tool = PayPackTool(
private_key="0x...",
wallet_address="0x...",
network="base-sepolia",
spend_limit_daily=10.0,
broadcast=False
)
# AI agent calls this directly
result = tool._run(to="0x...", amount=0.001, currency="USDC")
print(result)
Supported Networks
| Network | Chain ID | Currency |
|---|---|---|
| Base Sepolia (testnet) | 84532 | ETH, USDC |
| Base Mainnet | 8453 | ETH, USDC |
| Ethereum Mainnet | 1 | ETH, USDC |
| Polygon Mainnet | 137 | POL, USDC |
| Arbitrum Mainnet | 42161 | ETH, USDC |
Milestones
✅ v0.1.0 (2026-06-20) — ETH + USDC offline signing verified on Base Sepolia testnet
✅ v0.2.0 — AP2 protocol parser completed
✅ v0.3.0 (2026-06-21) — LangChain tool plugin tested, multi-chain support, balance checks, environment variable key support
✅ v0.4.0 (2026-07-08) — Signer abstraction (LocalSigner + AWSKMSSigner), ERC-4337 batch settlement (Batcher + Bundler)
✅ v0.5.0 (2026-07-08) — RPC failover (multi-node auto-switch), transaction retry (RBF + exponential backoff), limit persistence (Redis/SQLite)
| Currency | Amount | Offline-Signed TX Hash |
|---|---|---|
| ETH | 0.0001 ETH | d5f7ec94342c26a132289a9898ffd4885010089d1ddba19951117618a3992127 |
| USDC | 0.001 USDC | c4c24c4c1c8fd2ae738ed91cd87596ad2c672337b5ebf6d42a392adf61760e27 |
📌 Production-ready: RPC failover, retry, persistent limits, KMS signing — all in place.
Roadmap
| Phase | Goal | Status |
|---|---|---|
| v0.1 | Base testnet x402 payment loop (ETH + USDC) | ✅ Done |
| v0.2 | AP2 protocol support | ✅ Done |
| v0.3 | LangChain plugin release | ✅ Done |
| v0.4 | Signer abstraction + ERC-4337 batch settlement | ✅ Done |
| v0.5 | RPC failover + retry + limit persistence | ✅ Done |
| v0.6 | Alipay AI Pay integration | 🚧 Planned |
| v1.0 | PayPack Cloud (hosted service) | 🚧 Planned |
Why Now?
- Stablecoin annual transaction volume surpassed $33 trillion (2025) — 20x PayPal
- AI agent count projected to reach 22 billion (McKinsey)
- x402 protocol already processes tens of millions of transactions on Solana
- LangChain/LlamaIndex payment plugin market is completely vacant
Infrastructure is ready. Demand is exploding. The payment layer lacks a standard answer.
Contributing
Star this repo, open an issue, or reach out if you're building in the agent economy.
License
Apache License 2.0. See LICENSE.
Project details
Release history Release notifications | RSS feed
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 langchain_paypack-0.5.0.tar.gz.
File metadata
- Download URL: langchain_paypack-0.5.0.tar.gz
- Upload date:
- Size: 23.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
049815a35f39342cca5d9c0e1708a74ccb3f7a51066b57e62dc00e6ca13a588b
|
|
| MD5 |
99f029f9f0c494d280270dd27188bd77
|
|
| BLAKE2b-256 |
06331211152ef78e13d91da06502fea8524ff6d4fc683ec217cf4320821355a6
|
File details
Details for the file langchain_paypack-0.5.0-py3-none-any.whl.
File metadata
- Download URL: langchain_paypack-0.5.0-py3-none-any.whl
- Upload date:
- Size: 27.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c94380b86b573ebb1c3b5605cb61b3b609c91bb57c75022e4de2ec5e805b52a
|
|
| MD5 |
a8c9f5c734b069a8aaf043113cdb8f97
|
|
| BLAKE2b-256 |
d76d2e4fe102532a6b1f2e3987a58185aa7911dab61836577481ee8a9b470b94
|