Skip to content

Conversation

uedag5
Copy link

@uedag5 uedag5 commented Sep 20, 2025

This pull request enhances the rate-limiting and retry logic for API requests, specifically adding support for Cerebras API rate limits and improving test coverage for these scenarios. The main changes include introducing logic to handle the x-ratelimit-reset-tokens-minute header for Cerebras, adjusting how delays are calculated based on the API provider, and adding comprehensive unit tests to verify the new behavior.

Cerebras Rate Limiting Support:

  • Added a new function getCerebrasRateLimitDelayMs to extract delay values from the x-ratelimit-reset-tokens-minute header, including proper handling of floating point and invalid values.
  • Updated the delay calculation logic in getDelayDurationAndStatus to use Cerebras-specific headers when the API base URL matches Cerebras, falling back to standard Retry-After headers for other providers.

Unit Test Improvements:

  • Added a new test suite for Cerebras rate limiting in retry.test.ts, covering scenarios for correct delay extraction, fallback behavior, and edge cases with invalid or missing headers.

Minor Test Cleanups:

  • Removed unnecessary eslint-disable comments for promise rejection assertions in retry.test.ts for improved code clarity. [1] [2] [3] [4]
  • Updated import statements to include HttpError directly from retry.js for consistency.

Cerebras APIの特別なレート制限ヘッダー「x-ratelimit-reset-tokens-minute」に対応し、適切な待機時間を計算する機能を実装

Cerebras固有のヘッダーを優先的に使用することで、より正確なレート制限処理を実現(従来のRetry-Afterヘッダーにも対応)

包括的なテストケースを追加し、浮動小数点値の処理、無効な値の処理、非Cerebras APIでの既存動作の維持を確認
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant