API Reference
Welcome to the P402 production API. Execute gasless USDC payments on Base L2 using EIP-3009 transferWithAuthorization. Global facilitator network with sub-50ms verification times.
V1 — Payment Layer
x402 payment protocol: route planning, settlement, facilitator management, AP2 policy mandates, and protocol governance. The cryptographic foundation for agent payments.
V2 — Orchestration Layer
OpenAI-compatible AI routing: multi-provider completions, semantic caching, session management, and real-time cost optimization. Drops into any OpenAI SDK.
Authentication
All API requests must be authenticated using your P402 API Key. You can manage your keys in the Dashboard. Pass the key in the Authorization header for every request.
Security Best PracticeNever expose your API key in client-side code (browsers, mobile apps). Always route requests through a secure backend service to keep your credentials safe.
Error Codes
P402 uses a unified error format across all endpoints. Errors are returned with an appropriate HTTP status code and a JSON body containing an error object.
{
"error": {
"type": "invalid_request", // Category
"code": "INVALID_INPUT", // Specific machine-readable code
"message": "Amount must be greater than 0"
}
}Common Error Codes
INVALID_INPUTMissing or malformed request parameters.
UNAUTHORIZEDMissing or invalid API key.
POLICY_DENIEDRequest blocked by governance policy (budgets, allowed actions).
SETTLEMENT_FAILEDOn-chain verification failed or transaction not found.
RATE_LIMITEDToo many requests. Please slow down.
INTERNAL_ERRORUnexpected server-side error.
https://p402.io/api/v1/facilitator/verifyVerify Payment Authorization
Verify an EIP-3009 payment authorization without executing it. Uses the x402 wire format: paymentPayload (containing the signed authorization) and paymentRequirements (the terms being paid for). Returns { isValid, payer } on success.
Parameters
x402 payment payload containing scheme, network, and the signed authorization + signature
The payment requirements: scheme, network, maxAmountRequired, payTo, asset, resource
Example Request
curl https://p402.io/api/v1/facilitator/verify \
-H "Content-Type: application/json" \
-d '{
"paymentPayload": {
"x402Version": 2,
"scheme": "exact",
"network": "eip155:8453",
"payload": {
"signature": "0x...",
"authorization": {
"from": "0x...",
"to": "0xb23f146251e3816a011e800bcbae704baa5619ec",
"value": "1000000",
"validAfter": "0",
"validBefore": "1735689600",
"nonce": "0x..."
}
}
},
"paymentRequirements": {
"scheme": "exact",
"network": "eip155:8453",
"maxAmountRequired": "1000000",
"resource": "https://example.com/api",
"description": "AI inference",
"payTo": "0xb23f146251e3816a011e800bcbae704baa5619ec",
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
}
}'Example Response
{
"isValid": true,
"payer": "0x..."
}https://p402.io/api/v1/facilitator/settleExecute Gasless Settlement
Execute a gasless USDC settlement using the x402 wire format. The facilitator pays gas fees and executes the EIP-3009 transferWithAuthorization. Returns a SettleResponse with { success, transaction, network, payer }.
Parameters
x402 payment payload containing the signed authorization and 65-byte signature
The payment requirements: scheme, network, maxAmountRequired, payTo, asset
Example Request
curl https://p402.io/api/v1/facilitator/settle \
-H "Content-Type: application/json" \
-d '{
"paymentPayload": {
"x402Version": 2,
"scheme": "exact",
"network": "eip155:8453",
"payload": {
"signature": "0x...",
"authorization": {
"from": "0x...",
"to": "0xb23f146251e3816a011e800bcbae704baa5619ec",
"value": "1000000",
"validAfter": "0",
"validBefore": "1735689600",
"nonce": "0x..."
}
}
},
"paymentRequirements": {
"scheme": "exact",
"network": "eip155:8453",
"maxAmountRequired": "1000000",
"resource": "https://example.com/api",
"description": "AI inference",
"payTo": "0xb23f146251e3816a011e800bcbae704baa5619ec",
"asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"
}
}'Example Response
{
"success": true,
"transaction": "0x88df016a12fa890a...",
"network": "eip155:8453",
"payer": "0x..."
}/api/v1/receiptsCreate Payment Receipt
Create a reusable payment receipt from a successful transaction. Receipts can be used for multiple AI sessions without additional signatures.
Parameters
Transaction hash from successful settlement
Session identifier for tracking
Amount in USD (decimal)
Optional metadata (payer, network, token)
Example Request
curl https://p402.io/api/v1/receipts \
-H "Content-Type: application/json" \
-d '{
"txHash": "0x88df01e...",
"sessionId": "session_123",
"amount": 1.0,
"metadata": {
"payer": "0x...",
"network": "eip155:8453",
"token": "USDC"
}
}'Example Response
{
"success": true,
"receiptId": "rcpt_456",
"validUntil": "2024-12-31T23:59:59Z",
"amount": 1,
"network": "eip155:8453",
"token": "USDC"
}/api/v2/chat/completionsChat Completions
OpenAI-compatible endpoint for generating AI responses with P402 orchestration. Supports multi-provider routing, semantic caching, and real-time cost tracking.
Parameters
The model to use. If omitted, P402 will select the optimal model based on your routing mode.
A list of messages comprising the conversation so far.
Routing mode: "cost", "quality", "speed", or "balanced" (default).
Enable semantic caching to eliminate redundant API calls.
Example Request
curl https://p402.io/api/v2/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $P402_API_KEY" \
-d '{
"messages": [{"role": "user", "content": "Explain P402."}],
"p402": { "mode": "cost", "cache": true }
}'Example Response
{
"id": "chatcmpl-123",
"choices": [
{
"message": {
"content": "P402 is an AI orchestration layer..."
}
}
],
"p402_metadata": {
"provider": "anthropic",
"cost_usd": 0.00045,
"cached": false,
"latency_ms": 840
}
}/api/v2/modelsList Models
Dynamically retrieve all 300+ models accessible via the OpenRouter Meta-Provider, including real-time pricing, context windows, and model capabilities.
Example Request
curl https://p402.io/api/v2/modelsExample Response
{
"object": "list",
"total": 339,
"data": [
{
"id": "openai/gpt-4o",
"name": "GPT-4o",
"context_window": 128000,
"pricing": {
"prompt": "0.000005",
"completion": "0.000015"
}
}
]
}/api/v2/analytics/recommendationsCost Recommendations
Get AI-powered cost optimization suggestions based on your historical usage patterns.
Example Request
curl https://p402.io/api/v2/analytics/recommendationsExample Response
{
"recommendations": [
{
"type": "model_switch",
"title": "Switch to Haiku",
"saved_monthly": 245
}
]
}/api/a2aSubmit x402 Payment
Submit cryptographic proof of payment (EIP-3009 signature or transaction hash) for an A2A task. Mandatory step in the A2A x402 Extension 3-message flow.
Parameters
The unique payment identifier provided in the payment-required message.
The payment scheme used: "exact", "onchain", or "receipt".
The EIP-3009 permit signature (required for "exact" scheme).
The blockchain transaction hash (required for "onchain" scheme).
Example Request
curl https://p402.io/api/a2a \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "x402/payment-submitted",
"params": {
"payment_id": "pay_123",
"scheme": "exact",
"signature": "0x..."
},
"id": 1
}'Example Response
{
"jsonrpc": "2.0",
"result": {
"payment_id": "pay_123",
"status": "completed",
"receipt": {
"receipt_id": "rec_456",
"signature": "0x..."
}
},
"id": 1
}/api/v1/router/planPlan Route
Calculates the optimal routing path for a resource request without executing it. Returns payment requirements and facilitator selection.
Parameters
The target resource identifier.
Payment preferences { network, scheme, amount, asset }.
Optional policy ID to enforce during planning.
Example Request
curl https://p402.io/api/v1/router/plan \
-H "Content-Type: application/json" \
-d '{
"routeId": "MODEL_GPT4",
"payment": {
"network": "eip155:8453",
"scheme": "exact",
"amount": "0.50",
"asset": "USDC"
}
}'Example Response
{
"decision_id": "trace_abc123",
"route": {
"id": "route_xyz",
"facilitator_url": "https://...",
"cost": 0.5
},
"payment_headers": {
"X-Payment-Required": "true"
}
}/api/v1/router/settleSettle Payment
Records an on-chain settlement for a planned route. Use this to finalize a transaction after the user has paid.
Parameters
The verified transaction hash.
Amount settled.
Asset symbol (e.g. USDC).
The decision ID from the /plan response.
Example Request
curl https://p402.io/api/v1/router/settle \
-H "Content-Type: application/json" \
-d '{
"txHash": "0x...",
"amount": "0.50",
"asset": "USDC",
"decisionId": "trace_abc123"
}'Example Response
{
"scheme": "onchain",
"settled": true,
"facilitatorId": "chain_base",
"receipt": {
"txHash": "0x...",
"verifiedAmount": "0.50",
"asset": "USDC",
"timestamp": "2026-01-15T12:00:00Z"
}
}/api/v1/intelligence/auditAutonomous Policy Audit
Audits A2A traffic flows to identify cost optimizations and budget compliance. Powered by Gemini 3 Pro.
Parameters
History window to analyze (default: 7).
Actually execute the recommended optimizations (Autonomous mode).
Example Request
curl -X POST https://p402.io/api/v1/intelligence/audit \
-H "Content-Type: application/json" \
-d '{"days": 7, "execute": true}'Example Response
{
"audit_id": "audit_123",
"thinking_trace": [
"Analyzing 5,432 decisions...",
"Detected GPT-4 overkill on simple tasks.",
"Executing model_substitution..."
],
"total_savings": 42.5
}/api/v1/intelligence/code-auditSecurity & Privacy Audit
Performs a deep audit of agent infrastructure for security vulnerabilities and privacy leaks.
Parameters
The agent/application code to audit.
Example Request
curl -X POST https://p402.io/api/v1/intelligence/code-audit \
-H "Content-Type: application/json" \
-d '{"code": "import openai\nclient = openai.OpenAI(...)"}'Example Response
{
"report": "# Audit Report\n\nRISK SCORE: 8/10\n- Dangerous loop detected...",
"metrics": {
"riskScore": 8,
"costPerHour": 15
}
}/api/v1/intelligence/statusGovernance Status
Retrieves the current status of the protocol governance layer and active policy enforcement.
Example Request
curl https://p402.io/api/v1/intelligence/statusExample Response
{
"agents": {
"economist": "online",
"sentinel": "active",
"memory": "92% hit rate"
},
"total_savings": 12450.8
}