Corex402 Documentation

Complete guide to building autonomous AI commerce systems with the x402++ protocol.

x402 vs x402++: What Changed?

x402 (the original) introduced the concept of using HTTP 402 "Payment Required" for blockchain-based API payments. It worked, but had a critical flaw: every request required a separate blockchain transaction, making it slow and expensive.

x402++ (the evolution) fixes this with prepaid sessions. Instead of 100 blockchain transactions for 100 requests, x402++ uses just 2: one to open the session, one to close it. Everything in between happens off-chain with automatic balance tracking.

3.5x
Cheaper
6x
Faster
50x
Fewer Txs

Complete Protocol Flow

01
Agent creates Intent
Express needs, max price, SLA requirements
02
Provider sends Offer
Actual price, SLA guarantees, Ed25519 signature
03
Agent creates Session
Deposits funds on Solana (1 blockchain tx)
04
Agent makes requests
100+ requests, all off-chain, auto-deducted
05
Agent closes Session
Get refund for remaining balance (1 blockchain tx)
Key Insight: Only steps 03 and 05 touch the blockchain. Step 04 (all the requests) happens off-chain with instant balance deduction. This is why x402++ is 50x more efficient than x402.

Quick Install

For AI Agents
npm install x402pp-client
For API Providers
npm install x402pp-server

Your First Agent

import { X402Client } from 'x402pp-client';

const client = new X402Client({ connection, wallet });

// 1. Express your needs
const intent = client.createIntent({
  capability: 'gpt-4-inference',
  maxPricePerRequest: 0.01,
  token: 'USDC',
});

// 2. Negotiate
const offer = await client.negotiate(
  'https://api.provider.com',
  intent
);

// 3. Create session
const session = await client.createSession(offer);

// 4. Execute (payment automatic!)
const result = await client.executeRequest(
  session.sessionId,
  { prompt: 'Hello AI!' }
);

console.log(result.data);     // Response
console.log(result.receipt);  // Proof
X (Twitter)