Preimage Research SDK Documentation
Payment infrastructure for machine-to-machine commerce. Build APIs that accept USDC payments over HTTP using the x402 protocol.
6 Production SDKs
TypeScript, Express, FastAPI, Django, Gin, and Axum - all production-ready
Stateless Design
Proxy-to-gateway pattern means no database required for payment logic
Verifiable Receipts
JWS-signed receipts for every transaction, finance-ready proof of payment
USDC Payments
Native USDC support on Base, Ethereum, and Polygon (L1 + L2)
Non-Custodial
You control your wallet, payments go directly to your address
Mock Mode
Test locally without real blockchain transactions or Gateway access
Quick Start
Get started in under 5 minutes. Choose your role:
For API Consumers (Client SDK)
Install the TypeScript client and start making payments to protected APIs:
npm install @preimage/clientimport { createClient } from '@preimage/client';
const client = createClient({
gatewayUrl: 'https://api.preimage-research.ai',
walletPrivateKey: process.env.WALLET_PRIVATE_KEY,
network: 'base-sepolia',
});
// Automatic 402 payment handling
const response = await client.request('/v1/weather?city=SF');
console.log(response.data);For API Providers
Protect your API endpoints with x402 payments in one line of code:
import { createX402Middleware } from '@preimage/express';
app.use('/api', createX402Middleware({
gatewayUrl: 'https://gateway.preimage.io',
providerId: 'your-provider-id',
pricing: { usdcPerUnit: 0.001 }
}));Get started with Provider SDKs →
How It Works
Preimage Research implements the x402 protocol for HTTP payments:
- Client makes request → API returns
402 Payment Requiredwith payment challenge - Client signs USDC payment → Using EIP-3009
transferWithAuthorization - Client retries with proof → Includes signed payment in
Authorizationheader - Gateway verifies → Confirms payment on-chain, returns success + receipt
- API responds → Returns data with cryptographically signed receipt
All provider SDKs use a stateless proxy-to-gateway pattern. This means your API doesn't need a database - all payment logic is handled by the Preimage Research Gateway.
Architecture
┌─────────────┐
│ Client │
│ (@preimage/│
│ client) │
└──────┬──────┘
│ 1. GET /api/data
↓
┌──────────────────────────────────────┐
│ Your API Server │
│ ┌────────────────────────────────┐ │
│ │ Provider SDK Middleware │ │
│ │ (Express/FastAPI/Django/etc) │ │
│ └────────┬───────────────────────┘ │
└───────────┼──────────────────────────┘
│ 2. Forward to Gateway
↓
┌──────────────────────────────────────┐
│ Preimage Research Gateway │
│ - Generate challenge (402) │
│ - Verify USDC payment │
│ - Sign receipts │
└──────────────────────────────────────┘Why Preimage Research?
Transparent Tiered Pricing
Preimage uses 4-tier dynamic pricing - 50-95% cheaper than Stripe/PayPal:
| Payment Amount | Platform Fee | You Keep | vs Stripe |
|---|---|---|---|
| $0.10 (micro) | 5% | 95% | Can't process! |
| $1.00 | 8% | 92% | 76% cheaper |
| $5.00 | 4% | 96% | 55% cheaper |
| $50.00 | 2.6% | 97% | 26% cheaper |
Tier Breakdown:
- Ultra-Micro ($0.005-$0.009): 10% only
- Micropayments ($0.01-$0.99): 5% only
- Standard ($1-$9.99): 3% + $0.05
- Large ($10+): 2.5% + $0.05
Every payment is split automatically in one atomic transaction. View full pricing →
Non-Custodial
You control your wallet. Payments go directly to your address. Preimage Research never holds your funds.
Verifiable Receipts
Every transaction includes a JWS-signed receipt with:
- Payment ID
- Amount paid (provider + platform split)
- Timestamp
- Cryptographic signature
Perfect for accounting, auditing, and compliance.
Supported Networks
| Network | Chain ID | USDC Contract |
|---|---|---|
| Base | 8453 | 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 |
| Base Sepolia | 84532 | 0x036CbD53842c5426634e7929541eC2318f3dCF7e |
| Ethereum | 1 | 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 |
| Ethereum Sepolia | 11155111 | 0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238 |
| Polygon | 137 | 0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359 |
| Polygon Amoy | 80002 | 0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582 |
For production, use mainnet networks (Base, Ethereum, Polygon). For development and testing, use testnet networks (Base Sepolia, Ethereum Sepolia, Polygon Amoy).
Next Steps
Learn the Basics
Understand how x402 payments work and the Preimage Research architecture
Build Your First Integration
Follow our quickstart guide to integrate Preimage Research in 10 minutes