ruvnet / ruvnet/ruflo

[FEATURE REQUEST] Intelligent Rate Limiting System for Claude Flow

Open
#258 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
72.7k
Forks
8.6k
Avg merge
2d 23h
Merged PRs (30d)
83

Description

# [FEATURE REQUEST] Intelligent Rate Limiting System for Claude Flow

## Overview
Implement configurable rate limiting to respect Claude API usage limits and prevent 429/529 errors, particularly for users on lower-tier Claude API plans.

## Problem Statement
- **Rate Limiting**: Users on lower-tier Claude API plans (Tier 1: 50 requests/minute) quickly hit rate limits during intensive development sessions
- **HTTP 429/529 Errors**: Rate limit and service unavailable errors need proper handling and retry logic
- **Manual Tier Management**: Users need to manually configure limits based on their API plan

## Proposed Features

### 🚦 Intelligent Rate Limiting System

#### Key Features:
- **Configurable Delay**: Pause between API calls (default: disabled, configurable)
- **Manual Tier Configuration**: User-specified API tier limits (no auto-detection possible)
- **Simple Request Spacing**: Basic delay between consecutive requests
- **Error Handling**: Graceful handling of 429 (rate limit) and 529 (service unavailable) errors
- **Basic Usage Logging**: Log request timing for manual monitoring
- **Pricing Plan Detection**: Automated retrieval of current Claude pricing tiers

#### Configuration Options:
```json
{
"rateLimit": {
"enabled": false,
"delayBetweenRequests": 10000,
"maxRequestsPerMinute": null,
"retryDelayOnLimit": 60000,
"retryDelayOnUnavailable": 30000,
"maxRetries": 3,
"logRequests": false
}
}
```

#### Implementation Details:
- Add simple delay mechanism between Claude Code invocations
- Implement exponential backoff for 429/529 errors
- Log request timing to console/file when enabled
- CLI flags: `--rate-limit-delay`, `--enable-rate-limit`
- Include `get-claude-pricing.sh` script to fetch latest pricing from Anthropic website

#### Tier Limits (Manual Configuration):
Users must manually configure based on their known plan:
- **Tier 1**: 50 requests/minute, 40K tokens/minute, 100K tokens/day
- **Tier 2**: 1000 requests/minute, 80K tokens/minute, 300K tokens/day
- **Tier 3**: 2000 requests/minute, 160K tokens/minute, 1M tokens/day
- **Tier 4**: 4000 requests/minute, 320K tokens/minute, 2M tokens/day

## Technical Implementation

### Architecture Changes
1. **Rate Limiting Service**: Request throttling with exponential backoff
2. **Configuration System**: JSON-based feature management
3. **Pricing Detection**: Web scraping for current Claude pricing tiers

### New CLI Commands
```bash
# Rate limiting
./claude-flow config set rate-limit-delay 10000
./claude-flow config set enable-rate-limit true
./claude-flow pricing update # Fetch latest pricing
```

### New Scripts
- `scripts/get-claude-pricing.sh` - Fetch latest Claude pricing and limits

### Configuration Files
- `.claude-flow/config.json` - Main configuration (feature disabled by default)
- `.claude-flow/pricing-cache.json` - Cached pricing information

## Benefits

### For Lower-Tier Users:
- **Intelligent Rate Control**: Avoid API overages with smart throttling
- **Usage Monitoring**: Track API usage patterns and costs
- **Graceful Degradation**: Continue working despite rate limits

### For All Users:
- **Error Prevention**: Reduce 429/529 errors significantly
- **Cost Management**: Better control over API usage costs
- **Improved Reliability**: More stable development experience

## Implementation Timeline

**Estimated: 2-3 days with AI assistance**

- [ ] Basic delay mechanism between requests
- [ ] 429/529 error handling with exponential backoff
- [ ] Configuration system implementation
- [ ] `get-claude-pricing.sh` script
- [ ] CLI integration for rate limiting

## Testing Strategy

### Automated Testing
- Rate limiting logic with mock API responses
- Configuration validation and error handling
- Exponential backoff behavior
- optional: include https://github.com/dotnet/dev-proxy

### Manual Testing
- API rate limit simulation with various tiers
- Performance impact assessment

## Success Metrics
- **Rate Limiting**: 90% reduction in 429/529 errors for enabled users
- **User Experience**: Positive feedback from beta testers on lower-tier plans

## Get Claude Pricing Script

### `get-claude-pricing.sh`
```bash
#!/bin/bash
# Fetch latest Claude pricing from Anthropic website
# Output: pricing-cache.json with current tier limits
curl -s "https://www.anthropic.com/pricing" | \
grep -E "(Tier|requests|tokens)" | \
jq -r '.pricing' > .claude-flow/pricing-cache.json
```

## Limitations & Considerations

### What's NOT Possible:
- Real-time API usage monitoring (requires Anthropic API access)
- Automatic tier detection (no API endpoint available)

### What IS Achievable:
- Intelligent request throttling
- Cost-effective development for lower-tier users
- Reliable error handling and recovery

Contributor guide

Open the contributing guide

Research direction

Start by locating the existing Claude API invocation, configuration, and CLI entry points; the issue does not name their files. Review the proposed .claude-flow/config.json, scripts/get-claude-pricing.sh, and pricing-cache.json requirements, then map the requested throttling, retries, logging, and CLI behavior to existing tests. Done would require all listed implementation and testing items to work together.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell, typescript
Domain
api, backend, cli, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.