This monorepo contains Python SDKs for the x402 payment protocol - enabling instant micropayments for both API providers and AI agents.
fast-x402 β‘οΈ
Lightning-fast x402 payment integration for FastAPI and modern Python web frameworks. Accept micropayments with just 3 lines of code!
from fastapi import FastAPI
from fast_x402 import x402_middleware
app = FastAPI()
app.add_middleware(x402_middleware,
wallet_address="0xYourAddress",
routes={"/api/premium": "0.10"}
)x402-langchain π€
Enable your LangChain AI agents to make autonomous micropayments. Give your agents economic agency!
from x402_langchain import create_x402_agent
agent = create_x402_agent(
private_key="0xYourPrivateKey",
llm=ChatOpenAI(model="gpt-4"),
spending_limit_daily=10.0,
)- Zero Protocol Fees - Only pay ~$0.001 in blockchain gas
- Instant Settlement - 2-second finality on Base L2
- Simple Integration - Add payments in minutes, not weeks
- Built for AI - Native support for autonomous agent payments
- Secure by Design - EIP-712 signatures, spending limits, domain restrictions
# For API providers
pip install fast-x402
# For AI developers
pip install x402-langchain# Clone the repository
git clone https://github.com/x402/x402-sdk.git
cd x402-sdk
# Install dependencies
pip install poetry
poetry install
# Run tests
poetry run pytest
# Run examples
cd packages/fast-x402/examples
python basic_api.py- fast-x402 Documentation - For API providers
- x402-langchain Documentation - For AI developers
- Protocol Specification - Technical details
- Monetize APIs with micropayments
- Replace complex subscriptions with pay-per-use
- Accept payments from AI agents automatically
- Zero payment processing fees
- Build agents that can purchase data autonomously
- Access premium APIs without manual API keys
- Implement spending controls and limits
- Track agent expenditures and ROI
The x402 protocol enables instant payments through HTTP headers:
- Client requests resource β
GET /api/data - Server returns 402 β Payment details in response
- Client signs payment β EIP-712 standard
- Client retries with payment β
X-Paymentheader - Server delivers resource β Instant settlement
- EIP-712 Signatures - Cryptographically secure payments
- Replay Protection - Each payment has unique nonce
- Spending Limits - Control agent expenditures
- Domain Restrictions - Whitelist/blacklist payment destinations
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
| Package | Version | Tests | Coverage |
|---|---|---|---|
| fast-x402 | 1.0.0 | β | 95% |
| x402-langchain | 1.0.0 | β | 92% |
- JavaScript/TypeScript SDKs
- Rust implementation
- Multi-chain support (Polygon, Arbitrum)
- Advanced payment schemes ("upto", "subscription")
- Payment analytics dashboard
- Agent marketplace integration
This project is licensed under the MIT License - see the LICENSE file for details.
Built on top of the x402 protocol by Coinbase. Special thanks to:
- The Coinbase team for creating the x402 standard
- The Anthropic team for the Model Context Protocol
- The LangChain community for the agent framework
- π¬ Discord Community
- π§ Email Support
- π Issue Tracker
- π¦ Twitter Updates
Built with β€οΈ by the x402 community
Website β’ Documentation β’ GitHub