/** * Provider Wrapper with Rate Limiting and Retry * * Wraps an LLMProvider with automatic rate limiting and retry functionality. */ import type { LLMProvider, Message, ChatOptions, StreamChunk } from '../providers/types.js'; import type { RateLimiter, RateLimitRetryConfig } from './types.js'; /** * Wrapper that adds rate limiting and retry to any LLMProvider * * @example * ```typescript * const provider = new ClaudeProvider({ apiKey: 'xxx' }); * const wrapped = new RateLimitedProvider(provider, { * rateLimit: { * requestsPerMinute: 60, * tokensPerMinute: 100000, * }, * retry: { * maxRetries: 3, * baseDelayMs: 1000, * }, * }); * * // Use wrapped provider like normal * const agent = new Agent({ provider: wrapped }); * ``` */ export declare class RateLimitedProvider implements LLMProvider { readonly name: string; private readonly provider; private readonly rateLimiter; private readonly retryConfig; constructor(provider: LLMProvider, config?: RateLimitRetryConfig); getModel(): string; setModel(modelId: string): void; /** * Get the rate limiter instance for statistics */ getRateLimiter(): RateLimiter; /** * Send messages with rate limiting and retry */ chat(messages: Message[], options?: ChatOptions): AsyncIterable; /** * Count tokens with rate limiting */ countTokens(messages: Message[]): Promise; /** * Estimate tokens from messages using tiktoken */ private estimateTokens; } /** * Create a rate-limited provider wrapper * * @param provider - The base LLM provider * @param config - Rate limit and retry configuration * @returns Wrapped provider with rate limiting and retry * * @example * ```typescript * const provider = createClaudeProvider(); * const rateLimited = wrapWithRateLimit(provider, { * rateLimit: { requestsPerMinute: 60 }, * retry: { maxRetries: 3 }, * }); * ``` */ export declare function wrapWithRateLimit(provider: LLMProvider, config?: RateLimitRetryConfig): RateLimitedProvider; /** * Default rate limits for known providers */ export declare const ProviderRateLimits: { /** * Anthropic Claude API limits (Tier 1) * @see https://docs.anthropic.com/en/api/rate-limits */ readonly claude: { readonly tier1: { readonly requestsPerMinute: 50; readonly tokensPerMinute: 40000; }; readonly tier2: { readonly requestsPerMinute: 1000; readonly tokensPerMinute: 80000; }; readonly tier3: { readonly requestsPerMinute: 2000; readonly tokensPerMinute: 160000; }; readonly tier4: { readonly requestsPerMinute: 4000; readonly tokensPerMinute: 400000; }; }; /** * OpenAI GPT-4 API limits (approximate) */ readonly openai: { readonly gpt4: { readonly requestsPerMinute: 500; readonly tokensPerMinute: 10000; }; readonly gpt4Turbo: { readonly requestsPerMinute: 500; readonly tokensPerMinute: 30000; }; readonly gpt35Turbo: { readonly requestsPerMinute: 3500; readonly tokensPerMinute: 90000; }; }; };