Vana SDK - v2.2.2
    Preparing search index...

    Interface ApiResponse<T>

    Response wrapper for API results providing consistent error handling.

    Standardizes API responses across the SDK, making it easy to handle both successful and failed requests. The generic type parameter T represents the expected data type for successful responses. Check the success flag before accessing data to ensure type safety.

    // Handling API responses
    async function fetchUserData(userId: string): Promise<User | null> {
    const response: ApiResponse<User> = await api.getUser(userId);

    if (response.success) {
    console.log('User fetched:', response.data.name);
    // Access metadata if available
    if (response.metadata?.cached) {
    console.log('Data was cached');
    }
    return response.data;
    } else {
    console.error('Failed to fetch user:', response.error);
    return null;
    }
    }

    // Type-safe error handling
    interface UserData {
    id: string;
    name: string;
    }

    const result: ApiResponse<UserData> = await api.call('/users/123');
    if (result.success) {
    // TypeScript knows result.data is UserData here
    console.log(result.data.name);
    }
    interface ApiResponse<T> {
        data: T;
        success: boolean;
        error?: string;
        metadata?: Record<string, unknown>;
    }

    Type Parameters

    • T
    Index

    Properties

    data: T

    Response data

    success: boolean

    Success status

    error?: string

    Error message if not successful

    metadata?: Record<string, unknown>

    Additional metadata