> ## Documentation Index
> Fetch the complete documentation index at: https://docs.venice.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> The Venice API is OpenAI-compatible: use any OpenAI SDK with the base URL `https://api.venice.ai/api/v1` and a Venice API key, or pay per request from a USDC wallet through x402 with no account.
> Read model IDs from `GET /models` or `GET /models/traits` at runtime instead of hardcoding them from memory or from these pages. Models are added and retired often.
> Every model's price is in https://docs.venice.ai/pricing.md. Quote video and audio jobs with `POST /video/quote` or `POST /audio/quote` before you queue them.
> Search these docs from an MCP client at https://docs.venice.ai/mcp. The full agent guide is https://docs.venice.ai/agents.md.

# X402

> Access the Venice API with no key by paying per request with x402 and a crypto wallet.

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.

> [card] Wallet Auth
>
> Authenticate with a signed Sign-In-With-X payload in the `SIGN-IN-WITH-X` header.

> [card] Pay with USDC
>
> Maintain spendable balance with USDC on Base or Solana.

## What is X402?

[X402](https://www.x402.org/) 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

> [!TIP]
>
> Consider using a dedicated wallet for automation rather than your main treasury wallet.

## Quick start

The [`venice-x402-client`](https://github.com/veniceai/x402-client) SDK provides helpers for wallet auth, top-ups, and balance tracking.

```bash theme={"system"}
npm install venice-x402-client
```

```typescript theme={"system"}
import { VeniceClient } from 'venice-x402-client'

const venice = new VeniceClient(process.env.WALLET_KEY)

await venice.topUp(10) // skip if the wallet already has spendable balance

const response = await venice.chat({
  model: 'kimi-k2-6',
  messages: [{ role: 'user', content: 'Hello!' }]
})
```

The client generates a fresh 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:

```typescript theme={"system"}
import { createAuthFetch } from 'venice-x402-client'

const authFetch = createAuthFetch(process.env.WALLET_KEY)
```

### Available helpers

The SDK includes first-class helpers for the most common Venice x402 routes. For anything not covered, use `request()` 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()` |
| 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, top up first.

### Step 1: Create the SIGN-IN-WITH-X header

Venice expects an x402 sign-in-with-x proof in the `SIGN-IN-WITH-X` header: Base64-encoded JSON with the fields of the signed message (`domain`, `address`, `uri`, `version`, `chainId`, `type`, `nonce`, `issuedAt`, and the optional `expirationTime`, `notBefore`, `statement`, and `resources`) plus the `signature`. Venice rebuilds the signed message from those fields. EVM wallets sign an EIP-4361 SIWE message on Base and set `type` to `eip191`, including smart contract wallets. Solana wallets sign the Solana sign-in message with Ed25519. In the JSON, `chainId` is the CAIP-2 identifier (`eip155:8453`), while the `Chain ID` line of the signed message carries the bare reference (`8453`). The legacy `X-Sign-In-With-X` header name is still accepted, as are older payloads that send the signed `message` itself.

Each signed message can be used only once. Sign a new message with a fresh nonce for every request, either your own or the `nonce` from the latest `402` challenge, and send it within 5 minutes of its `issuedAt` time. Reusing a message returns `401` (nonce already used), as does a message issued more than 5 minutes ago.

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.

```typescript theme={"system"}
import { Wallet } from 'ethers'
import { SiweMessage, generateNonce } from 'siwe'

const wallet = new Wallet(process.env.EVM_PRIVATE_KEY)

async function createSiwxHeader(resourceUrl: string): Promise<string> {
  const now = new Date()
  const fields = {
    domain: 'api.venice.ai',
    address: wallet.address,
    statement: 'Sign in to Venice AI',
    uri: resourceUrl,
    version: '1',
    nonce: generateNonce(),
    issuedAt: now.toISOString(),
    expirationTime: new Date(now.getTime() + 5 * 60 * 1000).toISOString(),
  }

  const message = new SiweMessage({ ...fields, chainId: 8453 }).prepareMessage()
  const signature = await wallet.signMessage(message)

  return Buffer.from(JSON.stringify({ ...fields, chainId: 'eip155:8453', type: 'eip191', signature }), 'utf8').toString('base64')
}

const response = await fetch('https://api.venice.ai/api/v1/chat/completions', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'SIGN-IN-WITH-X': await createSiwxHeader('https://api.venice.ai/api/v1/chat/completions'),
  },
  body: JSON.stringify({
    model: 'kimi-k2-6',
    messages: [{ role: 'user', content: 'Hello!' }],
  }),
})
```

Call `createSiwxHeader()` immediately before every request. In the `curl` examples below, `X402_AUTH` must be a newly signed header for each call.

### Step 2: Check balance

Before making a paid request, verify the wallet has spendable balance:

```bash theme={"system"}
export WALLET_ADDRESS=0xYOUR_WALLET_ADDRESS_OR_SOLANA_ADDRESS
export X402_AUTH=YOUR_BASE64_SIWX_HEADER

curl --request GET \
  --url "https://api.venice.ai/api/v1/x402/balance/$WALLET_ADDRESS" \
  --header "SIGN-IN-WITH-X: $X402_AUTH"
```

The response includes:

* `canConsume`: whether the wallet can make paid requests
* `balanceUsd`: current spendable balance
* `minimumTopUpUsd` and `suggestedTopUpUsd`: guidance for top-ups

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:

```bash theme={"system"}
curl --request POST \
  --url https://api.venice.ai/api/v1/x402/top-up
```

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 a `PAYMENT-SIGNATURE` header, and retry the same route. The legacy `X-402-Payment` and `X-PAYMENT` header names are still accepted.

> [!WARNING]
>
> Sending USDC straight to a `payTo` address does not top up your balance. Credit is only added when a signed `PAYMENT-SIGNATURE` settles through `POST /x402/top-up`. Only Base and Solana are supported, so USDC sent on any other chain, including Ethereum mainnet, is not credited. The balance and transactions routes read the Venice ledger rather than the chain, so after a plain transfer they show nothing.

#### Building the PAYMENT-SIGNATURE 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.

```bash theme={"system"}
export EVM_PRIVATE_KEY=0xYOUR_PRIVATE_KEY
```

```bash theme={"system"}
export X402_PAYMENT="$(
node --input-type=module <<'EOF'
import { createPaymentHeader } from "x402/client";
import { privateKeyToAccount } from "viem/accounts";

const signer = privateKeyToAccount(process.env.EVM_PRIVATE_KEY);
const amountUsd = 5;
const amountBaseUnits = String(Math.round(amountUsd * 1e6));

const header = await createPaymentHeader(signer, 2, {
  scheme: "exact",
  network: "base",
  maxAmountRequired: amountBaseUnits,
  resource: "https://api.venice.ai/api/v1/x402/top-up",
  description: "Venice x402 top-up",
  mimeType: "application/json",
  payTo: "0x2670B922ef37C7Df47158725C0CC407b5382293F",
  maxTimeoutSeconds: 300,
  asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  extra: { name: "USD Coin", version: "2" },
});

process.stdout.write(header);
EOF
)"

curl -X POST "https://api.venice.ai/api/v1/x402/top-up" \
  -H "PAYMENT-SIGNATURE: $X402_PAYMENT"
```

> [!NOTE]
>
> 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 a newly signed `SIGN-IN-WITH-X` header:

```bash theme={"system"}
export X402_AUTH=YOUR_BASE64_SIWX_HEADER

curl --request POST \
  --url https://api.venice.ai/api/v1/chat/completions \
  --header "Content-Type: application/json" \
  --header "SIGN-IN-WITH-X: $X402_AUTH" \
  --data '{
    "model": "kimi-k2-6",
    "messages": [
      {
        "role": "user",
        "content": "Hello from an x402-authenticated wallet."
      }
    ]
  }'
```

Successful responses may include an `X-Balance-Remaining` header.

### Step 5: Inspect transactions (optional)

Review the wallet's transaction history:

```bash theme={"system"}
export WALLET_ADDRESS=0xYOUR_WALLET_ADDRESS_OR_SOLANA_ADDRESS
export X402_AUTH=YOUR_BASE64_SIWX_HEADER

curl --request GET \
  --url "https://api.venice.ai/api/v1/x402/transactions/$WALLET_ADDRESS?limit=10&offset=0" \
  --header "SIGN-IN-WITH-X: $X402_AUTH"
```

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

### 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/voices`, `POST /api/v1/audio/complete`, `POST /api/v1/audio/queue`, `POST /api/v1/audio/retrieve` |
| Decisions | `POST /api/v1/decisions`, `POST /api/v1/systemone` |
| Tools | `POST /api/v1/augment/search`, `POST /api/v1/augment/scrape`, `POST /api/v1/augment/text-parser` |
| Blockchain RPC | `POST /api/v1/crypto/rpc/{network}` |

### Routes without x402 support

Video and voice changer don't currently support x402, so the routes below need an API key. A request that sends only a `SIGN-IN-WITH-X` header returns `401` with `"error": "Authentication failed"`.

| Category | Endpoints |
| - | - |
| Video | `POST /api/v1/video/queue`, `POST /api/v1/video/retrieve`, `POST /api/v1/video/complete` |
| Voice changer | `POST /api/v1/audio/voice-changer/queue`, `POST /api/v1/audio/voice-changer/retrieve`, `POST /api/v1/audio/voice-changer/complete` |

### Top-up route

| Endpoint | Auth | Purpose |
| - | - | - |
| `POST /api/v1/x402/top-up` | Initial request: none. Retry: `PAYMENT-SIGNATURE` | Add USDC credits to the wallet's spendable balance using an accepted Base or Solana payment option |

### Wallet-only routes

These routes use `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, expired, or already used Sign-In-With-X payload. The response body's `code` (`X402_SIGN_IN_*`) names the failed check, and `invalidReason` gives the matching `invalid_siwx_*` spec code when there is one. | Sign a new `SIGN-IN-WITH-X` message with a fresh nonce for this request |
| `401` with `X402_USER_NOT_ALLOWED` | The Venice account of the signed-in wallet is banned or deleted. Balance and transaction routes return `{ "code": "X402_USER_NOT_ALLOWED", "error": "Wallet user is not allowed to authenticate" }` and do not read the wallet's credits. | Use a wallet that is allowed to authenticate |
| `402` with `"error": "Authentication required"` | No `SIGN-IN-WITH-X` header or API key was sent | Add the Sign-In-With-X header. The response's `extensions` field contains a fresh nonce to sign. |
| `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 `PAYMENT-SIGNATURE` 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, sign a new Sign-In-With-X message for every request, and check balance before requests to avoid unnecessary `402` round-trips.

***

## Related resources

> [card] [x402 Client SDK](https://github.com/veniceai/x402-client)
>
> Official Venice x402 client for Node.js/TypeScript.

> [card] [Model prices](https://docs.venice.ai/models/overview.md)
>
> Check what each model costs.

> [card] [Chat Completions](https://docs.venice.ai/api-reference/endpoint/chat/completions.md)
>
> A common paid route for wallet-based access.

> [card] [API Spec](https://docs.venice.ai/api-reference/api-spec.md)
>
> Reference documentation and raw spec access.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.