/** * Pure helpers for multi-API-key rotation within a single provider. * * Single key: many time-increasing retries (router owns the count). * Multiple keys: circular order from sticky start; 2 attempts per key. */ /** Max stored API keys per LLM provider (UI + save clamp). */ export declare const MAX_PROVIDER_KEYS = 10; /** Attempts per key when multiple keys are configured (initial + one retry). */ export declare const MULTI_KEY_ATTEMPTS = 2; /** * Circular attempt order of length `n` starting at `startIndex`. * Example: n=4, start=2 → [2, 3, 0, 1] */ export declare function buildKeyAttemptPlan(n: number, startIndex: number): number[]; /** * How many attempts the router should make for one key slot. * Single-key mode uses the router's MAX_RETRIES budget (passed in). * Multi-key mode is always MULTI_KEY_ATTEMPTS. */ export declare function attemptsPerKey(keyCount: number, singleKeyMaxAttempts: number): number; /** Auth failures: rotate to another key, but do not backoff-retry the same key. */ export declare function isAuthKeyError(error: unknown): boolean; /** * Per-key billing / balance / quota failures (e.g. HTTP 402 insufficient credits). * These will not recover on the same key mid-request — rotate immediately. */ export declare function isQuotaKeyError(error: unknown): boolean; /** * Failures that should move to the next key without sleeping on the same key * (auth revoked, empty wallet). Still try the rest of the circle. */ export declare function isImmediateKeySwitchError(error: unknown): boolean; /** Whether this error should rotate to the next API key (auth / capacity / transient). */ export declare function isKeyRotatableError(error: unknown, isRetriable: (e: unknown) => boolean): boolean; /** * Model/request errors that will not improve with another key for the same * model. Outer provider fallback may still apply for some statuses (e.g. 413). */ export declare function isKeyCircleStopError(error: unknown): boolean; export type ProviderKeyEventType = "using" | "retry" | "switch" | "endpoint" | "exhausted"; export interface ProviderKeyEvent { readonly type: ProviderKeyEventType; readonly provider: string; /** Last-4 style mask, e.g. `…ab12`. */ readonly maskedTail: string; readonly reason?: string | undefined; readonly waitMs?: number | undefined; readonly keyIndex?: number | undefined; readonly keyCount?: number | undefined; } export declare function formatKeyEventStatus(event: ProviderKeyEvent): string; export declare function isProviderFailureStatus(text: string): boolean;