call-ai
Version:
Lightweight library for making AI API calls with streaming support
37 lines (36 loc) • 1.32 kB
TypeScript
import { Falsy, Mocks } from "./types.js";
import { type CallAIEnv } from "./env.js";
export interface EnvLike {
readonly CALLAI_API_KEY?: unknown;
readonly CALLAI_REFRESH_ENDPOINT?: unknown;
readonly CALL_AI_REFRESH_TOKEN?: unknown;
readonly CALLAI_DEBUG?: unknown;
}
export interface KeyMetadata {
key: string;
hash: string;
created: Date;
expires: Date;
remaining: number;
limit: number;
}
export declare function keyStore(): {
current: string | undefined;
refreshEndpoint: string;
refreshToken: string | 0 | false | null | undefined;
isRefreshing: boolean;
lastRefreshAttempt: number;
metadata: Record<string, Partial<KeyMetadata>>;
};
declare let globalDebug: boolean;
declare function initKeyStore(env?: CallAIEnv | EnvLike): void;
declare function isNewKeyError(ierror: unknown, debug?: boolean): boolean;
declare function refreshApiKey(options: {
mock?: Mocks;
}, currentKey: string | Falsy, endpoint: string | Falsy, refreshToken: string | Falsy, debug?: boolean): Promise<{
apiKey: string;
topup: boolean;
}>;
declare function getHashFromKey(key: string): string | null;
declare function storeKeyMetadata(data: KeyMetadata): void;
export { globalDebug, initKeyStore, isNewKeyError, refreshApiKey, getHashFromKey, storeKeyMetadata };