X402 Balance
Get the x402 credit balance for a wallet address. Requires Sign-in-with-x authentication for the same EVM or Solana wallet.
curl --request GET \
--url https://api.venice.ai/api/v1/x402/balance/{walletAddress} \
--header 'SIGN-IN-WITH-X: <api-key>'import requests
url = "https://api.venice.ai/api/v1/x402/balance/{walletAddress}"
headers = {"SIGN-IN-WITH-X": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'SIGN-IN-WITH-X': '<api-key>'}};
fetch('https://api.venice.ai/api/v1/x402/balance/{walletAddress}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.venice.ai/api/v1/x402/balance/{walletAddress}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"SIGN-IN-WITH-X: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.venice.ai/api/v1/x402/balance/{walletAddress}"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("SIGN-IN-WITH-X", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.venice.ai/api/v1/x402/balance/{walletAddress}")
.header("SIGN-IN-WITH-X", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.venice.ai/api/v1/x402/balance/{walletAddress}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["SIGN-IN-WITH-X"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"walletAddress": "0xyour_wallet_address",
"balanceUsd": 12.5,
"canConsume": true,
"minimumTopUpUsd": 5,
"suggestedTopUpUsd": 10
}
}{
"error": "<string>",
"details": {
"_errors": [],
"field": {
"_errors": [
"Field is required"
]
}
}
}{
"error": "This nonce has already been used",
"code": "X402_SIGN_IN_NONCE_REUSED",
"invalidReason": "invalid_siwx_nonce"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}Authorizations
Wallet-based authentication using the x402 sign-in-with-x extension. Supports EVM wallets on Base (EIP-4361 SIWE, including EIP-1271 smart contract wallets) and Ed25519 wallets on Solana mainnet.
Header format: Base64-encoded JSON proof with these fields:
domain—api.venice.aiaddress— EVM or Solana wallet addressuri— URL of the requested resourceversion—"1"chainId—"eip155:8453"for Base or"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"for Solanatype—"eip191"for EVM wallets or"ed25519"for Solananonce— thenoncefrom the latest 402 challenge (extensions["sign-in-with-x"].info.nonce), or 32 random hex characters. Each nonce works once.issuedAt— ISO 8601 time the proof was signed. Proofs older than 5 minutes are rejected.expirationTime,notBefore,statement,resources— optionalsignature— signature over the message built from these fields: an EIP-4361 SIWE message for EVM (hex) or the Solana sign-in message (base58)
Venice rebuilds the signed message from these fields, with the bare reference on its Chain ID line (8453, 5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp). Proofs from older clients that send the signed message itself are still accepted.
Example (TypeScript, viem):
import { privateKeyToAccount } from 'viem/accounts'
import { createSiweMessage } from 'viem/siwe'
const account = privateKeyToAccount(PRIVATE_KEY)
const fields = { domain: 'api.venice.ai', address: account.address, uri: 'https://api.venice.ai/api/v1/chat/completions', version: '1' as const, nonce: crypto.randomUUID().replace(/-/g, ''), issuedAt: new Date().toISOString(), statement: 'Sign in to Venice AI' }
const message = createSiweMessage({ ...fields, chainId: 8453, issuedAt: new Date(fields.issuedAt) })
const signature = await account.signMessage({ message })
const header = btoa(JSON.stringify({ ...fields, chainId: 'eip155:8453', type: 'eip191', signature }))
// Set header: SIGN-IN-WITH-X: <header>
SDK: npm install venice-x402-client provides VeniceClient and createAuthFetch which handle this automatically.
Billing: x402 users pay from a prepaid x402 credit balance. Top up via POST /x402/top-up. When balance is insufficient, endpoints return 402 with structured top-up instructions.
Headers
Path Parameters
Was this page helpful?
curl --request GET \
--url https://api.venice.ai/api/v1/x402/balance/{walletAddress} \
--header 'SIGN-IN-WITH-X: <api-key>'import requests
url = "https://api.venice.ai/api/v1/x402/balance/{walletAddress}"
headers = {"SIGN-IN-WITH-X": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'SIGN-IN-WITH-X': '<api-key>'}};
fetch('https://api.venice.ai/api/v1/x402/balance/{walletAddress}', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.venice.ai/api/v1/x402/balance/{walletAddress}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"SIGN-IN-WITH-X: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.venice.ai/api/v1/x402/balance/{walletAddress}"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("SIGN-IN-WITH-X", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.venice.ai/api/v1/x402/balance/{walletAddress}")
.header("SIGN-IN-WITH-X", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.venice.ai/api/v1/x402/balance/{walletAddress}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["SIGN-IN-WITH-X"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"walletAddress": "0xyour_wallet_address",
"balanceUsd": 12.5,
"canConsume": true,
"minimumTopUpUsd": 5,
"suggestedTopUpUsd": 10
}
}{
"error": "<string>",
"details": {
"_errors": [],
"field": {
"_errors": [
"Field is required"
]
}
}
}{
"error": "This nonce has already been used",
"code": "X402_SIGN_IN_NONCE_REUSED",
"invalidReason": "invalid_siwx_nonce"
}{
"error": "<string>"
}{
"error": "<string>"
}{
"error": "<string>"
}