An open-source library for AI-native x402 integrations in the Solana ecosystem. Built for Python and Node.js, distributed via PyPI and npm, with server implementations for FastAPI and Express.js. Accelerate.
openlibx402 is an early-stage TypeScript project in the AI payments / x402 ecosystem, focused on express, fastapi, langchain, langgraph. It currently has 4 GitHub stars and 1 forks, and sits alongside related tools like a2a-server, ampersend-sdk, agoragentic-integrations, x402-sdk, trust-gated-agent-example, paynode-sdk-js.
Enable AI agents and web APIs to autonomously pay for services using HTTP 402 "Payment Required" and Solana blockchain
OpenLibx402 is a library ecosystem that implements the X402 protocol - an open standard for enabling AI agents to autonomously pay for API access using HTTP 402 "Payment Required" status code and blockchain micropayments on Solana.
✨ 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
OpenLibx402 is available in Python, TypeScript/Node.js, Go, Rust, Java, and Kotlin, with full feature parity:
All implementations provide both server and client libraries with comprehensive examples.
from fastapi import FastAPI
from openlibx402_fastapi import payment_required
app = FastAPI()
@app.get("/premium-data")
@payment_required(
amount="0.10",
payment_address="YOUR_WALLET_ADDRESS",
token_mint="USDC_MINT_ADDRESS"
)
async def get_premium_data():
return {"data": "Premium content"}
import express from 'express';
import { paymentRequired, initX402, X402Config } from '@openlibx402/express';
const app = express();
initX402(new X402Config({
paymentAddress: "YOUR_WALLET_ADDRESS",
tokenMint: "USDC_MINT_ADDRESS"
}));
app.get('/premium-data',
paymentRequired({ amount: '0.10' }),
(req, res) => res.json({ data: 'Premium content' })
);
app.listen(3000);
from openlibx402_client import X402AutoClient
from solders.keypair import Keypair
client = X402AutoClient(wallet_keypair=keypair)
# Automatically handles 402 and pays
response = await client.fetch("https://api.example.com/premium-data")
data = response.json()
import { X402AutoClient } from '@openlibx402/client';
import { Keypair } from '@solana/web3.js';
const client = new X402AutoClient(keypair);
// Automatically handles 402 and pays
const response = await client.get('https://api.example.com/premium-data');
const data = response.data;
import { PrivyX402Client, PrivyX402Config } from '@openlibx402/privy';
const config = new PrivyX402Config({
appId: process.env.PRIVY_APP_ID,
appSecret: process.env.PRIVY_APP_SECRET,
walletId: process.env.PRIVY_WALLET_ID,
});
const client = new PrivyX402Client(config);
await client.initialize();
// Automatically handles 402 and pays using Privy server wallet
const response = await client.get('https://api.example.com/premium-data');
from openlibx402_langchain import create_x402_agent
agent = create_x402_agent(
wallet_keypair=keypair,
max_payment="5.0"
)
response = agent.run("Get premium market data from the API")
# Using pip
pip install openlibx402-core openlibx402-fastapi openlibx402-client
# Or using uv (recommended)
uv sync
# Using pnpm (recommended)
pnpm install
# Or using npm
npm install @openlibx402/core @openlibx402/express @openlibx402/client
Python (uv monorepo):
git clone https://github.com/openlibx402/openlibx402.git
cd openlibx402
uv sync
TypeScript (pnpm monorepo):
git clone https://github.com/openlibx402/openlibx402.git
cd openlibx402
pnpm install
pnpm run build
See SETUP.md for detailed setup instructions.
openlibx402/
├── packages/
│ ├── python/ # Python packages (uv monorepo)
│ │ ├── openlibx402-core/ # Core protocol
│ │ ├── openlibx402-fastapi/ # FastAPI middleware
│ │ ├── openlibx402-client/ # HTTP client
│ │ ├── openlibx402-langchain/ # LangChain integration
│ │ └── openlibx402-langgraph/ # LangGraph integration
│ │
│ ├── typescript/ # TypeScript packages (pnpm monorepo)
│ │ ├── openlibx402-core/ # Core protocol (TS)
│ │ ├── openlibx402-express/ # Express.js middleware
│ │ ├── openlibx402-client/ # HTTP client (TS)
│ │ ├── openlibx402-langchain/ # LangChain.js integration
│ │ ├── openlibx402-langgraph/ # LangGraph.js integration
│ │ └── openlibx402-privy/ # Privy server wallet integration
│ │
│ ├── go/ # Go packages
│ │ ├── openlibx402-core/ # Core protocol (Go)
│ │ ├── openlibx402-client/ # HTTP client (Go)
│ │ ├── openlibx402-nethttp/ # net/http middleware
│ │ └── openlibx402-echo/ # Echo framework integration
│ │
│ ├── rust/ # Rust packages (Cargo workspace)
│ │ ├── openlibx402-core/ # Core protocol (Rust)
│ │ ├── openlibx402-client/ # HTTP client (Rust)
│ │ ├── openlibx402-rocket/ # Rocket framework integration
│ │ └── openlibx402-actix/ # Actix Web integration
│ │
│ ├── java/ # Java packages (Maven)
│ │ ├── openlibx402-core/ # Core protocol (Java)
│ │ └── openlibx402-client/ # HTTP client (Java)
│ │
│ └── kotlin/ # Kotlin packages (Gradle)
│ ├── openlibx402-core/ # Core protocol (Kotlin)
│ └── openlibx402-client/ # HTTP client (Kotlin)
│
├── examples/
│ ├── python/
│ │ ├── fastapi-server/ # Python FastAPI demo
│ │ ├── langchain-agent/ # Python LangChain agent
│ │ └── langgraph-workflow/ # Python LangGraph workflow
│ ├── typescript/
│ │ ├── express-server/ # TypeScript Express.js demo
│ │ └── privy-agent/ # Privy server wallet agent
│ ├── go/
│ │ ├── nethttp-server/ # Go net/http demo
│ │ └── echo-server/ # Go Echo demo
│ └── rust/
│ ├── rocket-server/ # Rust Rocket demo
│ └── actix-server/ # Rust Actix Web demo
│
├── pnpm-workspace.yaml # TypeScript monorepo config
├── pyproject.toml # Python monorepo config
├── package.json # Root TypeScript package
├── Makefile # TypeScript build commands
└── docs/
├── SETUP.md # Setup guide
└── openlibx402-technical-spec.md # Technical specification
cd examples/fastapi-server
pip install -r requirements.txt
python main.py
Visit http://localhost:8000/docs for API documentation.
cd examples/langchain-agent
pip install -r requirements.txt
export OPENAI_API_KEY='your-key-here'
python main.py
cd examples/langgraph-workflow
pip install -r requirements.txt
python main.py
┌─────────────┐ ┌──────────────┐ ┌────────────┐
│ AI Agent │ ─1─→ │ API Server │ │ Blockchain │
│ (Client) │ │ (Server) │ │ (Solana) │
└─────────────┘ └──────────────┘ └────────────┘
│ │ │
│ GET /data │ │
├───────────────────────→│ │
│ │ │
│ 402 Payment Required │ │
│ + Payment Details │ │
│←───────────────────────┤ │
│ │ │
│ Create & Broadcast │ │
│ Payment Transaction │ │
├────────────────────────┼───────────────────────→│
│ │ │
│ │ Verify Transaction │
│ │←───────────────────────┤
│ │ │
│ GET /data │ │
│ + Payment Auth Header │ │
├───────────────────────→│ │
│ │ │
│ 200 OK + Data │ │
│←───────────────────────┤ │
📚 Setup Guide - Complete setup for all languages 🚀 Technical Specification - Complete architecture
🐍 Python README - Python implementation guide 📖 TypeScript README - TypeScript implementation guide 🐹 Go README - Go implementation guide 🦀 Rust README - Rust implementation guide ☕ Java README - Java implementation guide 🎯 Kotlin README - Kotlin implementation guide
X402_PAYMENT_ADDRESS=YourSolanaWalletAddress
X402_TOKEN_MINT=USDC_MINT_ADDRESS
X402_NETWORK=solana-devnet
X402_RPC_URL=https://api.devnet.solana.com
from openlibx402_fastapi import X402Config, init_x402
config = X402Config(
payment_address="YOUR_WALLET",
token_mint="USDC_MINT",
network="solana-devnet"
)
init_x402(config)
🔐 Key Security Features:
⚠️ Security Best Practices:
from openlibx402_core.testing import MockSolanaPaymentProcessor
processor = MockSolanaPaymentProcessor()
processor.balance = 100.0
# Use in tests without real blockchain
client = X402AutoClient(wallet_keypair=test_keypair)
client.client.processor = processor
We welcome contributions! Here's how you can help:
# Clone repository
git clone https://github.com/openlibx402/openlibx402.git
cd openlibx402
# Install development dependencies
pip install -e "packages/python/openlibx402-core[dev]"
pip install -e "packages/python/openlibx402-fastapi[dev]"
pip install -e "packages/python/openlibx402-client[dev]"
# Run tests
pytest packages/python/*/tests
# Format code
black packages/python/
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: 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.
OpenLibx402 is released under the MIT License.
Built with ❤️ for the autonomous AI economy
Production-ready A2A Protocol Server with dual protocol support (HTTP REST + JSON-RPC 2.0). Built on SceneGraphManager v2.0.0 for JSON-driven AI workflow orchestration with LangGraph.
Tooling for building applications with x402 payment capabilities. Supports buyer and seller roles.
Public adapters and discovery catalog for Triptych OS (Agent OS): agent frameworks, MCP/A2A/x402 protocols, workflows, wallets, SDKs, and examples for execute-first routing, governed handoffs, and receipt-aware agent commerce.
x402 Payment Protocol SDKs - Dead simple micropayments for APIs and AI agents
Trust-gated AI agent examples. Check CraftedTrust before connecting to any MCP server. Python (LangGraph) + TypeScript.
Node.js/TypeScript middleware for merchants to intercept API requests and verify on-chain x402 payments.
An open SDK for agentic payments. Let AI agents make payments, hold funds, and move money across chains with policy enforcement and human approval built in.
Golang SDK for A2A Protocol
Client SDK for the Vybe x402 API. Pay-per-call USDC over HTTP and prepaid-credit WebSocket streaming for Vybe's Solana analytics API. Built for AI agents.
Rust SDK for the Machine Payments Protocol
Building blocks for Agentic payments (x402, MPP, AP2) for TypeScript, Rust, Go, Python, Ruby, PHP, Lua, Kotlin and Swift.
Opinionated React Native crypto x AI chat app boilerplate with embedded wallet support, conversational AI, and dynamic UI component injection