Intent → Offer Negotiation

How agents and providers negotiate pricing dynamically

Negotiation Flow

1
Agent Creates Intent
Expresses capability needed, maximum price, and SLA requirements
{ capability: "gpt-4", maxPrice: 0.01, sla: {...} }
2
Agent Sends Intent to Provider
POST /api with X-402-Intent header
3
Provider Creates Signed Offer
Calculates price, signs with Ed25519, returns 402 status
{ price: 0.008, signature: "ed25519..." }
4
Agent Verifies & Accepts
Checks signature, validates price ≤ maxPrice, creates session
DETAILED MESSAGE FLOW
Agent                                    Provider
  │                                          │
  │ 1. Create Intent                         │
  ├─ {                                       │
  │    capability: "gpt-4",                  │
  │    maxPricePerRequest: 0.01,  ──┐       │
  │    token: "USDC"                 │       │
  │  }                               │       │
  │                                  │       │
  │ 2. Send Intent                   │       │
  ├──────────────────────────────────┼───────>│
  │   POST /api/inference            │       │
  │   X-402-Intent: {...}            │       │
  │                                  │       │
  │                                  │    3. Evaluate Intent
  │                                  │    ├─ Check capability
  │                                  │    ├─ Calculate price
  │                                  │    ├─ Check if can meet SLA
  │                                  │    │
  │                                  │    4. Create Offer
  │                                  │    ├─ {
  │                                  │    │    pricePerRequest: 0.008,
  │                                  │    │    sla: { maxLatencyMs: 1500 }
  │                                  │    │  }
  │                                  │    │
  │                                  │    5. Sign Offer
  │                                  │    ├─ Ed25519 signature
  │                                  │    │
  │ 6. Receive Offer                 │    │
  │<─────────────────────────────────┼────┤
  │   402 Payment Required           │    │
  │   X-402-Offer: {...}             │    │
  │                                  │    │
  │ 7. Verify Signature              │    │
  ├─ verifyOffer(offer) ✓            │    │
  │                                  │    │
  │ 8. Check Price                   │    │
  ├─ 0.008 <= 0.01 ✓                 │    │
  │                                  │    │
  │ 9. Accept Offer                  │    │
  ├─ Create session ─────────────────┼────>│

Intent Structure

Intent Object
interface Intent {
  // Identification
  version: string;              // Protocol version "0.1.0"
  timestamp: number;            // Unix timestamp
  intentId: string;             // Unique ID
  
  // Requirements
  capability: string;           // What service needed
  maxPricePerRequest: number;   // Price ceiling
  token: SupportedToken;        // Payment token
  
  // Optional
  maxSessionBudget?: number;    // Total budget limit
  sessionDurationMs?: number;   // Desired session length
  sla?: {
    maxLatencyMs?: number;      // Max response time
    minUptimePercent?: number;  // Min availability
    maxErrorRatePercent?: number; // Max error rate
  };
  
  // Identity
  agentPubkey: string;          // Solana public key
  metadata?: Record<string, any>;
}

Offer Structure

Offer Object
interface Offer {
  // Identification
  version: string;
  timestamp: number;
  intentId: string;             // References Intent
  offerId: string;              // Unique ID
  
  // Provider Info
  providerPubkey: string;       // Provider's Solana key
  endpoint: string;             // API endpoint URL
  
  // Pricing
  pricePerRequest: number;      // Actual price offered
  token: SupportedToken;
  tokenMint: string;            // Solana mint address
  
  // Guarantees
  sla: SLA;                     // SLA commitments
  sessionDurationMs: number;    // How long session lasts
  expiresAt: number;            // Offer expiration
  
  // Cryptographic Proof
  signature: string;            // Ed25519 signature
  
  metadata?: Record<string, any>;
}

Signature Verification

Every Offer is cryptographically signed by the provider using Ed25519.

SIGNATURE PROCESS
Provider Side (Creating Offer):
────────────────────────────────
1. Create Offer object (without signature field)
2. Serialize to canonical JSON
3. Hash with SHA-256
4. Sign hash with Ed25519 private key
5. Encode signature as base58
6. Add signature field to Offer
7. Send to agent

Agent Side (Verifying Offer):
──────────────────────────────
1. Receive Offer
2. Extract signature field
3. Remove signature from object
4. Serialize to canonical JSON
5. Hash with SHA-256  
6. Verify signature with provider's public key
7. Check offer hasn't expired
8. Verify price <= maxPricePerRequest
9. Accept or reject
import { verifyOffer } from 'x402pp-core';

// Verify offer is valid and not tampered
try {
  verifyOffer(offer);
  console.log('✓ Offer is valid');
  
  // Check if acceptable
  if (offer.pricePerRequest <= intent.maxPricePerRequest) {
    console.log('✓ Price acceptable');
    // Accept and create session
  }
} catch (error) {
  if (error instanceof OfferExpiredError) {
    console.log('Offer expired, request new one');
  } else if (error instanceof InvalidSignatureError) {
    console.log('Signature invalid, offer tampered!');
  }
}

Dynamic Pricing Example

Custom Pricing Strategy
import { PricingStrategy } from 'x402pp-server';

class CustomPricing implements PricingStrategy {
  async getPrice(intent: Intent): Promise<number> {
    let price = 0.01;  // base
    
    // Adjust for capability
    if (intent.capability === 'gpt-4-inference') {
      price = 0.02;
    }
    
    // Adjust for SLA strictness
    if (intent.sla?.maxLatencyMs && intent.sla.maxLatencyMs < 1000) {
      price *= 1.5;  // 50% premium for <1s response
    }
    
    // Adjust for current load
    const load = await getCurrentLoad();
    price *= (1 + load);
    
    // Adjust for time of day
    const hour = new Date().getHours();
    if (hour >= 9 && hour <= 17) {
      price *= 1.2;  // 20% premium during business hours
    }
    
    return price;
  }
}

// Use in middleware
app.use('/api/*', x402Middleware({
  // ...
  pricing: new CustomPricing()
}));
X (Twitter)