OpenLibx402: Autonomous Payments for AI Agents¶
Enable AI agents and web APIs to autonomously pay for services using HTTP 402 "Payment Required" and Solana blockchain
What is OpenLibx402?¶
OpenLibx402 is a library ecosystem that implements the X402 protocol - an open standard for enabling AI agents to autonomously pay for API access, data, and digital services using the HTTP 402 "Payment Required" status code and blockchain micropayments.
Key Features¶
✨ One-Line Integration - Add payments to APIs with a single decorator
🤖 AI-Native - Built specifically for autonomous agent workflows
⚡ Instant Settlement - Payments settle in ~200ms on Solana
💰 Micropayments - Support payments as low as $0.001
🔐 No Accounts - No API keys, subscriptions, or manual billing
🌐 Chain-Agnostic Design - Solana first, architected for multi-chain
🛠️ Framework Integrations - FastAPI, LangChain, LangGraph, and more
Quick Start¶
Server (FastAPI)¶
Client (Auto-Payment)¶
LangChain Agent¶
How It Works¶
Documentation¶
📚 Technical Specification - Complete architecture and design 📖 Quick Reference - Common patterns and examples 📝 Project Summary - Overview and next steps 🤖 RAG Chatbot Documentation - AI-powered chatbot with X402 payments
Guides¶
🧪 Testing Guide - Testing strategies and mock processors 🚀 Production Deployment - Deploy to production environments 🔧 Troubleshooting - Common issues and solutions 🔄 Language Comparison - Choose the right language for your project
Feature Parity Matrix¶
| Feature | Python | TypeScript | Go | Rust | Java | Kotlin |
|---|---|---|---|---|---|---|
| Core Protocol | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Client Library | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Auto-Payment Client | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Server Middleware | ✅ FastAPI | ✅ Express, Next.js | ✅ net/http, Echo | ✅ Rocket, Actix | ⚠️ Custom | ⚠️ Custom |
| LangChain Integration | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| LangGraph Integration | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| Payment Verification | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Mock Processors | ✅ | ✅ | ✅ | ✅ | ⚠️ | ⚠️ |
| Async Support | ✅ async/await | ✅ Promises | ✅ Goroutines | ✅ async/await | ⚠️ Future | ✅ Coroutines |
| Type Safety | ⚠️ Runtime | ✅ Compile | ✅ Compile | ✅ Compile | ✅ Compile | ✅ Compile |
| Examples | 3 | 8 | 2 | 2 | 1 | 1 |
| Documentation | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete |
Legend¶
- ✅ Fully supported
- ⚠️ Partial support or requires custom implementation
- ❌ Not available
Packages¶
Core Protocol (6 Languages)¶
Python:
- openlibx402-core - Core protocol implementation
- Python Documentation
TypeScript:
- @openlibx402/core - Core protocol (TypeScript)
- TypeScript Documentation
Go:
- openlibx402-core - Core protocol (Go)
- Go Documentation
Rust:
- openlibx402-core - Core protocol (Rust)
- Rust Documentation
Java:
- openlibx402-core - Core protocol (Java)
- Java Documentation
Kotlin:
- openlibx402-core - Core protocol (Kotlin)
- Kotlin Documentation
Server Frameworks¶
Python:
- openlibx402-fastapi - FastAPI middleware
- FastAPI Guide
TypeScript:
- @openlibx402/express - Express.js middleware
- @openlibx402/nextjs - Next.js API routes
- Express Guide | Next.js Guide
Go:
- openlibx402-nethttp - net/http middleware
- openlibx402-echo - Echo framework integration
- Go Server Guide
Rust:
- openlibx402-rocket - Rocket framework integration
- openlibx402-actix - Actix Web integration
- Rust Server Guide
Java & Kotlin: - Custom Spring Boot / Ktor implementations - Java Server Guide | Kotlin Server Guide
Client Libraries (All Languages)¶
- Python:
openlibx402-client - TypeScript:
@openlibx402/client - Go:
openlibx402-client - Rust:
openlibx402-client - Java:
openlibx402-client - Kotlin:
openlibx402-client
All clients support both explicit and automatic payment handling.
AI Agent Integrations¶
Python:
- openlibx402-langchain - LangChain Tool & Middleware
- openlibx402-langgraph - LangGraph nodes
TypeScript:
- @openlibx402/langchain - LangChain.js integration
- @openlibx402/langgraph - LangGraph.js integration
Specialized Packages¶
RAG & Chatbot:
- @openlibx402/ragbot - RAG utilities (embeddings, vector search, LLM)
- RAGBot Documentation
- Chatbot Application - Production RAG chatbot with X402 payments
Use Cases¶
For API Providers¶
- 💵 Monetize APIs with pay-per-use pricing
- 🚫 Eliminate API key management
- ⚡ Instant payment settlement
- 🛡️ No chargebacks or fraud risk
For AI Agents¶
- 🔓 Access premium data without human intervention
- 💰 Pay exactly for what you use
- 🌍 No geographic restrictions
- 🤖 Fully autonomous operation
Real-World Examples¶
- 📊 Research agent paying per financial data point
- 🎯 Trading bot accessing real-time market data
- 📰 Content aggregator paying per article
- 🖼️ Image generation API charging per image
- ☁️ GPU compute charged per minute
Architecture¶
Development Status¶
✅ Phase 1: Python (Complete)¶
- ✅ Core package (Python)
- ✅ FastAPI integration
- ✅ Client library
- ✅ LangChain integration
- ✅ LangGraph integration
- ✅ Example implementations
✅ Phase 2: TypeScript (Complete)¶
- ✅ Core package (TypeScript)
- ✅ Express.js middleware
- ✅ Next.js integration
- ✅ Client library (TS)
- ✅ LangChain.js integration
- ✅ LangGraph.js integration
- ✅ Frontend examples (Vue, Nuxt, Astro)
✅ Phase 3: Go (Complete)¶
- ✅ Core package (Go)
- ✅ Client library (Go)
- ✅ net/http middleware
- ✅ Echo framework integration
- ✅ Example servers
✅ Phase 4: Rust (Complete)¶
- ✅ Core package (Rust)
- ✅ Client library (Rust)
- ✅ Rocket framework integration
- ✅ Actix Web integration
- ✅ Example servers
✅ Phase 5: Java & Kotlin (Complete)¶
- ✅ Core packages (Java & Kotlin)
- ✅ Client libraries (Java & Kotlin)
- ✅ Maven & Gradle setups
- ✅ Coroutine support (Kotlin)
- ✅ Documentation & examples
✅ Phase 6: Chatbot & RAGBot (Complete)¶
- ✅ RAG Chatbot (Deno + Hono)
- ✅ RAGBot TypeScript package
- ✅ OpenAI & Pinecone integration
- ✅ USDC payment integration
- ✅ Rate limiting & streaming
- ✅ Deno Deploy deployment
🔲 Phase 7: Ecosystem Expansion¶
- [ ] Flask middleware (Python)
- [ ] Django middleware (Python)
- [ ] Additional agent frameworks
- [ ] CLI tools
- [ ] Admin dashboard
🔲 Phase 8: Advanced Features¶
- [ ] Multi-chain support (Ethereum, Base)
- [ ] Payment batching
- [ ] Subscription management
- [ ] Analytics & monitoring
- [ ] Browser extension
- [ ] Wallet UI components
Installation¶
Python¶
TypeScript¶
Go¶
Rust¶
Java¶
Kotlin¶
Examples¶
FastAPI Server¶
LangChain Agent¶
LangGraph Workflow¶
Configuration¶
Environment Variables¶
Code Configuration¶
Security¶
🔐 Key Security Features: - Private keys never leave client - On-chain transaction verification - Nonce-based replay protection - Payment expiration timestamps - Maximum payment limits - HTTPS required for production
⚠️ Security Best Practices: - Never log private keys - Use environment variables for secrets - Validate all payment fields - Set reasonable payment timeouts - Implement rate limiting - Use hardware wallets in production
Testing¶
Mock Payment Processor¶
Test Server¶
Contributing¶
We welcome contributions! Here's how you can help:
- 🐛 Report bugs via GitHub Issues
- 💡 Suggest features or improvements
- 📝 Improve documentation
- 🔧 Submit pull requests
- ⭐ Star the repository
Development Setup¶
Roadmap¶
✅ 2025 Q4 (Completed)¶
- ✅ Technical specification
- ✅ Core libraries (Python, TypeScript, Go, Rust, Java, Kotlin)
- ✅ Server middleware (FastAPI, Express, Next.js, net/http, Echo, Rocket, Actix)
- ✅ Client libraries (all 6 languages)
- ✅ LangChain/LangGraph integrations (Python & TypeScript)
- ✅ RAG Chatbot with X402 payments
- ✅ RAGBot package for reusable RAG utilities
- ✅ Frontend examples (Vue, Nuxt, Astro)
- ✅ Comprehensive documentation (75+ pages)
- ✅ Testing guides and production deployment guides
🔜 2025 Q4 - 2026 Q1 (pending)¶
- 🔲 Flask middleware (Python)
- 🔲 Django middleware (Python)
- 🔲 CLI tools for wallet management
- 🔲 Payment analytics dashboard
- 🔲 Additional AI agent frameworks
- 🔲 Package publishing to npm/PyPI/crates.io
🔮 2026¶
- 🔲 Multi-chain support (Ethereum, Base L2)
- 🔲 Payment batching & subscriptions
- 🔲 Admin dashboard for API providers
- 🔲 Real-time analytics & monitoring
- 🔲 Browser extension for payment management
- 🔲 Wallet UI components
- 🔲 Zapier/Make.com integrations
- 🔲 Enterprise features (SSO, team management)
FAQ¶
Q: Why Solana first?
A: Solana offers ~200ms transaction finality and <$0.0001 fees, making it ideal for micropayments.
Q: Will this support other blockchains?
A: Yes! The architecture is designed to be chain-agnostic. Ethereum and Base L2 support is planned.
Q: Do I need crypto knowledge to use this?
A: Minimal. The libraries handle blockchain complexity. You just need a wallet and some tokens.
Q: Is this production-ready?
A: Not yet. We're currently in development. Follow progress on GitHub.
Q: How much do transactions cost?
A: On Solana devnet/mainnet, transaction fees are <$0.0001. Payment amounts are configurable.
Q: Can agents really operate autonomously?
A: Yes! Once configured with a wallet, agents can discover, pay for, and use APIs without human intervention.
Resources¶
- 📄 X402 Whitepaper
- 🌐 X402 Protocol Website
- 📚 Solana Documentation
- 🔗 SPL Token Program
- 🦜 LangChain Docs
- 🕸️ LangGraph Docs
Community¶
- 💬 Discord - Coming soon
- 🐦 Twitter - @openlibx402
- 📧 Email - x402@openlib.xyz
License¶
OpenLibx402 is released under the MIT License.
Acknowledgments¶
- Built on the X402 protocol by Coinbase
- Powered by Solana blockchain
- Integrates with LangChain and LangGraph
Built with ❤️ for the autonomous AI economy