Here's a feature request draft for adding a requests per minute limiter to the Roo-Cline project:
Feature Request: Requests Per Minute (RPM) Limiter
Summary
Add a feature to the Roo-Cline extension that limits API requests to a configurable number of requests per minute (RPM) to help reduce API errors caused by exceeding rate limits.
Problem Statement
When using certain API providers (e.g., Anthropic, OpenRouter, Google Gemini, Bedrock, etc.), users may encounter API errors due to exceeding the provider's rate limits. These errors disrupt the workflow and can result in incomplete tasks, especially during tasks involving multiple API calls. A built-in requests per minute limiter would allow the extension to throttle requests proactively, avoiding such errors.
Proposed Solution
Introduce an RPM Limiter in the Roo-Cline extension that:
- Allows users to define a maximum number of API requests per minute for each provider.
- Queues and schedules requests when the limit is exceeded, ensuring the rate limit is respected.
- Provides feedback in the UI to indicate when requests are being throttled, showing the time remaining until the next request can be sent.
- Logs RPM-related information (e.g., throttling events) in the extension's output for debugging purposes.
Key Features
-
Global and Provider-Specific Limits:
- Allow users to configure a global RPM limit in settings.
- Optionally, allow provider-specific limits (e.g., Anthropic = 100 RPM, OpenRouter = 60 RPM).
-
UI Feedback:
- Notify users when throttling is active, e.g., "Throttling requests: X seconds until the next request."
- Include an indicator in the task progress UI or logs.
-
Queue Management:
- Automatically queue excess requests and execute them in order as the RPM window resets.
- Provide a cancellation option for queued requests.
-
Default Settings:
- Use provider-specific safe defaults based on their published rate limits (e.g., OpenRouter = 60 RPM, Gemini = 15 RPM for free-tier users).
Implementation Details
-
Configuration:
- Add a new section in the settings UI for "API Rate Limits" under each provider's configuration.
- Default to provider-specific rate limits for known APIs, with an option for users to override.
-
Throttling Logic:
- Implement a rate-limiting mechanism at the API handler level for each provider (e.g.,
AnthropicHandler, OpenRouterHandler, GeminiHandler, etc.).
- Use a timestamp-based approach to track the number of requests within the current minute and delay requests exceeding the limit.
-
UI and Feedback:
- Display throttling messages in the chat or extension logs.
- Optionally, show a countdown timer for queued requests in the UI.
Benefits
- Reduces API errors caused by exceeding rate limits, improving user experience and task reliability.
- Provides transparency and control over API usage for users with limited quotas.
- Aligns with the provider-specific rate-limiting guidelines, avoiding potential account suspensions or overage fees.
Potential Challenges
-
Handling Parallel Requests:
- Some tasks may require multiple parallel requests (e.g., fetching multiple files or resources). Ensure queued requests are handled efficiently without blocking other processes unnecessarily.
-
Dynamic Rate Limits:
- Some API providers offer dynamic rate limits based on user tiers or usage patterns. Provide flexibility for users to adjust limits accordingly.
-
Edge Cases:
- Handle edge cases like API retries due to transient errors without bypassing the RPM limiter.
References
[Redacted Person]
Settings UI:
[API Rate Limits]
- Global RPM Limit: [ 60 ]
- Provider-Specific Limits:
- Anthropic: [ 100 ]
- OpenRouter: [ 60 ]
- Gemini: [ 15 ]
- [Redacted Person]: [ 50 ]
Throttling Notification:
[Throttling Active] Waiting 15 seconds before sending the next request (60 requests per minute limit).
Related Areas in Code
- API Handlers: The rate-limiting logic should be implemented in the relevant API handlers:
src/api/providers/anthropic.ts
src/api/providers/openrouter.ts
src/api/providers/gemini.ts
src/api/providers/bedrock.ts
- Settings Configuration: Add RPM configuration options in:
webview-ui/src/components/settings/ApiOptions.tsx
- Shared Logic:
src/shared/api.ts for defining provider-specific defaults.
src/utils for implementing reusable rate-limiting logic.
Conclusion
An RPM limiter is a valuable addition to Roo-Cline, helping users avoid errors caused by exceeding API rate limits. With configurable limits, queuing, and UI feedback, it would enhance the stability and usability of the extension, especially for tasks requiring frequent API requests.
Would you like additional details or mockup examples for implementation?