Wallet Auth
Authenticate with a signed SIWE payload in the
X-Sign-In-With-X header.Pay with USDC
Maintain spendable balance with USDC on Base.
DIEM First
If the wallet is linked to a Venice account with DIEM balance, that is spent first.
What is X402?
X402 is an open payment standard that lets applications and agents pay for services programmatically using cryptocurrency. Venice implements X402 on Base so that wallets can authenticate and pay for inference directly.Prerequisites
- An EVM wallet on Base
- A small amount of ETH on Base for gas
- USDC on Base (or existing DIEM-backed balance from a linked Venice account)
Quick start
Thevenice-x402-client SDK provides helpers for SIWE auth, top-ups, and balance tracking.
X-Sign-In-With-X header for each request and automatically tracks balance from X-Balance-Remaining response headers.
With OpenAI-compatible tools
If you’re using a tool that accepts a customfetch, use createAuthFetch to add wallet auth to any request:
Available helpers
The SDK includes first-class helpers for the most common Venice x402 routes. For anything not covered, userequest() or createAuthFetch() directly.
| Category | Methods |
|---|---|
| Chat | chat(), chatStream() |
| Responses | responses.create(), responses.stream() |
| Images | images.generate(), images.generations(), images.upscale(), images.edit(), images.multiEdit(), images.backgroundRemove() |
| Audio | audio.speech(), audio.transcribe(), audio.queue(), audio.retrieve(), audio.complete() |
| Video | video.queue(), video.retrieve(), video.generate(), video.complete(), video.transcribe() |
| Embeddings | embeddings() |
| Models | models() |
| Wallet | getBalance(), getTransactions(), topUp() |
Manual flow
If you’re not using the SDK or need to understand the underlying protocol, here’s the step-by-step flow. For a new wallet, assume you need to top up first unless it already has spendable DIEM balance.Step 1: Create the X-Sign-In-With-X header
Venice expects a Base64-encoded JSON payload containing a signed SIWE message. Generate a fresh nonce and timestamp for each request flow.Step 2: Check balance
Before making a paid request, verify the wallet has spendable balance:canConsume: whether the wallet can make paid requestsbalanceUsd: current spendable balanceminimumTopUpUsdandsuggestedTopUpUsd: guidance for top-upsdiemBalanceUsd: DIEM-backed balance, if any
Step 3: Top up
Top up with USDC on Base:402 Payment Required with a PAYMENT-REQUIRED header containing an accepts array. Use those payment details to build an X-402-Payment header and retry the same route.
Building the X-402-Payment header
The following script creates a signed x402 payment and sends the top-up request. Requires thex402 and viem npm packages.
Use the latest
PAYMENT-REQUIRED / accepts response as the source of truth in production instead of hardcoding these values.Step 4: Make a request
Once the wallet has spendable balance, call any supported endpoint with theX-Sign-In-With-X header:
X-Balance-Remaining header.
Step 5: Inspect transactions (optional)
Review the wallet’s transaction history:TOP_UP, CHARGE, and REFUND.
Supported routes
Paid inference routes
The following public paid Venice routes currently support x402 wallet authentication.| Category | Endpoints |
|---|---|
| Chat | POST /api/v1/chat/completions, POST /api/v1/responses |
| Image | POST /api/v1/image/generate, POST /api/v1/images/generations, POST /api/v1/image/upscale, POST /api/v1/image/edit, POST /api/v1/image/multi-edit, POST /api/v1/image/background-remove |
| Embeddings | POST /api/v1/embeddings |
| Audio | POST /api/v1/audio/speech, POST /api/v1/audio/transcriptions, POST /api/v1/audio/complete, POST /api/v1/audio/queue, POST /api/v1/audio/retrieve |
| Video | POST /api/v1/video/complete, POST /api/v1/video/queue, POST /api/v1/video/retrieve, POST /api/v1/video/transcriptions |
Top-up route
| Endpoint | Auth | Purpose |
|---|---|---|
POST /api/v1/x402/top-up | Initial request: none. Retry: X-402-Payment | Add USDC credits to the wallet’s spendable balance |
Wallet-only routes
These routes useX-Sign-In-With-X for identity but do not charge balance.
| Endpoint | Purpose |
|---|---|
GET /api/v1/x402/balance/{walletAddress} | Check spendable balance |
GET /api/v1/x402/transactions/{walletAddress} | View transaction history |
Errors
| Status | Likely cause | What to do |
|---|---|---|
401 | Malformed or expired SIWE payload | Rebuild X-Sign-In-With-X with a fresh nonce and timestamp |
402 on a paid route | Not enough spendable balance | Top up and retry |
402 on /x402/top-up | Expected. This is the payment initiation flow. | Use the returned payment details to build X-402-Payment and retry |
403 on balance or transactions | Wallet mismatch | Ensure the authenticated wallet matches the walletAddress path parameter |
400 on top-up | Malformed payment header | Rebuild from the latest 402 response |
For agents
The flow is the same. Store private keys in environment variables or a secret manager, and check balance before requests to avoid unnecessary402 round-trips.
Related resources
x402 Client SDK
Official Venice x402 client for Node.js/TypeScript.
API Pricing
Check model pricing and how Venice charges usage.
Chat Completions
A common paid route for wallet-based access.
API Spec
Reference documentation and raw spec access.