Protocol Overview

Understanding the x402++ four-stage transactional model

Architecture

APPLICATION LAYER
• AI Agents
• API Providers
• Applications
PROTOCOL LAYER
• x402pp-client
• x402pp-server
• Intent/Offer/Session/Receipt
BLOCKCHAIN LAYER
• Solana Programs
• Session Escrow
• Receipt Storage

Four-Stage Model

Stage 1: Intent

Agent expresses what it wants and maximum price willing to pay.

const intent = {
  intentId: "intent_abc123",
  capability: "gpt-4-inference",
  maxPricePerRequest: 0.01,  // Max willing to pay
  token: "USDC",
  sla: {
    maxLatencyMs: 2000,      // Must respond in <2s
    minUptimePercent: 99.0   // Must have 99% uptime
  },
  agentPubkey: "SolanaPublicKey..."
}

Stage 2: Offer

Provider responds with actual price and SLA guarantees, cryptographically signed.

const offer = {
  offerId: "offer_xyz789",
  intentId: "intent_abc123",     // References Intent
  providerPubkey: "ProviderKey...",
  pricePerRequest: 0.008,        // 20% discount!
  token: "USDC",
  sla: {
    maxLatencyMs: 1500,          // Better than required
    minUptimePercent: 99.5
  },
  expiresAt: 1234567890,
  signature: "base58_ed25519..."  // Cryptographic proof
}

Stage 3: Session

Prepaid channel allowing multiple requests under one payment.

const session = {
  sessionId: "session_def456",
  offerId: "offer_xyz789",       // Based on accepted Offer
  depositAmount: 1.0,            // 1 USDC deposited
  remainingBalance: 1.0,         // Decrements with each request
  pricePerRequest: 0.008,
  startedAt: 1234567890,
  expiresAt: 1234657890,         // 10 minutes later
  state: "active",
  requestCount: 0,
  creationTxSignature: "Solana..." // On-chain proof
}

// Can make 125 requests! (1.0 / 0.008 = 125)

Stage 4: Receipt

Cryptographic proof of work for each completed request.

const receipt = {
  receiptId: "receipt_ghi789",
  sessionId: "session_def456",
  requestNumber: 1,
  inputHash: "sha256(...)",        // Proves input integrity
  outputHash: "sha256(...)",       // Proves output integrity
  requestStartedAt: 1234567890,
  requestCompletedAt: 1234568390,
  latencyMs: 500,
  amountCharged: 0.008,
  slaVerification: {
    met: true,                     // SLA compliance
    metrics: {
      latency: { expected: 1500, actual: 500, met: true }
    }
  },
  providerPubkey: "ProviderKey...",
  signature: "base58_ed25519..."   // Provider's signature
}

// Verifiable proof that:
// ✓ Request was executed
// ✓ SLA was met
// ✓ Correct amount charged
// ✓ Input/output integrity preserved

Message Flow

HTTP MESSAGES
Request without session:
POST /api/inference
Host: provider.com
X-402-Intent: {"capability":"gpt-4",...}

→ Response: 402 Payment Required
X-402-Offer: {"pricePerRequest":0.008,...}
Request with session:
POST /api/inference
Host: provider.com
X-402-Session-Id: session_def456
Content: {"prompt":"Hello"}

→ Response: 200 OK
X-402-Receipt: {"receiptId":"receipt_123",...}
Content: {"response":"Hi there!"}
X (Twitter)