Implements the Coinbase x402 protocol to provide a standardized HTTP payment layer for AI agents to handle '402 Payment Required' responses.
Provides automated payment capabilities for CrewAI agents, allowing them to access monetized APIs via USDC on Solana without manual code changes.
Allows LangChain agents to transparently intercept 402 responses and execute payments on the Solana blockchain to access paywalled API content.
Utilizes the Solana blockchain as a payment rail to enable fast USDC transactions for AI agents, supporting both on-chain and high-speed prepaid payment systems.
Ag402 is the payment layer for the Coinbase x402 protocol. It makes AI agents pay for API calls automatically — on Solana, in USDC, with zero code changes.
Agent calls API → 402 Payment Required → Ag402 auto-pays USDC on Solana → 200 OKNon-custodial. Zero telemetry. Already in production.
Why Ag402
Zero friction
Zero code changes for buyers, sellers, and MCP developers
Three CLI commands cover everything:
ag402 run,ag402 serve,ag402 installNo config files, no API keys, no accounts, no signup
Colab one-click demo — try it in your browser, zero install
Open standard
Implements Coinbase x402 — the emerging HTTP payment standard
MIT licensed, fully open source, extensible protocol layer (
open402) with zero dependenciesAI-native docs — ships with
llms.txtso LLM agents can read the full CLI reference natively
Battle-tested
Token RugCheck — live on Solana mainnet with real USDC payments
648+ tests, 90%+ coverage, 4 security audits (24/24 issues fixed)
Multi-endpoint RPC failover + circuit breaker + async delivery retry
Blazing fast
~0.5s standard payment (
confirmedfinality, not 13sfinalized)~1ms prepaid payment (local HMAC, no on-chain call)
Zero overhead on non-402 requests — no body read, no allocation
Connection pooling, lazy imports, SQLite WAL mode
Security-first
6-layer budget protection — per-tx / per-minute / daily / circuit breaker / rollback / key redaction
Non-custodial — private keys never leave your machine
Seller-No-Key — sellers only need a public address, zero private key risk
Zero telemetry — no tracking, no IP logging, no analytics
Wallet encryption: PBKDF2 (480K iter) + AES
CI: CodeQL + Trivy + pip-audit + Semgrep + OpenSSF Scorecard
Universal compatibility
Claude Code, Cursor, Claude Desktop — MCP auto-config
OpenClaw — native Skill (SKILL.md + TOOLS.md + skill.py), not just MCP
LangChain, AutoGen, CrewAI, Semantic Kernel — works automatically
Any Python agent using
httpxorrequests— zero changes
Zero Code Changes. For Everyone.
You are... | What you do | Code changes |
Agent user (LangChain, CrewAI, AutoGen, any Python agent) |
| Zero — your agent code is untouched |
Claude Code / Cursor user |
| Zero — MCP tools appear automatically |
OpenClaw user |
| Zero — native Skill + MCP, auto-configured |
API seller (monetize your API) |
| Zero — reverse proxy handles everything |
MCP server developer |
| Zero — wrap your existing MCP server, instant paywall |
No config files. No API keys. No accounts. No code changes.
Try It Now
pip install ag402-core
ag402 init # Creates wallet + $100 test USDC — zero prompts
ag402 demo # Watch the full payment flow end-to-endOr zero install:
Already in Production
Token RugCheck
Live on Solana mainnet. AI agents pay $0.02 USDC per audit to detect rug pulls before purchasing tokens.
Three-layer audit: machine verdict → LLM analysis → raw on-chain evidence
Seller:
ag402 serve— zero code changes to the audit APIBuyer:
ag402_core.enable()— agents auto-pay, zero code changesTry it now:
curl -I https://rugcheck.aethercore.dev/v1/audit/DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263
Agent → GET /v1/audit/{token}
← 402 Payment Required ($0.02)
→ Ag402 pays USDC on Solana
→ Retries with tx_hash proof
← 200 OK + full audit reportNot a demo. Real USDC, real Solana mainnet, real users, already running.
How It Works
For Agent Users — Zero Code Changes
Your agent already uses httpx or requests under the hood. Ag402 patches them transparently:
# Option A: CLI wrapper (easiest — zero code changes)
ag402 run -- python my_agent.py
# Option B: One-liner in code
import ag402_core; ag402_core.enable()That's it. Every HTTP 402 response is now intercepted → paid → retried automatically. Your agent code stays completely untouched.
Works with LangChain, AutoGen, CrewAI, Semantic Kernel, and any framework built on httpx or requests.
For Claude Code / Cursor / OpenClaw — One Command
pip install ag402-core ag402-client-mcp
ag402 install claude-code # or: cursor / claude-desktop / openclawRestart your tool. Three MCP tools appear:
MCP Tool | What It Does |
| HTTP request → auto-pays 402 APIs |
| Check USDC balance + budget usage |
| View recent payments |
OpenClaw gets the deepest integration — Ag402 ships as a native OpenClaw Skill (SKILL.md + TOOLS.md + skill.py), not a wrapper. The skill registers natively in OpenClaw's skill system, with full tool definitions, prepaid support, and auto-fallback.
For API Sellers — Zero Code Changes
pip install ag402-core ag402-mcp
ag402 serve --target http://localhost:8000 --price 0.05 --address <YourSolanaAddress>Your existing API runs untouched behind a reverse proxy. The proxy:
Returns 402 + x402 challenge to unpaid requests
Verifies payment on-chain (no private key needed — seller only provides a public address)
Proxies paid requests through to your API
Handles replay protection, rate limiting, header sanitization
MCP server developers: same command, same result. Wrap your MCP server, get a paywall instantly.
Performance
Metric | Value | How |
Payment latency | ~0.5s |
|
Prepaid latency | ~1ms | Local HMAC-SHA256 — no on-chain call at all |
Non-402 overhead | Zero | Checks status code only — no body read, no allocation, no latency |
RPC resilience | Multi-endpoint | Exponential backoff → auto-failover to backup RPC → circuit breaker |
Delivery guarantee | Async retry | Payment succeeds but upstream fails? Background worker retries with backoff |
🆕 Prepaid System — From 500ms to 1ms
The problem: Standard x402 payments require an on-chain Solana transaction for every API call (~0.5s + gas fee). For high-frequency agents making hundreds of calls per hour, this adds up in both latency and cost.
The solution: Buy a prepaid credit pack with one on-chain payment, then use HMAC credentials for subsequent calls — zero gas, ~1ms latency.
Buy: Agent → one Solana payment → gets HMAC-SHA256 credential (N calls / M days)
Use: Agent → X-Prepaid-Credential header → local HMAC verify → 200 OK ← no chain, ~1ms5 Prepaid Tiers
Package | Duration | Calls | Price (USDC) | Cost per Call |
Starter | 3 days | 100 | $1.50 | $0.015 |
Basic | 7 days | 500 | $5.00 | $0.010 |
Pro | 30 days | 1,000 | $8.00 | $0.008 |
Business | 365 days | 5,000 | $35.00 | $0.007 |
Enterprise | 730 days | 10,000 | $60.00 | $0.006 |
How it works
Buyer purchases a prepaid pack → one Solana tx → receives HMAC credential
Each API call includes
X-Prepaid-Credentialheader → server verifies HMAC locally (~1ms)No on-chain tx needed per call → zero gas fees after initial purchase
Auto-fallback to standard x402 payment when prepaid credits are exhausted
Quick Start (Buyer)
# Step 1: Browse available packages from any ag402 gateway
ag402 prepaid buy https://your-gateway.example.com p3d_100
# Step 2: Check your credentials
ag402 prepaid statusAvailable package IDs: p3d_100 (Starter), p7d_500 (Basic), p30d_1000 (Standard), p365d_5000 (Professional), p730d_10k (Enterprise).
In production mode (real USDC), ag402 prepaid buy will:
Show the package price and seller address
Ask
Confirm payment? [Y/n]Broadcast the USDC on-chain automatically
Store the credential at
~/.ag402/prepaid_credentials.json
If the gateway times out after payment is broadcast, your credential is not lost — retry or recover:
# Retry automatically picks up the last in-flight purchase
ag402 prepaid recover https://your-gateway.example.com
# Or provide explicit tx_hash and package_id if needed
ag402 prepaid recover https://your-gateway.example.com <tx_hash> <package_id># Manage credentials
ag402 prepaid status # View all credentials grouped by seller (calls remaining / expiry)
ag402 prepaid purge # Remove expired or depleted credentialsSeller Setup
# Start gateway with prepaid support (generates a signing key if not set)
ag402-gateway --target http://localhost:8000 \
--price 0.01 \
--address <YourSolanaAddress> \
--prepaid-signing-key <secret-key>
# Or via environment variable
AG402_PREPAID_SIGNING_KEY=<secret-key> ag402-gateway ...Buyers can then discover packages at GET /prepaid/packages and purchase at POST /prepaid/purchase.
Security
HMAC-SHA256 signatures prevent credential forgery
Constant-time comparison prevents timing attacks
Credentials are scoped per buyer-seller pair
Server-side cache (5 min TTL) for repeat verification
Security — Built for Real Money
Your agent holds private keys and moves real USDC. Security is not a feature — it's the foundation.
4 rounds of security audits · 24 issues found, 24 fixed · 109 dedicated security TDD tests · 648+ total tests · 90%+ coverage
6-Layer Budget Protection
Layer | What It Does | Default |
Per-transaction cap | Hard ceiling on single payment | $5.00 |
Per-minute rate limit | Dollar + count cap | $2.00 / 5 txns |
Daily spend cap | Maximum daily spend | $10.00 (ceiling: $1,000) |
Circuit breaker | Auto-stop after consecutive failures | 3 fails → 60s cooldown |
Auto-rollback | Instant reversal on failed payments | Always on |
Key redaction | Private keys scrubbed from all logs | Always on |
Architecture Principles
Principle | How |
Non-custodial | Private keys never leave your machine. No server. No account. |
Seller-No-Key | Sellers only need a public address — zero private key risk |
Wallet encryption | PBKDF2-HMAC-SHA256 (480K iterations) + Fernet/AES |
Zero telemetry | No tracking, no IP logging, no analytics. Period. |
Replay protection | Timestamp + nonce + persistent tx_hash dedup (SQLite) |
SSRF protection | Blocks private IPs, non-HTTPS, reserved ranges |
Header sanitization | Strips Cookie, X-Forwarded-For, Authorization before proxy |
CI Pipeline (Every PR)
CodeQL · Trivy · pip-audit · Semgrep · 648+ tests · 90%+ coverage · OpenSSF Scorecard
Protocol
HTTP/1.1 402 Payment Required
WWW-Authenticate: x402 chain="solana" token="USDC" amount="0.05" address="..."
→ Client pays on-chain, retries with:
GET /data HTTP/1.1
Authorization: x402 <solana_tx_hash>
→ Server verifies on-chain → 200 OKCompatible with the Coinbase x402 open payment standard.
Architecture
┌─────────────────────────────────────────────────────────────────┐
│ Your Agent (LangChain / CrewAI / AutoGen / any Python) │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ ag402_core.enable() ← monkey-patches httpx / requests │ │
│ └──────────────┬───────────────────────────────────────────┘ │
│ │ HTTP request │
│ ▼ │
│ ┌──────────────────────────┐ ┌────────────────────────┐ │
│ │ x402 Middleware │───▶│ BudgetGuard (6 layers)│ │
│ │ Intercepts 402 response │ │ Circuit Breaker │ │
│ └──────────┬───────────────┘ └────────────────────────┘ │
│ │ Pay │
│ ▼ │
│ ┌──────────────────────────┐ ┌────────────────────────┐ │
│ │ SolanaAdapter │───▶│ RPC Failover │ │
│ │ USDC transfer + verify │ │ Exponential backoff │ │
│ └──────────┬───────────────┘ └────────────────────────┘ │
│ │ tx_hash │
│ ▼ │
│ Retry original request with Authorization: x402 <tx_hash> │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Seller Gateway (ag402 serve) │
│ ┌────────────┐ ┌──────────────┐ ┌────────────────────────┐ │
│ │ 402 + x402 │ │ On-chain │ │ Replay Guard │ │
│ │ Challenge │ │ Verification │ │ Rate Limiter │ │
│ └────────────┘ └──────────────┘ │ Header Sanitization │ │
│ └────────────────────────┘ │
│ → Proxies to your API (unchanged) │
└─────────────────────────────────────────────────────────────────┘Full architecture diagrams & state machines → docs/architecture_state.md
Packages
Package | PyPI | Role |
Protocol standard — zero dependencies | ||
Payment engine + CLI + wallet (buyer) | ||
Reverse-proxy gateway (seller) — zero code changes | ||
MCP client for AI tools (buyer) |
CLI Reference
Command | Description |
| Non-interactive setup — for AI agents (zero prompts) |
| Interactive wizard — for humans |
| Full E2E payment demo |
| Run any script with automatic x402 payment |
| Single paid request |
| Start payment gateway (seller) |
| One-command MCP setup (claude-code / cursor / openclaw) |
| Dashboard: balance, budget, security |
| Quick balance check |
| Transaction history |
| Environment health check |
| Migrate test → production |
| Export history (JSON/CSV) |
Full CLI reference → llms.txt (AI-readable, paste into your agent's context)
Documentation
Resource | Description |
AI-readable CLI reference — paste into your agent's context | |
Step-by-step MCP integration | |
Step-by-step MCP integration | |
Native Skill + MCP integration | |
System diagrams & state machines | |
Full protocol specification | |
Native OpenClaw skill definition | |
Local Solana validator setup | |
Security policy & audit history | |
Version history | |
Contribution guide |
Quick Copy-Paste
Agent user (zero code changes):
pip install ag402-core && ag402 init && ag402 run -- python my_agent.pyClaude Code / Cursor:
pip install ag402-core ag402-client-mcp && ag402 install claude-codeSell your API (zero code changes):
pip install ag402-core ag402-mcp && ag402 serve --target http://your-api:8000 --price 0.05 --address <Addr>Community
GitHub Discussions — questions, ideas, show & tell
Issue Tracker — bug reports, feature requests
Contributing Guide — PRs welcome, see "Good First Issues"
Roadmap
Milestone | Status | Description |
✅ Solana USDC payments | Shipped | Standard x402 on-chain payments (~0.5s) |
✅ Prepaid system | Shipped | HMAC credentials, ~1ms, zero gas per call |
✅ Claude Code / Cursor / OpenClaw | Shipped | One-command install, native MCP support |
✅ 4 security audits | Shipped | 24/24 issues fixed, 588+ tests |
🔜 TypeScript SDK | Next |
|
🔜 Multi-chain | Planned | Base, Polygon, Arbitrum USDC support |
🔜 Stripe fallback | Planned | Fiat payment fallback for non-crypto users |
🔜 Dashboard | Planned | Web UI for sellers — revenue, analytics, API keys |
TypeScript SDK (Coming Soon)
The next major milestone: ag402-ts — a TypeScript implementation of ag402 for the Node.js/Deno/Bun ecosystem.
// Seller: Express middleware (coming soon)
import { ag402 } from 'ag402-ts';
app.use('/api', ag402({ price: '0.01', address: '<SolanaAddress>' }));
// Buyer: Auto-pay fetch wrapper (coming soon)
import { enableAutoPay } from 'ag402-ts/client';
enableAutoPay(); // All 402 responses are auto-paid
const data = await fetch('https://paid-api.example.com/data');Why TypeScript?
MCP ecosystem is ~50% TypeScript (FastMCP-TS, official SDK)
Vercel/Cloudflare edge functions need native TS support
npm > PyPI in total package installs
Want to contribute or beta test? Open an issue or reach out on X @AetherCoreDev.
License
MIT — Open source, free forever.
This server cannot be installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.