HTTP 402 Integration Guide
Complete reference for integrating Vlexivo's micropayment protocol into web applications, APIs, and browser extensions. Publisher SDK, API endpoints, payment flows, and error handling.
Overview
Vlexivo implements HTTP 402 Payment Required as a production micropayment protocol. Publishers embed the SDK in their server or frontend, set prices per resource, and receive cryptographically verified access tokens after on-chain payment — without holding funds or requiring user accounts.
https://vlexivo.online. The protocol uses X-Api-Key header authentication for publisher endpoints and X-Agent-Key for machine-to-machine agent billing.
Publisher SDK Integration
The Vlexivo SDK works in two modes: server-side middleware (Express.js/Node.js) and browser SDK (vanilla JS). Both intercept 402 responses automatically.
3-Step Setup
Install the SDK
Add the Vlexivo package to your Node.js project. The SDK works with Express.js or any Node HTTP server.
Configure with your API key
Register at vlexivo.online/onboard to get your publisher API key. Then configure the SDK with your key and price per resource.
Protect your endpoints
Wrap any Express route with the Vlexivo middleware. When an unprotected request arrives, Vlexivo returns HTTP 402 with the challenge. The browser SDK handles payment and retry automatically.
Express Middleware Options
| Option | Type | Default | Description |
|---|---|---|---|
scopeType | string | 'per-call' | Billing model: per-call, per-article, per-session, tip |
price | object | required | { amount: string, currency: string } |
autoRegister | boolean | false | Automatically create pricing rule if not found |
resourceId | string | route path | Override the resource identifier |
entitlementHeader | string | 'X-Entitlement' | Header to check for existing entitlement tokens |
onPaymentRequired | function | — | Custom callback when 402 is returned |
Browser SDK
For client-side payment handling, embed the Vlexivo browser SDK. It intercepts fetch requests, detects 402 responses, handles wallet connection, and retries automatically.
API Reference
Core Endpoints
| Method | Path | Description |
|---|---|---|
| POST | /v1/challenge | Generate a payment challenge. Publisher API key auth. |
| POST | /v1/unlock | Submit payment proof, receive JWT entitlement. No auth required. |
| POST | /v1/agent/pay | Machine-to-machine payment. Agent API key auth. |
| GET | /v1/agent/status | Agent key health check. |
| POST | /api/entitlements/validate | Server-side entitlement token validation. |
| GET | /api/pricing | List publisher pricing rules. |
| POST | /api/pricing | Create pricing rule. |
| GET | /health | Health check. No auth. |
POST /v1/challenge
Generates a payment challenge. Returns a Challenge402 object that the SDK wraps in an HTTP 402 response.
POST /v1/unlock
Consumer or agent submits blockchain proof of payment. Server verifies on-chain transaction, issues JWT entitlement.
JWT Entitlement Token Structure
HTTP Status Codes
Browser Extension Architecture
The Vlexivo browser extension (Manifest V3) provides automatic 402 interception for any website without requiring publisher SDK installation. It works by wrapping window.fetch and XHR in content scripts.
Components
Extension Interception Flow
Payment Flow Sequence
Complete end-to-end payment flow from publisher middleware through on-chain verification to entitlement delivery.
Retry Logic
The browser SDK implements automatic retry with backoff. If the initial unlock fails due to network or chain latency, it retries before presenting an error to the user.
confirmed commitment for transaction verification. This means the server waits ~2–4 seconds after broadcast before accepting the payment proof. Plan for this latency in UX design.Error Handling
Vlexivo returns structured error responses with machine-readable codes. All error bodies follow the same shape:
Challenge Errors
INVALID_API_KEY (401)
API key not found or malformed. Check your X-Api-Key header format: vlx_live_<64-hex>
PRICING_RULE_NOT_FOUND (404)
No matching pricing rule for this resource. Either create a pricing rule in the dashboard or pass auto_register: true with a price.
RATE_LIMITED (429)
Too many challenge requests. Limit: 100/min per IP. Back off and retry after the Retry-After header duration.
VALIDATION_ERROR (422)
Malformed request body. Check that resource_id is a non-empty string and price.amount is a decimal > 0.
Unlock Errors
NONCE_NOT_FOUND (404)
Nonce doesn't exist in the server's nonce store. Either the challenge was never created or the nonce was already consumed. Retry from the challenge step.
NONCE_ALREADY_USED (409)
Nonce has already been consumed. Payment proof was already submitted for this challenge. This is a replay attack — the original transaction was valid.
NONCE_EXPIRED (410)
Challenge TTL exceeded (15 minutes). Generate a new challenge and retry payment.
UNDERPAYMENT (402)
On-chain amount is less than the required price. The buyer sent funds but the amount is insufficient. Full amount must be sent.
TX_NOT_FOUND (404)
Transaction hash not found on-chain. The transaction may not have propagated yet — retry after a few seconds.
TX_FAILED (402)
On-chain transaction failed (meta.err is non-null). Check the blockchain explorer for the specific failure reason.
WRONG_RECIPIENT (402)
Transaction did not transfer funds to the publisher's wallet address. Payment was sent to the wrong address.
NO_CURRENCY_MATCH (402)
No on-chain transfer detected to the publisher's wallet in the specified currency (USDC, USDT, SOL). Check the currency and retry.
Edge Cases
Concurrent Unlock Requests
Two requests arriving simultaneously with the same nonce. Server uses SELECT FOR UPDATE for atomic nonce consumption. First request succeeds (200), second gets 409 Nonce Already Used.
Zero-Confirmation Transactions
Vlexivo requires at least 1 slot confirmation before accepting payment proof. Uncommitted transactions are rejected. No workaround — wait for confirmation.
Wallet Disconnection Mid-Flow
If the user disconnects their wallet during the payment modal, the SDK shows a "wallet disconnected" error and offers a "retry" button that re-triggers the payment flow.
Token Expiry During Read
If an entitlement token expires while the user is reading content (per-call tokens expire in 5 minutes), the next request returns 402 again. The SDK auto-retries — the user sees a brief "re-authenticating" moment.
Publisher Key Rotation
When a publisher rotates their API key, existing SDK instances receive 401 errors. The SDK detects this, alerts the publisher via console.error, and halts automatic retry. The publisher must update their key.
Solana RPC Outage
If the configured Solana RPC endpoint is unreachable or returns errors, verification falls back to a secondary RPC if configured. If no fallback exists, unlock returns 502 Bad Gateway with BLOCKCHAIN_VERIFICATION_ERROR.
VLEXIVO_BASE_URL to your test environment and use test API keys. In demo mode, the SDK uses StubVerifier — any well-formed proof is accepted without blockchain verification.
Vlexivo HTTP 402 Technical Specification · v1.0 · 2026-05-22
Questions? legal@vlexivo.online · Full Whitepaper · Pitch Deck