llm-credit-sdk
Version:
SDK for estimating and reconciling LLM token costs using a credit system.
100 lines • 3.8 kB
TypeScript
import { SDKConfig, EstimateCreditsInput, EstimateCreditsInputCustom, EstimateCreditsResult, ReconcileInput, ReconcileInputCustom, ReconcileResult, WrapCallInput, WrapCallInputCustom, WrapCallResult, DashboardSyncConfig } from './types';
/**
* LLM Credit SDK - Main class for token usage tracking and credit estimation
*/
export declare class LLMCreditSDK {
private config;
private eventEmitter;
private dashboardClient;
private dashboardSyncEnabled;
/**
* Initialize the SDK with optional custom configuration
* @param customConfig - Optional custom configuration to override defaults
*/
constructor(customConfig?: Partial<SDKConfig>);
/**
* Estimate credits for an LLM call before making it
* @param input - Parameters for credit estimation (supports both standard and custom models/features)
* @returns Estimated number of credits
*/
estimateCredits(input: EstimateCreditsInput | EstimateCreditsInputCustom): EstimateCreditsResult;
/**
* Reconcile estimated vs actual usage after an LLM call
* @param input - Parameters for reconciliation (supports both standard and custom models/features)
* @returns Reconciliation results with actual usage and delta
*/
reconcile(input: ReconcileInput | ReconcileInputCustom): ReconcileResult;
/**
* Wrap an LLM call with automatic credit estimation and reconciliation
* @param input - Parameters for the wrapped call (supports both standard and custom models/features)
* @returns Response from the LLM call plus reconciliation data
*/
wrapCall<T>(input: WrapCallInput<T> | WrapCallInputCustom<T>): Promise<WrapCallResult<T>>;
/**
* Get configuration for a specific model
* @param model - Model name (e.g., 'openai:gpt-4')
* @returns Model configuration
* @throws Error if model is not found
*/
private getModelConfig;
/**
* Get margin for a specific feature within a model
* @param modelConfig - Model configuration
* @param feature - Feature name
* @returns Margin multiplier
*/
private getMarginForFeature;
/**
* Deep merge two configuration objects
* @param defaultConfig - Default configuration
* @param customConfig - Custom configuration to merge
* @returns Merged configuration
*/
private mergeConfigs;
/**
* Get the current configuration (for debugging/inspection)
* @returns Current SDK configuration
*/
getConfig(): SDKConfig;
/**
* Get list of available models
* @returns Array of model names
*/
getAvailableModels(): string[];
/**
* Get list of available features for a specific model
* @param model - Model name
* @returns Array of feature names
*/
getAvailableFeatures(model: string): string[];
/**
* Get the current credit per dollar conversion rate
* @returns Credit per dollar rate
*/
getCreditPerDollar(): number;
/**
* Enable dashboard synchronization
* @param config - Dashboard sync configuration
*/
enableDashboardSync(config: DashboardSyncConfig): void;
/**
* Disable dashboard synchronization
*/
disableDashboardSync(): void;
/**
* Check if dashboard sync is enabled
* @returns True if dashboard sync is enabled
*/
isDashboardSyncEnabled(): boolean;
/**
* Get current dashboard configuration
* @returns Dashboard config if enabled, null otherwise
*/
getDashboardConfig(): DashboardSyncConfig | null;
/**
* Post reconciliation data to dashboard (if sync is enabled)
* This method is called internally but can also be used manually
*/
private postReconciliationToDashboard;
}
//# sourceMappingURL=sdk.d.ts.map