Thanks to visit codestin.com
Credit goes to github.com

Skip to content

samthedataman/x402-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

x402 Payment Protocol SDK Monorepo πŸš€

PyPI - fast-x402 PyPI - x402-langchain Python License: MIT

This monorepo contains Python SDKs for the x402 payment protocol - enabling instant micropayments for both API providers and AI agents.

πŸ“¦ Packages

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

🎯 Key Features

  • 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

πŸš€ Quick Start

Install Individual Packages

# For API providers
pip install fast-x402

# For AI developers  
pip install x402-langchain

Development Setup

# 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

πŸ“– Documentation

πŸ’‘ Use Cases

For API Providers (fast-x402)

  • Monetize APIs with micropayments
  • Replace complex subscriptions with pay-per-use
  • Accept payments from AI agents automatically
  • Zero payment processing fees

For AI Developers (x402-langchain)

  • Build agents that can purchase data autonomously
  • Access premium APIs without manual API keys
  • Implement spending controls and limits
  • Track agent expenditures and ROI

πŸ—οΈ Architecture

The x402 protocol enables instant payments through HTTP headers:

  1. Client requests resource β†’ GET /api/data
  2. Server returns 402 β†’ Payment details in response
  3. Client signs payment β†’ EIP-712 standard
  4. Client retries with payment β†’ X-Payment header
  5. Server delivers resource β†’ Instant settlement

πŸ›‘οΈ Security

  • EIP-712 Signatures - Cryptographically secure payments
  • Replay Protection - Each payment has unique nonce
  • Spending Limits - Control agent expenditures
  • Domain Restrictions - Whitelist/blacklist payment destinations

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Workflow

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

πŸ“Š Status

Package Version Tests Coverage
fast-x402 1.0.0 βœ… 95%
x402-langchain 1.0.0 βœ… 92%

🚦 Roadmap

  • JavaScript/TypeScript SDKs
  • Rust implementation
  • Multi-chain support (Polygon, Arbitrum)
  • Advanced payment schemes ("upto", "subscription")
  • Payment analytics dashboard
  • Agent marketplace integration

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

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

πŸ“ž Support


Built with ❀️ by the x402 community

Website β€’ Documentation β€’ GitHub

About

x402 Payment Protocol SDKs - Dead simple micropayments for APIs and AI agents

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published