Welcome to Aptos x402
A revolutionary HTTP 402 implementation for Aptos blockchain. Enable seamless micropayments and pay-per-use APIs with built-in blockchain verification.
Quick Start
Get up and running in minutes with our quickstart guides
AI Setup
One prompt = complete setup with Cursor or GitHub Copilot
API Reference
Complete API documentation and type definitions
Examples
Real-world examples and implementation patterns
Welcome to Aptos x402
What is Aptos x402?
Aptos x402 is a production-ready payment protocol implementation that enables APIs to require cryptocurrency payments on a per-request basis. Built on the Aptos blockchain, it brings the HTTP 402 "Payment Required" status code to life—allowing you to monetize APIs with seamless, automatic micropayments.
Think of it as a toll booth for your APIs: users pay as they go, with each request requiring a small blockchain payment. The entire payment flow is handled automatically, requiring no changes to your business logic.
The Problem We Solve
Traditional API Monetization is Broken
Current API monetization models have significant limitations:
1) Subscription Fatigue - Users pay monthly fees even when they barely use the service. Small developers can't afford dozens of subscriptions for APIs they need occasionally.
2) Usage Tiers - Rigid pricing tiers force users to overpay or underpay. You either commit to thousands of calls per month or get nothing.
3) Payment Integration Complexity - Setting up Stripe, managing subscriptions, handling billing cycles, dealing with chargebacks, currency conversions, and international payments adds weeks of development time.
4) No Microtransactions - Traditional payment processors charge 30¢ + 2.9% per transaction. This makes charging $0.001 per API call impossible.
5) Trust & Privacy - Users must share credit card information, personal data, and trust you with recurring charges. Developers must handle sensitive payment data and PCI compliance.
Enter Blockchain Micropayments
Blockchain technology enables something revolutionary: true pay-per-use at scale. Charge $0.0001 per API call with near-instant settlement and no intermediaries. Users pay only for what they use, and you get paid for every request.
But implementing blockchain payments is complex—managing wallets, signing transactions, verifying payments, handling network latency, ensuring security. This is what Aptos x402 solves.
Why x402 Protocol?
The x402 protocol, created by Coinbase, standardizes how APIs request payments using the HTTP 402 status code. When a client requests a protected resource:
- Server responds with 402 - Includes payment instructions (amount, recipient, blockchain network)
- Client signs transaction - Automatically creates and signs the payment
- Client retries with proof - Resends request with payment proof header
- Server validates and responds - Verifies payment on-chain and returns the resource
This standardized approach means any x402-compatible client can interact with any x402-compatible API, creating an open ecosystem for machine-to-machine payments.
Why Build on Aptos?
Not all blockchains are suitable for API micropayments. We chose Aptos for fundamental technical reasons:
Lightning-Fast Finality
- 1-3 second transaction confirmation means your API responses don't keep users waiting. Compare this to Ethereum (15+ seconds) or Bitcoin (10+ minutes). Fast finality enables real-time API interactions.
Negligible Transaction Costs
- ~$0.0001 per transaction makes true micropayments economically viable. On Ethereum, gas fees often exceed $5-50, making small payments impractical. On Aptos, you can charge pennies per API call and still profit.
Massive Throughput
- Thousands of transactions per second means your API can scale without blockchain bottlenecks. Aptos's parallel execution engine processes transactions concurrently, unlike sequential blockchains.
Developer-First Design
- Modern TypeScript SDK with excellent tooling, comprehensive documentation, and intuitive APIs. Aptos was built for developers in the modern era, not retrofitted from older blockchain architectures.
Account Abstraction
- Native account features enable sophisticated payment flows, sponsored transactions, and flexible fee structures without complex smart contracts.
How Aptos x402 Makes It Simple
We've abstracted away all blockchain complexity:
For API Providers
- Add one middleware file to your Next.js application and your APIs are protected. No payment logic, no blockchain code, no wallet management. Configure which endpoints require payment and how much to charge. The middleware handles everything—detecting requests, validating payments, settling transactions.
For API Consumers
- Use our drop-in axios replacement and blockchain payments happen automatically. Request a protected API, get a 402 response, and the library handles signing the transaction and retrying. From your perspective, it feels like a regular API call with a slight delay.
For Everyone
- Free hosted facilitator service handles blockchain interactions. No infrastructure to run, no blockchain nodes to sync, no transaction broadcasting to manage. Just point to our facilitator and start building.
The Architecture
Our three-tier architecture ensures security, scalability, and simplicity:
1) Client Layer - Signs transactions locally using private keys that never leave the user's machine. Handles retry logic and payment proof generation.
2) API Server Layer - Your business logic remains pure and payment-agnostic. Middleware intercepts requests, validates payments, and gates access automatically.
3) Facilitator Layer - Our hosted service verifies payment signatures, broadcasts to the blockchain, confirms settlement, and provides instant feedback. This is the bridge between HTTP and blockchain.
4) Blockchain Layer - Aptos provides immutable settlement, ensuring payments can't be reversed or disputed. Every transaction is permanently recorded.
Real-World Use Cases
AI Agent Marketplaces
Autonomous AI agents need to pay for API access without human intervention. x402 enables agents to trade services, share data, and collaborate economically.
Pay-Per-Query Data APIs
Weather data, financial feeds, geolocation services, ML model inference—charge per request rather than monthly subscriptions. Users pay only for data they actually use.
Microservices Economy
Internal company APIs can be monetized between departments. Track usage accurately, allocate costs fairly, and incentivize efficient API design.
Developer Tools
Rate limiters, API analytics, monitoring services—charge pennies per call instead of $99/month. Make professional tools accessible to hobbyists and bootstrapped startups.
Content Delivery
Serve premium content, articles, images, videos—charge micropayments per access. No paywalls, no subscriptions, just pay-per-view.
What Makes This Production-Ready?
- Comprehensive Error Handling - Network failures, insufficient balances, timeout scenarios, blockchain congestion—all handled gracefully with helpful error messages.
- Extensive Testing - Battle-tested in production environments with real money. Test suite covers edge cases, race conditions, and failure modes.
- Security First - Private keys never leave the client. Middleware validates all payments cryptographically. No trusted third parties except the blockchain itself.
- Monitoring & Observability - Built-in timing headers, transaction tracking, and audit trails. Know exactly where delays occur and how your system performs.
- TypeScript Throughout - Full type safety from client to server. Catch errors at compile time, not runtime. Excellent IDE autocomplete and inline documentation.