-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
Summary
The SDK currently lacks retry logic and rate limiting for API calls, which can lead to failures during network issues, temporary service unavailability, or when hitting API rate limits. This makes the SDK less reliable in production environments.
This affects user experience and reliability, especially for:
- File uploads that may fail due to temporary network issues
- API key generation and authentication requests
- Deal status checks
- Balance and usage queries
Proposed Solution
1. Implement Exponential Backoff Retry Logic
Add a utility function that wraps API calls with configurable retry logic:
interface RetryOptions {
maxRetries: number
baseDelay: number
maxDelay: number
retryCondition?: (error: any) => boolean
}
async function withRetry<T>(
operation: () => Promise<T>,
options: RetryOptions = {
maxRetries: 3,
baseDelay: 1000,
maxDelay: 10000
}
): Promise<T>
2. Rate Limiting Implementation
Implement a token bucket or sliding window rate limiter to prevent overwhelming the API:
class RateLimiter {
constructor(
private requestsPerSecond: number,
private burstSize: number
) {}
async waitForToken(): Promise<void>
}
3. Smart Retry Conditions
Only retry on specific conditions:
- Network errors (ECONNRESET, ETIMEDOUT, etc.)
- HTTP 429 (Too Many Requests)
- HTTP 502/503/504 (Server errors)
- Do NOT retry on 4xx client errors (except 429)
Metadata
Metadata
Assignees
Labels
No labels