The full upstream README, mirrored here for reference. Install config, tool schemas, adoption signals, and an original overview live on the P402 listing page.
AI payment router. Route across 300+ models, settle per request in USDC on Base or USDC.e on Tempo.
P402 sits between your AI application and every LLM provider. It handles intelligent multi-provider routing (cost / quality / speed / balanced), on-chain micropayment settlement via the x402 protocol and mppx on Base and Tempo, and spending guardrails for autonomous agents.
| Problem | P402 Solution |
|---|---|
| Hardcoded to one AI provider | Route across 300+ models automatically |
| $0.30 payment fees kill micropayments | USDC on Base: fractions of a cent per settlement |
| No spending limits for AI agents | Session budgets + AP2 mandate governance |
| Fragmented provider APIs | One OpenAI-compatible endpoint |
| No visibility into AI costs | Real-time analytics + optimization suggestions |
Install the extension — the MCP server is embedded, tools appear in Copilot agent mode immediately, no config files required:
Then run P402: Configure API Key from the command palette.
→ VS Code Marketplace · Open VSX
→ MCP docs · MCP Registry
| Mode | Optimizes For | Typical Provider |
|---|---|---|
cost | Lowest price | DeepSeek V3, Haiku 4.5, GPT-4o-mini |
quality | Best output | Claude Opus 4.6, GPT-5, Gemini 3 Pro |
speed | Lowest latency | Groq LPU, Flash models |
balanced | Equal weight (default) | Sonnet 4.6, GPT-4o, Gemini Flash |
Enforce hard spending caps for autonomous agents:
x402 is a machine-native payment protocol using HTTP 402. AI agents pay for resources using gasless EIP-3009 USDC transfers on Base L2.
Network: Base Mainnet (Chain ID: 8453) · Asset: USDC 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
P402 implements the Google A2A spec over JSON-RPC 2.0. Agents communicate through structured tasks, discover capabilities via /.well-known/agent.json, and settle payments via the x402 extension.
| Package | Description | Version |
|---|---|---|
@p402/sdk | TypeScript SDK — P402Client, types, EIP-712 mandate helpers | |
@p402/cli | CLI tool — login, chat, sessions, mandates, analytics | |
@p402/mcp-server | stdio MCP server — 6 tools over Model Context Protocol | |
@p402/mpp-method | mppx payment methods — Base EIP-3009 and Tempo TIP-20 multi-rail settlement | |
p402 VS Code extension | Embedded MCP server for VS Code, Cursor, and Windsurf — zero config |
| Example | What It Shows |
|---|---|
| 01-quickstart | Login → chat → view spend in ~20 lines |
| 02-openai-migration | Drop-in OpenAI SDK replacement |
| 03-nextjs-session-budget | Budget-capped AI in a Next.js App Router project |
| 04-a2a-agents | Two agents communicating with x402 payment gate |
| Guide | |
|---|---|
| Getting Started | Account, API key, first request |
| Authentication | API keys, env vars, security |
| Routing Guide | Modes, scoring, providers, models |
| x402 Payments | EIP-3009, wire format, settlement |
| Sessions | Session lifecycle + budget enforcement |
| A2A Protocol | JSON-RPC, mandates, Bazaar |
| CLI Reference | Full CLI command reference |
| OpenAPI Spec | Machine-readable API schema |
MIT © P402 Protocol