venice-dev-tools
Version:
unOfficial SDK for the Venice AI API
1,824 lines (1,787 loc) • 66.9 kB
TypeScript
import { AxiosInstance, InternalAxiosRequestConfig, AxiosError, AxiosResponse } from 'axios';
/**
* Types for the Characters API endpoints
*/
/**
* A character available in the Venice AI API
*/
interface Character$1 {
name: string;
description: string | null;
slug: string;
shareUrl: string | null;
createdAt: string;
updatedAt: string;
webEnabled: boolean;
adult: boolean;
tags: string[];
stats: {
imports: number;
};
}
/**
* Response for listing available characters
*/
interface ListCharactersResponse$1 {
object: 'list';
data: Character$1[];
}
/**
* Types for multimodal content
*/
/**
* Text content type
*/
interface TextContent {
type: 'text';
text: string;
}
/**
* Image URL content type
*/
interface ImageUrlContent {
type: 'image_url';
image_url: {
url: string;
};
}
/**
* Union type for all content types
*/
type ContentItem = TextContent | ImageUrlContent;
/**
* Types for the Chat API endpoints
*/
/**
* The role of a message in a chat completion
*/
type ChatCompletionRole = 'system' | 'user' | 'assistant';
/**
* A single message in a chat completion
*/
interface ChatCompletionMessage {
/**
* The role of the message author
*/
role: ChatCompletionRole;
/**
* The content of the message
* Can be a string for simple text messages or an array of content items for multimodal messages
*/
content: string | ContentItem[];
}
/**
* Request parameters for chat completion
*/
interface ChatCompletionRequest {
/**
* The model to use for chat completion
*/
model: string;
/**
* A list of messages to generate a completion for
*/
messages: ChatCompletionMessage[];
/**
* The maximum number of tokens to generate
*/
max_tokens?: number;
/**
* The temperature for sampling (0-1). Higher values mean more randomness.
*/
temperature?: number;
/**
* The top-p sampling parameter (0-1)
*/
top_p?: number;
/**
* Whether to stream the response
*/
stream?: boolean;
}
/**
* Chat completion choice object returned by the API
*/
interface ChatCompletionChoice {
/**
* The index of the choice
*/
index: number;
/**
* The completion message
*/
message: ChatCompletionMessage;
/**
* The finish reason
*/
finish_reason: string | null;
}
/**
* Usage statistics for a chat completion
*/
interface ChatCompletionUsage {
/**
* The number of prompt tokens used
*/
prompt_tokens: number;
/**
* The number of completion tokens used
*/
completion_tokens: number;
/**
* The total number of tokens used
*/
total_tokens: number;
}
/**
* Response from a chat completion request
*/
interface ChatCompletionResponse {
/**
* The ID of the chat completion
*/
id: string;
/**
* The type of object ("chat.completion")
*/
object: string;
/**
* The timestamp of when the completion was created
*/
created: number;
/**
* The model used for the completion
*/
model: string;
/**
* The list of completion choices
*/
choices: ChatCompletionChoice[];
/**
* Usage statistics
*/
usage: ChatCompletionUsage;
}
/**
* Interface for API error responses.
*/
interface ApiErrorResponse {
error: string;
details?: Record<string, any>;
}
/**
* Log levels for the logger.
*/
declare enum LogLevel {
DEBUG = 0,
INFO = 1,
WARN = 2,
ERROR = 3,
NONE = 4
}
/**
* Interface for Venice API client configuration.
*/
interface VeniceClientConfig {
/**
* The API key for authentication.
*/
apiKey?: string;
/**
* The base URL for the API.
*/
baseUrl?: string;
/**
* Request timeout in milliseconds.
*/
timeout?: number;
/**
* Additional headers to include in requests.
*/
headers?: Record<string, string>;
/**
* Maximum number of concurrent requests.
*/
maxConcurrent?: number;
/**
* Maximum requests per minute.
*/
requestsPerMinute?: number;
/**
* Log level for the client.
*/
logLevel?: LogLevel;
}
/**
* Interface for Venice-specific parameters for requests.
*/
interface VeniceParameters {
enable_web_search?: 'auto' | 'on' | 'off';
include_venice_system_prompt?: boolean;
character_slug?: string;
}
/**
* Interface for character information.
*/
interface Character {
name: string;
description: string | null;
slug: string;
shareUrl: string | null;
createdAt: string;
updatedAt: string;
webEnabled: boolean;
adult: boolean;
tags: string[];
stats: {
imports: number;
};
}
/**
* Interface for the response from listing characters.
*/
interface ListCharactersResponse {
object: 'list';
data: Character[];
}
/**
* Type for HTTP methods.
*/
type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
/**
* Interface for HTTP request options.
*/
interface HttpRequestOptions {
method?: HttpMethod;
headers?: Record<string, string>;
body?: any;
query?: Record<string, any>;
timeout?: number;
responseType?: 'json' | 'text' | 'arraybuffer' | 'blob' | 'stream';
signal?: AbortSignal;
}
/**
* Interface for HTTP response.
*/
interface HttpResponse<T = any> {
data: T;
status: number;
statusText: string;
headers: Record<string, string>;
}
/**
* Type for streaming response handlers.
*/
type StreamHandler<T> = (chunk: T) => void | Promise<void>;
interface ImageRequest {
model: string;
n?: number;
size?: number;
response_format?: 'url' | 'b64_json';
user?: string;
prompt?: string;
negative_prompt?: string;
style?: string;
quality?: 'standard' | 'high' | 'ultra';
safety?: 'low' | 'medium' | 'high';
copyright?: 'free' | 'commercial';
watermark?: 'none' | 'low' | 'high';
metadata?: {
key: string;
value: string;
}[];
}
interface GenerateImageRequest extends ImageRequest {
}
interface GenerateImageResponse {
data: {
url: string;
created_at: number;
model: string;
size: number;
response_format: 'url' | 'b64_json';
user: string;
prompt: string;
negative_prompt: string;
style: string;
quality: 'standard' | 'high' | 'ultra';
safety: 'low' | 'medium' | 'high';
copyright: 'free' | 'commercial';
watermark: 'none' | 'low' | 'high';
metadata: {
key: string;
value: string;
}[];
};
}
interface GenerateImageResponseHeaders {
'x-venice-is-content-violation'?: boolean;
'x-venice-is-blurred'?: boolean;
}
interface UpscaleImageParams {
image: Blob | ArrayBuffer | string;
scale?: 2 | 4;
}
interface ListImageStylesResponse {
styles: {
name: string;
description: string;
available: boolean;
}[];
}
/**
* Types for the API Keys endpoints
*/
/**
* Rate limit log entry
*/
interface RateLimitLogEntry {
/**
* The ID of the API key that exceeded the limit
*/
apiKeyId: string;
/**
* The ID of the model that was used when the rate limit was exceeded
*/
modelId: string;
/**
* The type of rate limit that was exceeded
*/
rateLimitType: string;
/**
* The API tier of the rate limit
*/
rateLimitTier: string;
/**
* The timestamp when the rate limit was exceeded
*/
timestamp: string;
}
/**
* Response from getting rate limit logs
*/
interface ListRateLimitLogsResponse {
/**
* The type of object ("list")
*/
object: string;
/**
* Array of rate limit log entries
*/
data: RateLimitLogEntry[];
}
/**
* An API key object
*/
interface ApiKey {
/**
* The API key ID
*/
id: string;
/**
* The API key value (only shown once on creation)
*/
key?: string;
/**
* The name of the API key
*/
name: string;
/**
* The timestamp when the key was created
*/
created_at: string;
/**
* The timestamp when the key was last used
*/
last_used_at?: string;
/**
* The expiration date of the key (if any)
*/
expires_at?: string;
/**
* Whether the key has been revoked
*/
is_revoked?: boolean;
}
/**
* Request to create a new API key
*/
interface CreateApiKeyRequest {
/**
* The name to assign to the new API key
*/
name: string;
/**
* Optional expiration date for the key (ISO 8601 format)
*/
expires_at?: string;
}
/**
* Response from creating a new API key
*/
interface CreateApiKeyResponse {
/**
* The created API key object
*/
api_key: ApiKey;
}
/**
* Response from listing API keys
*/
interface ListApiKeysResponse {
/**
* Array of API keys
*/
api_keys: ApiKey[];
}
/**
* Request to update an API key
*/
interface UpdateApiKeyRequest {
/**
* New name for the API key (optional)
*/
name?: string;
/**
* New expiration date for the key (ISO 8601 format, optional)
*/
expires_at?: string;
}
/**
* Response from updating an API key
*/
interface UpdateApiKeyResponse {
/**
* The updated API key object
*/
api_key: ApiKey;
}
/**
* Response from generating a web3 token
*/
interface GenerateWeb3TokenResponse {
/**
* The generated token to be signed with a wallet
*/
token: string;
}
/**
* Request to create an API key with web3 authentication
*/
interface CreateWeb3ApiKeyRequest {
/**
* The wallet address
*/
address: string;
/**
* The signature of the token
*/
signature: string;
/**
* The token that was signed
*/
token: string;
/**
* Description for the API key
*/
description?: string;
/**
* Type of API key (ADMIN or INFERENCE)
*/
apiKeyType?: 'ADMIN' | 'INFERENCE';
/**
* Expiration date for the key (ISO 8601 format)
*/
expiresAt?: string;
/**
* Consumption limits for the key
*/
consumptionLimit?: {
/**
* VCU consumption limit
*/
vcu: number | null;
/**
* USD consumption limit
*/
usd: number | null;
};
}
/**
* Response from creating an API key with web3 authentication
*/
interface CreateWeb3ApiKeyResponse {
/**
* The created API key object
*/
api_key: ApiKey;
}
/**
* Interface representing a model specification.
*/
interface ModelSpec {
availableContextTokens?: number;
capabilities?: {
supportsFunctionCalling?: boolean;
supportsResponseSchema?: boolean;
supportsWebSearch?: boolean;
supportsReasoning?: boolean;
};
traits?: string[];
modelSource?: string;
beta?: boolean;
offline?: boolean;
}
/**
* Interface representing a model in the API.
*/
interface Model {
id: string;
type: 'image' | 'text';
object: 'model';
created: number;
owned_by: string;
model_spec: ModelSpec;
}
/**
* Interface representing the response from listing models.
*/
interface ListModelsResponse {
object: 'list';
type: 'text' | 'image' | 'all' | 'code';
data: Model[];
}
/**
* Interface representing the model traits.
*/
interface ModelTraits {
[trait: string]: string;
}
/**
* Interface representing the response from listing model traits.
*/
interface ListModelTraitsResponse {
object: 'list';
type: 'text' | 'image' | 'all' | 'code';
data: ModelTraits;
}
/**
* Interface representing the model compatibility mapping.
*/
interface ModelCompatibility {
[model: string]: string;
}
/**
* Interface representing the response from listing model compatibility mappings.
*/
interface ListModelCompatibilityResponse {
object: 'list';
type: 'text' | 'image' | 'all' | 'code';
data: ModelCompatibility;
}
/**
* Interface representing parameters for listing models.
*/
interface ListModelsParams {
type?: 'text' | 'image' | 'all' | 'code';
}
/**
* Interface representing a model request.
*/
interface ModelRequest {
model: string;
prompt: string;
max_tokens?: number;
temperature?: number;
top_p?: number;
n?: number;
stream?: boolean;
logprobs?: number;
echo?: boolean;
stop?: string[];
presence_penalty?: number;
frequency_penalty?: number;
best_of?: number;
logit_bias?: {
[token: string]: number;
};
user?: string;
}
/**
* Manages configuration settings for the Venice AI SDK.
* Handles API key management and other configuration options.
*/
declare class ConfigManager {
/**
* The client configuration.
*/
private config;
/**
* Create a new configuration manager.
* @param initialConfig - The initial configuration.
*/
constructor(initialConfig?: VeniceClientConfig);
/**
* Get the current configuration.
* @returns The current configuration.
*/
getConfig(): VeniceClientConfig;
/**
* Set the API key for authentication.
* @param apiKey - The Venice API key.
* @throws VeniceAuthError if the API key is empty.
*/
setApiKey(apiKey: string): void;
/**
* Get the current API key.
* @returns The current API key or undefined if not set.
*/
getApiKey(): string | undefined;
/**
* Get the current API key, throwing an error if not set.
* @returns The current API key.
* @throws VeniceAuthError if no API key is set.
*/
getRequiredApiKey(): string;
/**
* Set a custom header for API requests.
* @param name - The header name.
* @param value - The header value.
*/
setHeader(name: string, value: string): void;
/**
* Get the base URL for API requests.
* @returns The base URL.
*/
getBaseUrl(): string;
/**
* Get the request timeout in milliseconds.
* @returns The timeout in milliseconds.
*/
getTimeout(): number;
/**
* Get the headers for API requests.
* @returns The headers.
*/
getHeaders(): Record<string, string>;
}
/**
* Manages events for the Venice AI SDK.
* Provides methods for subscribing to and emitting events.
*/
declare class EventManager {
/**
* The event emitter instance.
*/
private events;
/**
* Create a new event manager.
*/
constructor();
/**
* Subscribe to an event.
* @param event - The event name.
* @param listener - The event listener.
* @returns This event manager instance.
*/
on(event: string, listener: (...args: any[]) => void): this;
/**
* Subscribe to an event for one-time execution.
* @param event - The event name.
* @param listener - The event listener.
* @returns This event manager instance.
*/
once(event: string, listener: (...args: any[]) => void): this;
/**
* Unsubscribe from an event.
* @param event - The event name.
* @param listener - The event listener.
* @returns This event manager instance.
*/
off(event: string, listener: (...args: any[]) => void): this;
/**
* Emit an event.
* @param event - The event name.
* @param args - The event arguments.
* @returns Whether the event had listeners.
*/
emit(event: string, ...args: any[]): boolean;
/**
* Remove all listeners for an event.
* @param event - The event name (optional, if not provided, removes all listeners).
* @returns This event manager instance.
*/
removeAllListeners(event?: string): this;
/**
* Get the number of listeners for an event.
* @param event - The event name.
* @returns The number of listeners.
*/
listenerCount(event: string): number;
}
/**
* A log entry.
*/
interface LogEntry {
level: LogLevel;
message: string;
timestamp: string;
data?: any;
}
/**
* Options for the logger.
*/
interface LoggerOptions {
level?: LogLevel;
handlers?: Array<(entry: LogEntry) => void>;
}
/**
* Logger for the Venice AI SDK.
* Provides logging functionality with different log levels.
*/
declare class Logger {
/**
* The current log level.
*/
private level;
/**
* The log handlers.
*/
private handlers;
/**
* Creates a new logger.
*
* @param options - Logger options
*/
constructor(options?: LoggerOptions);
/**
* Sets the log level.
*
* @param level - The log level
*/
setLevel(level: LogLevel): void;
/**
* Adds a log handler.
*
* @param handler - The log handler
*/
addHandler(handler: (entry: LogEntry) => void): void;
/**
* Logs a debug message.
*
* @param message - The message to log
* @param data - Additional data to log
*/
debug(message: string, data?: any): void;
/**
* Logs an info message.
*
* @param message - The message to log
* @param data - Additional data to log
*/
info(message: string, data?: any): void;
/**
* Logs a warning message.
*
* @param message - The message to log
* @param data - Additional data to log
*/
warn(message: string, data?: any): void;
/**
* Logs an error message.
*
* @param message - The message to log
* @param data - Additional data to log
*/
error(message: string, data?: any): void;
/**
* Logs a message at the specified level.
*
* @param level - The log level
* @param message - The message to log
* @param data - Additional data to log
*/
private log;
/**
* Default log handler.
*
* @param entry - The log entry
*/
private defaultHandler;
}
/**
* Configuration options for HTTP client
*/
interface HttpClientConfig {
/**
* Base URL for API requests
*/
baseUrl?: string;
/**
* Default headers to include in all requests
*/
headers?: Record<string, string>;
/**
* Request timeout in milliseconds
*/
timeout?: number;
/**
* Logger instance
*/
logger?: Logger;
}
/**
* HTTP client interface
*/
interface IHttpClient {
/**
* Set an authorization header with a bearer token
* @param token - The API key or token
*/
setAuthToken(token: string): void;
/**
* Set a custom header for future requests
* @param name - The header name
* @param value - The header value
*/
setHeader(name: string, value: string): void;
/**
* Make an HTTP request
* @param path - The API path (will be appended to the base URL)
* @param options - Request options
* @returns The response data
*/
request<T = any>(path: string, options?: HttpRequestOptions): Promise<HttpResponse<T>>;
/**
* Make a GET request
* @param path - The API path
* @param options - Request options
* @returns The response data
*/
get<T = any>(path: string, options?: Omit<HttpRequestOptions, 'method'>): Promise<HttpResponse<T>>;
/**
* Make a POST request
* @param path - The API path
* @param body - The request body
* @param options - Additional request options
* @returns The response data
*/
post<T = any>(path: string, body?: any, options?: Omit<HttpRequestOptions, 'method' | 'body'>): Promise<HttpResponse<T>>;
/**
* Make a DELETE request
* @param path - The API path
* @param options - Request options
* @returns The response data
*/
delete<T = any>(path: string, options?: Omit<HttpRequestOptions, 'method'>): Promise<HttpResponse<T>>;
/**
* Create a new stream request
* @param path - The API path
* @param body - The request body
* @param options - Additional request options
* @returns A fetch response for streaming
*/
stream(path: string, body?: any, options?: Omit<HttpRequestOptions, 'method' | 'body'>): Promise<Response>;
}
/**
* Base HTTP client implementation
*
* This module provides the core HTTP client functionality.
*/
/**
* HTTP client for making requests to the Venice AI API
*/
declare class BaseHttpClient$1 implements IHttpClient {
/**
* The Axios client instance
*/
protected client: AxiosInstance;
/**
* The base URL for the API
*/
protected baseUrl: string;
/**
* The logger instance
*/
protected logger: Logger;
/**
* The request timeout in milliseconds
*/
protected timeout: number;
/**
* Create a new HTTP client
* @param config - Configuration options
*/
constructor(config?: HttpClientConfig);
/**
* Set an authorization header with a bearer token
* @param token - The API key or token
*/
setAuthToken(token: string): void;
/**
* Set a custom header for future requests
* @param name - The header name
* @param value - The header value
*/
setHeader(name: string, value: string): void;
/**
* Get all headers currently set on the client
* @returns The headers object
*/
getHeaders(): Record<string, string>;
/**
* Make an HTTP request
* @param path - The API path (will be appended to the base URL)
* @param options - Request options
* @returns The response data
*/
request<T = any>(path: string, options?: HttpRequestOptions): Promise<HttpResponse<T>>;
/**
* Make a GET request
* @param path - The API path
* @param options - Request options
* @returns The response data
*/
get<T = any>(path: string, options?: Omit<HttpRequestOptions, 'method'>): Promise<HttpResponse<T>>;
/**
* Make a POST request
* @param path - The API path
* @param body - The request body
* @param options - Additional request options
* @returns The response data
*/
post<T = any>(path: string, body?: any, options?: Omit<HttpRequestOptions, 'method' | 'body'>): Promise<HttpResponse<T>>;
/**
* Make a DELETE request
* @param path - The API path
* @param options - Request options
* @returns The response data
*/
delete<T = any>(path: string, options?: Omit<HttpRequestOptions, 'method'>): Promise<HttpResponse<T>>;
/**
* Create a new stream request
* @param path - The API path
* @param body - The request body
* @param options - Additional request options
* @returns A fetch response for streaming
*/
stream(path: string, body?: any, options?: Omit<HttpRequestOptions, 'method' | 'body'>): Promise<Response>;
}
/**
* HTTP request/response sanitization utilities
*
* This module provides utilities for sanitizing sensitive information
* from HTTP headers and request/response data before logging.
*/
/**
* Sanitize headers for logging by removing sensitive information
* @param headers - The headers to sanitize
* @returns The sanitized headers
*/
declare function sanitizeHeaders(headers: any): any;
/**
* Sanitize request/response data for logging by removing sensitive information
* @param data - The data to sanitize
* @returns The sanitized data
*/
declare function sanitizeData(data: any): any;
/**
* HTTP client interceptors
*
* This module provides request and response interceptors for the HTTP client.
* Interceptors are used for logging, adding request IDs, and other cross-cutting concerns.
*/
/**
* Create a request interceptor
* @param logger - The logger instance
* @returns An object with request and error handlers
*/
declare function createRequestInterceptor(logger: Logger): {
/**
* Handle outgoing requests
* @param config - The Axios request config
* @returns The modified config
*/
onRequest: (config: InternalAxiosRequestConfig) => InternalAxiosRequestConfig;
/**
* Handle request errors
* @param error - The error that occurred
* @returns A rejected promise with the error
*/
onRequestError: (error: AxiosError) => Promise<AxiosError>;
};
/**
* Create a response interceptor
* @param logger - The logger instance
* @returns An object with response and error handlers
*/
declare function createResponseInterceptor(logger: Logger): {
/**
* Handle successful responses
* @param response - The Axios response
* @returns The response
*/
onResponse: (response: AxiosResponse) => AxiosResponse;
/**
* Handle response errors
* @param error - The error that occurred
* @returns A rejected promise with the error
*/
onResponseError: (error: AxiosError) => Promise<AxiosError>;
};
/**
* HTTP error handling utilities
*
* This module provides utilities for handling HTTP errors and transforming
* them into appropriate SDK-specific error types.
*/
/**
* Handle API request errors and transform them into appropriate SDK errors
* @param error - The Axios error
* @param logger - The logger instance
* @param timeout - The request timeout in milliseconds
* @throws A transformed SDK-specific error
*/
declare function handleRequestError(error: AxiosError, logger: Logger, timeout: number): never;
/**
* Handle streaming request errors
* @param error - The error that occurred
* @param logger - The logger instance
* @param requestId - The request ID
* @throws A transformed SDK-specific error
*/
declare function handleStreamError(error: any, logger: Logger, requestId: string): never;
/**
* HTTP streaming utilities
*
* This module provides utilities for making streaming HTTP requests.
*/
/**
* Options for streaming requests
*/
interface StreamRequestOptions {
/**
* Request headers
*/
headers?: Record<string, string>;
/**
* AbortSignal for cancelling the request
*/
signal?: AbortSignal;
}
/**
* Create a streaming HTTP request
* @param baseUrl - The base URL for the API
* @param path - The API path
* @param body - The request body
* @param options - Additional request options
* @param logger - The logger instance
* @returns A fetch response for streaming
*/
declare function createStreamRequest(baseUrl: string, path: string, body: any, options: StreamRequestOptions | undefined, logger: Logger): Promise<Response>;
/**
* Process a streaming response
* @param response - The fetch response
* @param onChunk - Callback function for each chunk
* @param logger - The logger instance
*/
declare function processStreamResponse(response: Response, onChunk: (chunk: string) => void, logger: Logger): Promise<void>;
/**
* HTTP client for making requests to the Venice AI API
*/
declare class HttpClient extends BaseHttpClient$1 {
/**
* Create a new HTTP client
* @param baseUrl - The base URL for the API
* @param headers - Additional headers to include in requests
* @param timeout - Request timeout in milliseconds
* @param logger - Optional logger instance
*/
constructor(baseUrl?: string, headers?: Record<string, string>, timeout?: number, logger?: any);
/**
* Get the headers currently set on the client
* @returns The headers object
*/
getHeaders(): Record<string, string>;
}
/**
* Base abstract class for HTTP clients in the Venice AI SDK.
* Provides common functionality for making API requests.
*/
declare abstract class BaseHttpClient {
/**
* The base URL for API requests.
*/
protected baseUrl: string;
/**
* Headers to include in API requests.
*/
protected headers: Record<string, string>;
/**
* Request timeout in milliseconds.
*/
protected timeout: number;
/**
* Create a new HTTP client.
* @param baseUrl - The base URL for the API.
* @param headers - Additional headers to include in requests.
* @param timeout - Request timeout in milliseconds.
*/
constructor(baseUrl?: string, headers?: Record<string, string>, timeout?: number);
/**
* Set an authorization header with a bearer token.
* @param token - The API key or token.
*/
setAuthToken(token: string): void;
/**
* Set a custom header for future requests.
* @param name - The header name.
* @param value - The header value.
*/
setHeader(name: string, value: string): void;
/**
* Get the current headers.
* @returns The current headers.
*/
getHeaders(): Record<string, string>;
/**
* Get the base URL.
* @returns The base URL.
*/
getBaseUrl(): string;
/**
* Get the timeout.
* @returns The timeout in milliseconds.
*/
getTimeout(): number;
/**
* Set the timeout.
* @param timeout - The timeout in milliseconds.
*/
setTimeout(timeout: number): void;
}
/**
* Base error class for Venice AI SDK errors.
*/
declare class VeniceError extends Error {
/**
* Create a new Venice SDK error.
* @param message - The error message.
* @param options - Additional error options.
*/
constructor(message: string, options?: ErrorOptions);
}
/**
* Interface for error options.
*/
interface ErrorOptions {
cause?: unknown;
}
/**
* Error for validation issues.
*/
declare class VeniceValidationError extends VeniceError {
/**
* Additional validation details.
*/
readonly details?: Record<string, any>;
/**
* Create a new validation error.
* @param message - The error message.
* @param details - Additional validation details.
*/
constructor(message: string, details?: Record<string, any>);
}
/**
* Factory for creating Venice SDK errors.
*/
declare class ErrorFactory {
/**
* Create an error from an API response.
* @param status - The HTTP status code.
* @param message - The error message.
* @param details - Additional error details.
* @returns A Venice SDK error.
*/
createFromResponse(status: number, message: string, details?: Record<string, any>): VeniceError;
/**
* Create an error from an Axios error.
* @param error - The Axios error.
* @returns A Venice SDK error.
*/
createFromAxiosError(error: AxiosError): VeniceError;
/**
* Create an error from a fetch response.
* @param response - The fetch response.
* @returns A promise that resolves to a Venice SDK error.
*/
createFromFetchResponse(response: Response): Promise<VeniceError>;
/**
* Create an error from a stream error.
* @param error - The error that occurred during streaming.
* @returns A Venice SDK error.
*/
createFromStreamError(error: unknown): VeniceError;
/**
* Create a validation error.
* @param message - The error message.
* @param details - Additional validation details.
* @returns A Venice validation error.
*/
createValidationError(message: string, details?: Record<string, any>): VeniceValidationError;
/**
* Create a generic error from any error.
* @param error - The error to convert.
* @returns A Venice SDK error.
*/
createFromError(error: unknown): VeniceError;
}
/**
* Handles HTTP request errors and transforms them into appropriate SDK errors.
*/
declare class ErrorHandler {
/**
* The error factory used to create Venice SDK errors.
*/
private errorFactory;
/**
* Create a new error handler.
* @param errorFactory - The error factory to use.
*/
constructor(errorFactory?: ErrorFactory);
/**
* Handle API request errors from standard HTTP requests.
* @param error - The Axios error.
* @throws A Venice SDK error.
*/
handleRequestError(error: AxiosError): never;
/**
* Handle API stream errors from streaming HTTP requests.
* @param error - The error that occurred during streaming.
* @throws A Venice SDK error.
*/
handleStreamError(error: unknown): never;
/**
* Handle errors from response parsing.
* @param response - The fetch response.
* @throws A Venice SDK error if the response is not OK.
*/
handleResponseError(response: Response): Promise<void>;
}
/**
* Rate limiter for API requests.
* Manages request concurrency and rate limits.
*/
declare class RateLimiter {
/**
* Queue of pending requests.
*/
private queue;
/**
* Number of currently running requests.
*/
private running;
/**
* Maximum number of concurrent requests.
*/
private maxConcurrent;
/**
* Maximum requests per minute.
*/
private requestsPerMinute;
/**
* Timestamps of recent requests for rate limiting.
*/
private requestTimestamps;
/**
* Creates a new rate limiter.
*
* @param maxConcurrent - Maximum number of concurrent requests
* @param requestsPerMinute - Maximum requests per minute
*/
constructor(maxConcurrent?: number, requestsPerMinute?: number);
/**
* Adds a request to the rate limiter.
*
* @param fn - The request function to execute
* @returns A promise resolving to the request result
* @throws {VeniceRateLimitError} If the rate limit is exceeded
*/
add<T>(fn: () => Promise<T>): Promise<T>;
/**
* Processes the next request in the queue.
*/
private processQueue;
/**
* Records a request for rate limiting.
*/
private recordRequest;
/**
* Enforces the rate limit.
*
* @throws {VeniceRateLimitError} If the rate limit is exceeded
*/
private enforceRateLimit;
}
/**
* HTTP client for making standard (non-streaming) requests to the Venice AI API.
*/
declare class StandardHttpClient extends BaseHttpClient {
/**
* The Axios client instance.
*/
private client;
/**
* The error handler.
*/
private errorHandler;
/**
* The rate limiter for controlling request concurrency and rate limits.
*/
private rateLimiter?;
/**
* The logger for logging events and errors.
*/
private logger?;
/**
* Create a new standard HTTP client.
* @param baseUrl - The base URL for the API.
* @param headers - Additional headers to include in requests.
* @param timeout - Request timeout in milliseconds.
* @param errorHandler - The error handler to use.
* @param rateLimiter - Optional rate limiter for controlling request concurrency.
* @param logger - Optional logger for logging events and errors.
*/
constructor(baseUrl?: string, headers?: Record<string, string>, timeout?: number, errorHandler?: ErrorHandler, rateLimiter?: RateLimiter, logger?: Logger);
/**
* Set an authorization header with a bearer token.
* @param token - The API key or token.
*/
setAuthToken(token: string): void;
/**
* Set a custom header for future requests.
* @param name - The header name.
* @param value - The header value.
*/
setHeader(name: string, value: string): void;
/**
* Make an HTTP request.
* @param path - The API path (will be appended to the base URL).
* @param options - Request options.
* @returns The response data.
*/
request<T = any>(path: string, options?: HttpRequestOptions): Promise<HttpResponse<T>>;
/**
* Make a GET request.
* @param path - The API path.
* @param options - Request options.
* @returns The response data.
*/
get<T = any>(path: string, options?: Omit<HttpRequestOptions, 'method'>): Promise<HttpResponse<T>>;
/**
* Make a POST request.
* @param path - The API path.
* @param body - The request body.
* @param options - Additional request options.
* @returns The response data.
*/
post<T = any>(path: string, body?: any, options?: Omit<HttpRequestOptions, 'method' | 'body'>): Promise<HttpResponse<T>>;
/**
* Make a DELETE request.
* @param path - The API path.
* @param options - Request options.
* @returns The response data.
*/
delete<T = any>(path: string, options?: Omit<HttpRequestOptions, 'method'>): Promise<HttpResponse<T>>;
}
/**
* HTTP client for making streaming requests to the Venice AI API.
*/
declare class StreamingHttpClient extends BaseHttpClient {
/**
* The error handler.
*/
private errorHandler;
/**
* The rate limiter for controlling request concurrency and rate limits.
*/
private rateLimiter?;
/**
* The logger for logging events and errors.
*/
private logger?;
/**
* Create a new streaming HTTP client.
* @param baseUrl - The base URL for the API.
* @param headers - Additional headers to include in requests.
* @param timeout - Request timeout in milliseconds.
* @param errorHandler - The error handler to use.
* @param rateLimiter - Optional rate limiter for controlling request concurrency.
* @param logger - Optional logger for logging events and errors.
*/
constructor(baseUrl?: string, headers?: Record<string, string>, timeout?: number, errorHandler?: ErrorHandler, rateLimiter?: RateLimiter, logger?: Logger);
/**
* Create a new stream request.
* @param path - The API path.
* @param body - The request body.
* @param options - Additional request options.
* @returns A fetch response for streaming.
*/
stream(path: string, body?: any, options?: Omit<HttpRequestOptions, 'method' | 'body'>): Promise<Response>;
/**
* Process a stream response as a readable stream of events.
* @param response - The fetch response.
* @param onEvent - Callback for each event.
* @param onComplete - Callback when the stream completes.
* @param onError - Callback when an error occurs.
*/
processStream(response: Response, onEvent: (event: any) => void, onComplete?: () => void, onError?: (error: Error) => void): Promise<void>;
}
/**
* Factory for creating HTTP client instances.
*/
declare class HttpClientFactory {
/**
* The base URL for API requests.
*/
private baseUrl;
/**
* Headers to include in API requests.
*/
private headers;
/**
* Request timeout in milliseconds.
*/
private timeout;
/**
* The error handler.
*/
private errorHandler;
/**
* The rate limiter for controlling request concurrency and rate limits.
*/
private rateLimiter?;
/**
* The logger for logging events and errors.
*/
private logger?;
/**
* Create a new HTTP client factory.
* @param baseUrl - The base URL for the API.
* @param headers - Additional headers to include in requests.
* @param timeout - Request timeout in milliseconds.
* @param rateLimiter - Optional rate limiter for controlling request concurrency.
* @param logger - Optional logger for logging events and errors.
*/
constructor(baseUrl?: string, headers?: Record<string, string>, timeout?: number, rateLimiter?: RateLimiter, logger?: Logger);
/**
* Create a standard HTTP client.
* @returns A new standard HTTP client.
*/
createStandardClient(): StandardHttpClient;
/**
* Create a streaming HTTP client.
* @returns A new streaming HTTP client.
*/
createStreamingClient(): StreamingHttpClient;
/**
* Set the base URL for all created clients.
* @param baseUrl - The base URL.
*/
setBaseUrl(baseUrl: string): void;
/**
* Set headers for all created clients.
* @param headers - The headers.
*/
setHeaders(headers: Record<string, string>): void;
/**
* Set a specific header for all created clients.
* @param name - The header name.
* @param value - The header value.
*/
setHeader(name: string, value: string): void;
/**
* Set the timeout for all created clients.
* @param timeout - The timeout in milliseconds.
*/
setTimeout(timeout: number): void;
/**
* Set the authorization token for all created clients.
* @param token - The API key or token.
*/
setAuthToken(token: string): void;
}
/**
* The base class for the Venice AI SDK client.
* This provides core functionality shared by all platform-specific implementations.
*/
declare class VeniceClient {
/**
* The configuration manager.
*/
protected configManager: ConfigManager;
/**
* The event manager.
*/
protected eventManager: EventManager;
/**
* The HTTP client factory.
*/
protected httpClientFactory: HttpClientFactory;
/**
* The standard HTTP client for making API requests.
*/
protected standardHttpClient: StandardHttpClient;
/**
* The streaming HTTP client for making streaming API requests.
*/
protected streamingHttpClient: StreamingHttpClient;
/**
* The rate limiter for controlling request concurrency and rate limits.
*/
protected rateLimiter: RateLimiter;
/**
* The logger for logging events and errors.
*/
protected logger: Logger;
/**
* Create a new Venice API client.
* @param config - The client configuration.
*/
constructor(config?: VeniceClientConfig);
/**
* Set the API key for authentication.
* @param apiKey - The Venice API key.
*/
setApiKey(apiKey: string): void;
/**
* Get the current API key.
* @returns The current API key or undefined if not set.
*/
getApiKey(): string | undefined;
/**
* Set a custom header for API requests.
* @param name - The header name.
* @param value - The header value.
*/
setHeader(name: string, value: string): void;
/**
* Get the standard HTTP client for making API requests.
* @returns The standard HTTP client.
*/
getStandardHttpClient(): StandardHttpClient;
/**
* Get the streaming HTTP client for making streaming API requests.
* @returns The streaming HTTP client.
*/
getStreamingHttpClient(): StreamingHttpClient;
/**
* Subscribe to a client event.
* @param event - The event name.
* @param listener - The event listener.
* @returns This client instance.
*/
on(event: string, listener: (...args: any[]) => void): this;
/**
* Unsubscribe from a client event.
* @param event - The event name.
* @param listener - The event listener.
* @returns This client instance.
*/
off(event: string, listener: (...args: any[]) => void): this;
/**
* Emit a client event.
* @param event - The event name.
* @param args - The event arguments.
* @returns Whether the event had listeners.
*/
protected emit(event: string, ...args: any[]): boolean;
/**
* Get the logger instance.
* @returns The logger instance.
*/
getLogger(): Logger;
/**
* Set the log level.
* @param level - The log level.
*/
setLogLevel(level: LogLevel): void;
/**
* Executes a rate-limited API request.
*
* @param fn - The request function to execute
* @returns A promise resolving to the request result
* @throws {VeniceRateLimitError} If the rate limit is exceeded
*/
protected executeRateLimited<T>(fn: () => Promise<T>): Promise<T>;
}
/**
* Base class for all API endpoints in the Venice AI SDK.
* Provides common functionality for interacting with the Venice AI API.
*/
declare abstract class ApiEndpoint {
/**
* The standard HTTP client used for making API requests.
*/
protected http: StandardHttpClient;
/**
* The streaming HTTP client used for making streaming API requests.
*/
protected streamingHttp: StreamingHttpClient;
/**
* The parent client that owns this endpoint.
*/
protected client: VeniceClient;
/**
* Create a new API endpoint.
* @param client - The Venice client that owns this endpoint.
*/
constructor(client: VeniceClient);
/**
* Get the endpoint path for the API request.
* This should be implemented by each specific endpoint class.
*/
abstract getEndpointPath(): string;
/**
* Get a complete API path by combining the endpoint path with a subpath.
* @param subpath - The subpath to append to the endpoint path.
* @returns The complete API path.
*/
protected getPath(subpath?: string): string;
/**
* Emit an event via the parent client.
* @param event - The event name.
* @param args - The event arguments.
*/
protected emit(event: string, ...args: any[]): boolean;
}
/**
* API endpoint for standard (non-streaming) chat completions.
*
* This endpoint allows you to create chat completions using various models.
* It handles validation, request formatting, and response parsing.
*
* @example
* ```typescript
* const response = await venice.chat.createCompletion({
* model: 'llama-3.3-70b',
* messages: [
* { role: 'system', content: 'You are a helpful assistant.' },
* { role: 'user', content: 'What is the capital of France?' }
* ]
* });
*
* console.log(response.choices[0].message.content);
* // Output: Paris is the capital of France.
* ```
*/
declare class ChatEndpoint extends ApiEndpoint {
/**
* The chat validator for validating request parameters.
*/
private validator;
/**
* Creates a new ChatEndpoint instance.
*
* @param client - The Venice client instance
*/
constructor(client: any);
/**
* Gets the base endpoint path for chat requests.
*
* @returns The endpoint path ('/chat')
*/
getEndpointPath(): string;
/**
* Creates a chat completion using the specified model.
*
* @param request - The chat completion request parameters
* @param request.model - The model to use (e.g., 'llama-3.3-70b')
* @param request.messages - The conversation messages array
* @param request.temperature - Controls randomness (0-1, default: 0.7)
* @param request.max_tokens - Maximum tokens to generate (default: varies by model)
* @param request.top_p - Controls diversity via nucleus sampling (0-1, default: 1)
* @param request.frequency_penalty - Penalizes repeated tokens (-2 to 2, default: 0)
* @param request.presence_penalty - Penalizes repeated topics (-2 to 2, default: 0)
* @param request.stop - Array of sequences where the model should stop generating
*
* @returns A promise resolving to the chat completion response
*
* @throws {VeniceValidationError} If the request parameters are invalid
* @throws {VeniceApiError} If the API returns an error
* @throws {VeniceNetworkError} If there's a network issue
* @throws {VeniceTimeoutError} If the request times out
*/
createCompletion(request: ChatCompletionRequest): Promise<ChatCompletionResponse>;
}
/**
* API endpoint for streaming chat completions.
*
* This endpoint allows you to create streaming chat completions using various models.
* It returns an async generator that yields completion chunks as they become available.
*
* @example
* ```typescript
* const stream = venice.chatStream.streamCompletion({
* model: 'llama-3.3-70b',
* messages: [
* { role: 'system', content: 'You are a helpful assistant.' },
* { role: 'user', content: 'Write a short poem about AI.' }
* ]
* });
*
* // Process the stream chunks as they arrive
* for await (const chunk of stream) {
* const content = chunk.choices[0]?.delta?.content || '';
* process.stdout.write(content);
* }
* ```
*/
declare class ChatStreamEndpoint extends ApiEndpoint {
/**
* The chat validator for validating request parameters.
*/
private validator;
/**
* Creates a new ChatStreamEndpoint instance.
*
* @param client - The Venice client instance
*/
constructor(client: any);
/**
* Gets the base endpoint path for chat requests.
*
* @returns The endpoint path ('/chat')
*/
getEndpointPath(): string;
/**
* Streams a chat completion using the specified model.
*
* This method returns an async generator that yields completion chunks
* as they become available from the API. The request will automatically
* have `stream: true` set regardless of what's provided in the request.
*
* @param request - The chat completion request parameters
* @param request.model - The model to use (e.g., 'llama-3.3-70b')
* @param request.messages - The conversation messages array
* @param request.temperature - Controls randomness (0-1, default: 0.7)
* @param request.max_tokens - Maximum tokens to generate (default: varies by model)
* @param request.top_p - Controls diversity via nucleus sampling (0-1, default: 1)
* @param request.frequency_penalty - Penalizes repeated tokens (-2 to 2, default: 0)
* @param request.presence_penalty - Penalizes repeated topics (-2 to 2, default: 0)
* @param request.stop - Array of sequences where the model should stop generating
*
* @returns An async generator that yields completion chunks
*
* @throws {VeniceValidationError} If the request parameters are invalid
* @throws {VeniceApiError} If the API returns an error
* @throws {VeniceNetworkError} If there's a network issue
* @throws {VeniceTimeoutError} If the request times out
* @throws {VeniceStreamError} If there's an error processing the stream
*/
streamCompletion(request: ChatCompletionRequest): AsyncGenerator<any, void, unknown>;
}
/**
* API endpoint for models.
*/
declare class ModelsE