Skip to main content

venice_ai.resources.api_keys

Venice AI API Keys Resource Module.

This module provides comprehensive API key management functionality for the Venice AI platform. API keys serve as the primary authentication mechanism for accessing Venice AI services and are essential for controlling access to various endpoints, managing usage quotas, and enforcing rate limits across different model types and services.

The module supports both traditional API key creation and Web3-based authentication workflows, allowing users to manage their credentials through either conventional means or blockchain-based identity verification.

Main Features: - Create, list, retrieve, and delete API keys - Manage rate limits and usage monitoring - Web3 authentication and key generation - Usage analytics and billing integration

Classes: ApiKeys: Asynchronous resource client for comprehensive API key management operations

ApiKeys Objects

class ApiKeys(APIResource["VeniceClient"])

Asynchronous resource for comprehensive API key management operations.

This class provides a complete interface for managing Venice AI API keys, including creation, deletion, retrieval, and monitoring capabilities. It supports both standard API key workflows and Web3-based authentication mechanisms.

All operations are asynchronous and return awaitable coroutines. The class automatically handles request formatting, response parsing, and error handling for all API key operations.

Key Features:

  • Create and manage API keys with custom configurations
  • List and retrieve existing keys with pagination support
  • Delete keys with proper cleanup
  • Monitor rate limits and usage patterns
  • Web3 authentication and blockchain-based key generation
  • Real-time usage analytics and billing integration

Arguments:

  • _client - The VeniceClient instance for making API requests.

Example:

Basic API key management:

.. code-block:: python

import asyncio from venice_ai import VeniceClient from venice_ai.types.api import CreateApiKeyRequest

async def manage_api_keys(): async with VeniceClient() as client:

List existing keys

keys = await client.api_keys.list(limit=10)

Create a new key

request = CreateApiKeyRequest( description="Production API Key", apiKeyType="INFERENCE" ) new_key = await client.api_keys.create(api_key_request=request)

Monitor usage

rate_limits = await client.api_keys.get_rate_limits()

asyncio.run(manage_api_keys())

ApiKeys.list

async def list(*,
page: int | None = None,
limit: int | None = None) -> list[ApiKey]

Retrieve a paginated list of API keys for the authenticated account.

Returns metadata for all API keys associated with the current account, including both active and inactive keys. The actual secret key values are excluded from responses for security purposes.

Arguments:

  • page - Page number for pagination (1-based). Defaults to first page.
  • limit - Maximum number of keys per page. Uses server default if not specified.

Returns:

List of API key objects containing metadata including ID, description, creation timestamp, expiration, and usage statistics.

Raises:

  • AuthenticationError - If the API key is invalid or expired.
  • APIError - If the request fails or returns an error response.
  • APIConnectionError - If unable to connect to the API.

Example:

.. code-block:: python

List all keys

keys = await client.api_keys.list()

Paginated listing

page_keys = await client.api_keys.list(page=1, limit=10) for key in page_keys:

  • print(f"Key - {key.id} - {key.description}")

ApiKeys.iter_all

def iter_all(*,
page_size: int = DEFAULT_PAGE_SIZE,
max_items: int | None = None) -> Paginator[ApiKey]

Lazily iterate every API key, paging through the server as needed.

Wraps :meth:list for unbounded enumeration. Termination: there's no pagination envelope on this endpoint, so the iterator stops on the first short page (len(items) < page_size).

Arguments:

  • page_size: Server page size (default 100).
  • max_items: Optional cap on total items yielded. Example:
async for key in client.api_keys.iter_all():
print(key.id, key.description)

ApiKeys.create

async def create(*, api_key_request: CreateApiKeyRequest) -> CreatedApiKey

Create a new API key with the specified configuration.

Generates a new API key based on the provided parameters. The secret key value is returned only once in this response and cannot be retrieved later, so it must be stored securely immediately upon creation.

Arguments:

  • api_key_request - Configuration for the new API key including:
    • description: Human-readable description for identification
    • apiKeyType: Key type ("INFERENCE", "ADMIN", etc.)
    • expiresAt: Optional ISO 8601 expiration timestamp
    • consumptionLimit: Optional usage quotas and restrictions

Returns:

Complete API key object including the secret key value, metadata, and configuration details.

Raises:

  • AuthenticationError - If the current credentials are invalid.
  • APIError - If the request is invalid or account limits are exceeded.
  • APIConnectionError - If unable to connect to the API.

Warnings:

The secret key value is only returned once. Store it securely immediately.

Example:

.. code-block:: python

from venice_ai.types.api import CreateApiKeyRequest

Create a production API key

request = CreateApiKeyRequest( description="Production Service Key", apiKeyType="INFERENCE" ) new_key = await client.api_keys.create(api_key_request=request)

Store the secret key securely

secret_key = new_key.apiKey # Only available now!

ApiKeys.delete

async def delete(*, api_key_id: str) -> DeleteApiKeyResponse

Permanently delete an API key.

Removes the specified API key from the account, immediately invalidating it for all future requests. This operation cannot be undone.

Arguments:

  • api_key_id - Unique identifier of the API key to delete. This is the key's ID (not the secret value) as returned by create or list operations.

Returns:

Deletion confirmation response with operation status.

Raises:

  • AuthenticationError - If the current credentials are invalid.
  • APIError - If the key ID doesn't exist or belongs to another account.
  • APIConnectionError - If unable to connect to the API.

Warnings:

This operation is irreversible. The deleted key cannot be recovered.

Example:

.. code-block:: python

Delete a specific key

result = await client.api_keys.delete(api_key_id="key_123456789")

Batch delete test keys

keys = await client.api_keys.list() for key in keys: if "test" in key.description.lower(): await client.api_keys.delete(api_key_id=key.id)

ApiKeys.update

async def update(
*,
id: str,
description: str | None = None,
expires_at: str | None = None,
consumption_limit: dict[str, Any] | None = None,
limit_period: Literal["EPOCH", "MONTH", "LIFETIME"] | None = None
) -> ApiKey

Update an existing API key (PATCH /api_keys).

Arguments:

  • id - ID of the API key to update.
  • description - New description for the key.
  • expires_at - New expiration date (ISO 8601 format).
  • consumption_limit - Epoch consumption limits (e.g., {'diem': 1, 'usd': 10}).
  • limit_period - Period over which the consumption limit resets (EPOCH, MONTH, or LIFETIME).

Returns:

Updated :class:ApiKey object.

Raises:

  • AuthenticationError - If the API key is invalid or expired.
  • APIError - If the request fails or returns an error response.
  • APIConnectionError - If unable to connect to the API.

Example:

.. code-block:: python

updated = await client.api_keys.update( id="key_123", description="Updated description",

  • consumption_limit={"diem" - 5, "usd": 50}, )

ApiKeys.retrieve

async def retrieve(*, api_key_id: str) -> ApiKey

Retrieve detailed information about a specific API key.

Fetches comprehensive metadata for the specified API key, including usage statistics, configuration details, and current status. The secret key value is never included in responses for security purposes.

Arguments:

  • api_key_id - Unique identifier of the API key to retrieve.

Returns:

:class:ApiKey with metadata, usage statistics, and configuration parameters. The wire response is {"data": {<ApiKey fields>}}; the wrapper is unwrapped so callers receive the bare object, consistent with :meth:update.

Raises:

  • AuthenticationError - If the current credentials are invalid.
  • NotFoundError - If the specified key ID doesn't exist.
  • APIError - If the request fails or returns an error response.
  • APIConnectionError - If unable to connect to the API.

Example:

.. code-block:: python

Get detailed key information

api_key = await client.api_keys.retrieve(api_key_id="key_123456789")

  • print(f"Description - {api_key.description}")
  • print(f"Created - {api_key.createdAt}")
  • print(f"Usage - {api_key.usage}")

ApiKeys.get_web3_token

async def get_web3_token() -> Web3TokenResponse

Retrieve a temporary token for Web3 API key generation.

Generates a time-limited authentication token required for creating API keys through Web3 blockchain authentication. This token must be used in the subsequent Web3 key creation request.

Returns:

Response containing the temporary token and any associated metadata required for Web3 authentication.

Raises:

  • APIError - If token generation fails or service is unavailable.
  • APIConnectionError - If unable to connect to the API.

Notes:

The returned token has a limited lifespan and should be used immediately in the Web3 key creation process.

ApiKeys.create_web3_key

async def create_web3_key(
*, web3_key_request: Web3CreateApiKeyRequest) -> Web3ApiKeyResponse

Create a new API key using Web3 blockchain authentication.

Generates an API key authenticated through blockchain signature verification, enabling decentralized identity management for Venice AI access.

Arguments:

  • web3_key_request - Web3 authentication request containing:
    • apiKeyType: API key type ("INFERENCE" or "ADMIN")
    • address: Wallet address for authentication
    • signature: Signed token for verification
    • token: Token from get_web3_token()
    • description (optional): API key description
    • consumptionLimit (optional): Spending limits
    • limitPeriod (optional): Consumption-limit reset period ("EPOCH"/"MONTH"/"LIFETIME")
    • expiresAt (optional): Expiration date

Returns:

Response containing the newly created API key and associated metadata.

Raises:

  • APIError - If Web3 verification fails or key creation is rejected.
  • APIConnectionError - If unable to connect to the API.

Notes:

Requires a valid Web3 token from get_web3_token() and proper signature verification against the specified blockchain network.

ApiKeys.get_rate_limits

async def get_rate_limits() -> RateLimitsResponse

Retrieve current rate limit information and usage statistics.

Returns comprehensive rate limiting data for the authenticated API key, including configured limits across different time periods and current usage levels.

Returns:

Rate limit configuration and current usage statistics including:

  • Limits per minute, hour, day, and month
  • Current usage counts for each period
  • Remaining capacity and reset times

Raises:

  • AuthenticationError - If the API key is invalid or expired.
  • APIError - If the request fails or returns an error response.
  • APIConnectionError - If unable to connect to the API.

Example:

.. code-block:: python

Check current rate limits

limits = await client.api_keys.get_rate_limits() print(f"Requests per minute: {limits.data.requests_per_minute}") print(f"Current usage: {limits.data.current_usage}")

ApiKeys.get_rate_limit_logs

async def get_rate_limit_logs() -> RateLimitLogsResponse

Retrieves the last 50 rate limit violations for the account asynchronously.

Returns the last 50 rate limits that the account exceeded. This endpoint helps monitor and troubleshoot rate limiting issues by providing a history of when limits were hit.

Raises:

  • venice_ai.exceptions.AuthenticationError: If authentication fails.

  • venice_ai.exceptions.APIError: If the API returns an error.

  • venice_ai.exceptions.APIConnectionError: If there's an issue connecting to the API. Example: .. code-block:: python

    # Get recent rate limit logs asynchronously
    logs_response = await client.api_keys.get_rate_limit_logs()
    for log_entry in logs_response.data:
    print(f"Model: {log_entry.modelId}, Type: {log_entry.rateLimitType}, Time: {log_entry.timestamp}")

Returns:

List of the last 50 rate limit violations with timestamps, models, and violation types.