Wallet Auth
Authenticate with a signed Sign-In-With-X payload in the
X-Sign-In-With-X header.Pay with USDC
Maintain spendable balance with USDC on Base or Solana.
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 so that wallets can authenticate and pay for inference directly with USDC on Base or Solana.Prerequisites
- A wallet on Base or Solana
- Native token for gas on the selected chain, such as ETH on Base or SOL on Solana
- USDC on the selected chain (or existing DIEM-backed balance from a linked Venice account)
Quick start
Thevenice-x402-client SDK provides helpers for wallet 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 Sign-In-With-X message. EVM wallets sign an EIP-4361 SIWE message on Base. Solana wallets sign the Solana SIWX message with Ed25519. Generate a fresh nonce and timestamp for each request flow. For Solana, setchainId to solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp, include type: "ed25519" in the encoded JSON payload, and provide the Ed25519 signature as base58 or base64. The signed message starts with <domain> wants you to sign in with your Solana account:, followed by the wallet address and the standard URI, Version, Chain ID, Nonce, Issued At, and optional Expiration Time fields.
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
walletAddress path parameter accepts either an EVM address (0x...) or a Solana base58 address.
Step 3: Top up
Top up with USDC on Base or Solana:402 Payment Required with a PAYMENT-REQUIRED header containing an accepts array. Each entry describes one accepted payment option, including network, asset, payTo, and amount. Choose the Base or Solana option you want to pay with, use those exact details to build an X-402-Payment header, and retry the same route.
Building the X-402-Payment header for Base
The following script creates a signed x402 payment on Base 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. For Solana top-ups, build the payment from the Solana entry returned in accepts. Solana entries use network: "solana", the USDC mint as asset, and may include network-specific metadata such as extra.feePayer.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.
The walletAddress path parameter accepts either an EVM address (0x...) or a Solana base58 address.
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 using an accepted Base or Solana payment option |
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 for an EVM or Solana wallet address |
GET /api/v1/x402/transactions/{walletAddress} | View transaction history for an EVM or Solana wallet address |
Errors
| Status | Likely cause | What to do |
|---|---|---|
401 | Malformed or expired Sign-In-With-X 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.