Skip to main content
X402 lets you use Venice’s paid API routes by authenticating with a wallet and maintaining a prepaid USDC balance. No API key or account required. Sign a message, top up on Base or Solana, and call any supported route.

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)
Consider using a dedicated wallet for automation rather than your main treasury wallet.

Quick start

The venice-x402-client SDK provides helpers for wallet auth, top-ups, and balance tracking.
The client generates a fresh 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 custom fetch, 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, use request() or createAuthFetch() directly.

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, set chainId 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:
The response includes:
  • canConsume: whether the wallet can make paid requests
  • balanceUsd: current spendable balance
  • minimumTopUpUsd and suggestedTopUpUsd: guidance for top-ups
  • diemBalanceUsd: DIEM-backed balance, if any
The 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:
The first call returns 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 the x402 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 the X-Sign-In-With-X header:
Successful responses may include an X-Balance-Remaining header.

Step 5: Inspect transactions (optional)

Review the wallet’s transaction history:
The ledger includes entries such as TOP_UP, CHARGE, and REFUND. The walletAddress path parameter accepts either an EVM address (0x...) or a Solana base58 address.

Supported routes

The following public paid Venice routes currently support x402 wallet authentication.

Top-up route

Wallet-only routes

These routes use X-Sign-In-With-X for identity but do not charge balance.

Errors


For agents

The flow is the same. Store private keys in environment variables or a secret manager, and check balance before requests to avoid unnecessary 402 round-trips.

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.