> ## 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.

# Autonomous Agent API Key Creation

> Mint a Venice API key from an on-chain agent by staking VVV on Base.

An AI agent that controls a wallet on Base can mint its own Venice inference API key with no human in the loop. The agent acquires VVV, stakes it, requests a short-lived key request for its wallet, signs the request's readable message, and posts the signature back to receive a fresh API key tied to the staking wallet. The same flow can mint an ADMIN key when the wallet signs a message that names the ADMIN key type.

This guide walks through the full flow end to end and covers the funding options for actually paying for inference once the key is minted.

## Prerequisites

* An EVM wallet on Base controlled by the agent (private key in an env var or secret manager).
* A small amount of ETH on Base for gas (staking is two transactions: `approve` then `stake`).
* Any non-zero amount of VVV to stake. The minting endpoint requires only that the wallet has a non-zero sVVV balance, so 1 VVV is enough to mint a key. See [Paying for inference](#paying-for-inference) for what you need to actually call paid endpoints.

> [!TIP]
>
> Use a dedicated agent wallet rather than a treasury wallet. The wallet's private key signs every Venice token request, so its blast radius should be small.

## Steps

**1. Acquire VVV**

Send VVV to the agent's wallet, or have the agent swap on a DEX such as [Aerodrome](https://aerodrome.finance/swap?from=eth\&to=0xacfe6019ed1a7dc6f7b508c02d1b04ec88cc21bf\&chain0=8453\&chain1=8453) or [Uniswap](https://app.uniswap.org/swap?chain=base\&inputCurrency=NATIVE\&outputCurrency=0xacfe6019ed1a7dc6f7b508c02d1b04ec88cc21bf).

VVV token contract on Base: `0xacfE6019Ed1A7Dc6f7B508C02d1b04ec88cC21bf`

**2. Stake VVV with Venice**

Stake the VVV in the [Venice Staking Smart Contract](https://basescan.org/address/0x321b7ff75154472b18edb199033ff4d116f340ff#code) at `0x321b7ff75154472B18EDb199033fF4D116F340Ff`. This is two transactions:

1. `approve(spender, amount)` on the VVV token, where `spender` is the staking contract.
2. `stake(amount)` on the staking contract.

![Smart Contract Staking](https://mintcdn.com/veniceai/IFxWLBK8qRcf4Dhb/images/guides/SC-Stake.png?fit=max\&auto=format\&n=IFxWLBK8qRcf4Dhb\&q=85\&s=6a2180bbdc58f95990e99568d7015bbc)

When the second transaction confirms, the wallet's VVV balance decreases and its sVVV balance increases by the same amount. The minting endpoint reads the sVVV balance to confirm the wallet is staked.

**3. Request a key request for the wallet**

Call `GET /api/v1/api_keys/generate_web3_key` with the staking wallet's address. The endpoint is unauthenticated.

```bash theme={"system"}
curl --request GET \
  --url 'https://api.venice.ai/api/v1/api_keys/generate_web3_key?address=<wallet address>'
```

The optional `apiKeyType` query parameter sets the key type the wallet authorizes: `INFERENCE` (the default) or `ADMIN`. The type is fixed in the token and named in the message, so request the type you will mint. See [Minting an ADMIN key](#minting-an-admin-key).

The response contains two fields:

* `token`, a Venice-signed token bound to that wallet. It expires 15 minutes after issuance, so sign and submit it well before then.
* `message`, the readable text the wallet signs. It names the wallet, the key type (`INFERENCE` unless you requested `ADMIN`), the issuer, the chain, a one-time nonce, and the issue and expiration times:

```text theme={"system"}
Venice API key request

Sign this only if you are creating a Venice inference API key for this wallet. The key spends from this wallet's Venice account.

Wallet: <wallet address>
Key type: INFERENCE
Issued by: api.venice.ai
Chain ID: 8453
Nonce: <random hex>
Issued At: <ISO 8601 time>
Expiration Time: <ISO 8601 time>
```

**4. Sign the message with the staking wallet**

Sign the exact `message` string with the wallet that holds the staked VVV. This is a standard `personal_sign` (EIP-191). Both `ethers.Wallet.signMessage(message)` and `viem`'s `account.signMessage({ message })` produce the correct signature. Do not modify the message: Venice rebuilds it from the token, and the signature must match it exactly.

**5. Mint the API key**

`POST` the address, signature, and token to the same endpoint.

```bash theme={"system"}
curl --request POST \
  --url https://api.venice.ai/api/v1/api_keys/generate_web3_key \
  --header 'Content-Type: application/json' \
  --data '{
    "address": "<wallet address>",
    "signature": "<signature of message>",
    "token": "<token>",
    "apiKeyType": "INFERENCE",
    "description": "Agent key minted on <date>"
  }'
```

Required fields: `address`, `signature`, `token`, `apiKeyType`. `apiKeyType` must match the key type named in the signed message: `INFERENCE` for a token requested without `apiKeyType`, or `ADMIN` for a token requested with `apiKeyType=ADMIN`.

Optional fields:

* `description`, `expiresAt`
* `consumptionLimit` — the spend cap for this key, denominated in `usd` or `diem` (`vcu` is deprecated; use `diem` instead)
* `limitPeriod` — the window the cap is measured over: `EPOCH` (resets every UTC day), `MONTH` (resets on the 1st of each UTC month), or `LIFETIME` (never resets, so the cap is permanent)
* `modelPrivacy` — which models the key may call, by privacy tier: `ALL`, `PRIVATE_TEXT`, or `PRIVATE_ONLY`
* `ipAllowlist` — IPv4 or IPv6 addresses and CIDR subnets allowed to use the key (up to 100 entries); an empty list allows any IP address

> [!WARNING]
>
> `limitPeriod` defaults to `EPOCH` when omitted, which means the cap **resets every day** rather than being a lifetime total. A key created with `consumptionLimit: {"usd": 50}` and no `limitPeriod` can spend \$50 per day. For an unattended agent key, set `limitPeriod: "LIFETIME"` explicitly so the limit is a permanent ceiling.

On success the response contains the minted `apiKey` string. Store it in the agent's secret store and use it as a normal Bearer token (`Authorization: Bearer <key>`).

## End-to-end example

The example below uses a real wallet from an environment variable rather than a randomly generated one. A random wallet has no staked VVV and the mint will be rejected with a `Wallet 0x… has no staked VVV on Base` error.

```typescript theme={"system"}
import { ethers } from "ethers"

const wallet = new ethers.Wallet(process.env.WALLET_PRIVATE_KEY!)
const address = wallet.address

const tokenResponse = await fetch(
  `https://api.venice.ai/api/v1/api_keys/generate_web3_key?address=${address}`,
)
const { data: { token, message } } = await tokenResponse.json()

const signature = await wallet.signMessage(message)

const mintResponse = await fetch("https://api.venice.ai/api/v1/api_keys/generate_web3_key", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    address,
    signature,
    token,
    apiKeyType: "INFERENCE",
    description: "Agent key",
    // A permanent $50 ceiling. Without limitPeriod this would reset daily.
    consumptionLimit: { usd: 50 },
    limitPeriod: "LIFETIME",
  }),
})

const result = await mintResponse.json()
if (!mintResponse.ok) {
  throw new Error(`Mint failed: ${result.error}`)
}

console.log("Minted key:", result.data.apiKey)
```

## Minting an ADMIN key

An ADMIN key can create and delete other API keys and read billing for the wallet's Venice account, and it spends from that account. To mint one, request a token with `apiKeyType=ADMIN`, sign its message, and `POST` with `apiKeyType: "ADMIN"`:

```bash theme={"system"}
curl --request GET \
  --url 'https://api.venice.ai/api/v1/api_keys/generate_web3_key?address=<wallet address>&apiKeyType=ADMIN'
```

The returned `message` states that it creates an ADMIN key and what that key can do:

```text theme={"system"}
Venice API key request

Sign this only if you are creating a Venice ADMIN API key for this wallet. An ADMIN key can create and delete other API keys and read billing for this wallet's Venice account, and it spends from this wallet's Venice account.

Wallet: <wallet address>
Key type: ADMIN
Issued by: api.venice.ai
Chain ID: 8453
Nonce: <random hex>
Issued At: <ISO 8601 time>
Expiration Time: <ISO 8601 time>
```

Sign and submit it as in the steps above, with `"apiKeyType": "ADMIN"` in the `POST` body. A token's key type cannot be changed: an `INFERENCE` token cannot mint an ADMIN key, and an `ADMIN` token cannot mint an INFERENCE key. ADMIN keys require the readable message, so [legacy tokens](#legacy-tokens) cannot mint them.

> [!WARNING]
>
> Have a wallet sign an ADMIN message only when the agent needs to manage keys or read billing. Anyone holding the ADMIN key can create new keys for the account, so store it at least as carefully as the wallet's private key.

## Error reference

The endpoint returns specific, actionable error messages. Map these in the agent so it can decide whether to retry, request a new token, or stop.

| Status | Error message contains | What it means | What to do |
| - | - | - | - |
| `400` | `Invalid wallet address` | The `address` query parameter or field is not a valid EVM address. | Fix the address and resubmit. |
| `400` | `Invalid "apiKeyType"` | The `apiKeyType` query parameter is not `INFERENCE` or `ADMIN`. | Use `INFERENCE` or `ADMIN`. |
| `400` | `ADMIN keys require a readable key request` | The `GET` asked for `apiKeyType=ADMIN` without `?address=`. | Request the token with both `address` and `apiKeyType=ADMIN`. |
| `400` | `This token was issued for an` | The `POST` body's `apiKeyType` differs from the key type named in the signed message. | Send the type the token was issued for, or request a new token with the `apiKeyType` you want. The error names the right `GET`. |
| `400` | `ADMIN keys cannot be created with a token that has no wallet address` | A legacy token (requested without `?address=`) was used with `apiKeyType: "ADMIN"`. | Request a token with `?address=<wallet>&apiKeyType=ADMIN` and sign its `message`. |
| `400` | `issued for a different wallet` | The token was requested for a different `address` than the one in the `POST` body. | Request a token with `?address=` set to the wallet that signs. |
| `400` | `JWT has expired` | The validation token expired before you signed and submitted it. | Request a new token, sign it, and submit immediately. |
| `400` | `JWT signature is invalid` | The token was not signed by Venice (likely tampered with or fabricated). | Always use a fresh token from the `GET` endpoint. |
| `400` | `JWT claims are invalid` | The token's issuer or audience does not match what Venice expects. | Use the unmodified token returned by the `GET` endpoint. |
| `400` | `JWT is malformed` | The submitted `token` is not a JWT. | Ensure you are sending the exact `token` string returned by the `GET` endpoint. |
| `400` | `Wallet signature does not match` | The `signature` is not the `address` wallet's signature of the token's `message`. | Sign the exact `message` returned with the token, using the wallet that owns `address`. |
| `400` | `Tokens without a wallet address are no longer accepted` | The token was requested without `?address=`. These legacy tokens stop working on December 26, 2026. | Request a token with `?address=` and sign its `message`. |
| `400` | `Could not verify wallet signature` | RPC call to verify the signature failed (transient). | Retry with backoff. |
| `400` | `has no staked VVV` | The wallet has zero sVVV balance. The full message is `Wallet 0x… has no staked VVV on Base` with your wallet address in place of `0x…`, followed by a link, so match on `has no staked VVV` rather than the full text. | Stake VVV first, then retry. |

## Legacy tokens

Before November 2026 the endpoint issued tokens without a wallet address, and the wallet signed the raw token string. Those tokens still mint INFERENCE keys until **December 26, 2026 00:00 UTC**, and responses for them carry `Deprecation`, `Sunset`, and `Link` headers. After that date, `POST` rejects them. Switch to `?address=` and sign `message` before then.

## Paying for inference

Minting a key and being able to call paid endpoints with it are two separate things. A freshly minted key authenticates correctly but cannot call paid endpoints (such as `/chat/completions`) until the wallet's account has a spendable balance.

The minted key can spend from the user account in this priority order: DIEM, then earned credits, then bundled credits, then USD.

| Funding source | Autonomous? | How |
| - | - | - |
| **DIEM from VVV staking** | Yes | The wallet's daily DIEM allocation is proportional to its share of the staking pool. The account needs at least 0.1 staked DIEM for any DIEM to be spendable. Larger stakes earn proportionally more daily DIEM, refreshed each epoch (00:00 UTC). |
| **USD via Stripe** | No (browser) | Sign into venice.ai with the same wallet (Sign-In-With-Ethereum). The dashboard finds the existing user record. Add credits in Settings, API. |
| **Coinbase crypto subscription** | No (browser) | Same wallet sign-in, then subscribe through the dashboard. The flow redirects to Coinbase Commerce for the actual payment, so it cannot be driven from a script. |
| **Coinbase onramp** | No (browser) | Same wallet sign-in, then use the onramp widget in the dashboard. Hosted on Coinbase's UI. |

If the agent needs a fully crypto-native, headless funding path, the cleanest options are:

1. **Stake more VVV** so the daily DIEM allocation covers the agent's spend. The minted key picks this up automatically.
2. **Use the [x402 wallet flow](https://docs.venice.ai/guides/integrations/x402-venice-api.md) instead of the API key.** With x402 the agent signs a Sign-In-With-X message per request, tops up directly with USDC on Base or Solana via `POST /api/v1/x402/top-up`, and pays per request. The x402 USDC balance is wallet-bound, not user-bound, so it does not show up as balance for the minted Bearer key, but it does let the same wallet pay for inference programmatically.

## Related resources

> [card] [Crypto and Agents](https://docs.venice.ai/guides/integrations/crypto-rpc-agents.md)
>
> Use Venice as both the model provider and the blockchain RPC layer for autonomous agents.

> [card] [x402 Wallet Authentication](https://docs.venice.ai/guides/integrations/x402-venice-api.md)
>
> Pay per request with USDC on Base or Solana, no API key required.

> [card] [Generate Web3 API Key Endpoint](https://docs.venice.ai/api-reference/endpoint/api_keys/generate_web3_key/post.md)
>
> Endpoint reference for the mint endpoint.

> [card] [Standard API Key Guide](https://docs.venice.ai/guides/getting-started/generating-api-key.md)
>
> For users who prefer to mint a key from the dashboard.


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