Skip to content

[Feat] Add support for Batch API Rate limiting - PR1 adds support for input based rate limits - #16075

Merged
ishaan-jaff merged 13 commits into
mainfrom
litellm_batch_rate_limits
Oct 30, 2025
Merged

[Feat] Add support for Batch API Rate limiting - PR1 adds support for input based rate limits #16075
ishaan-jaff merged 13 commits into
mainfrom
litellm_batch_rate_limits

Conversation

@ishaan-jaff

@ishaan-jaff ishaan-jaff commented Oct 29, 2025

Copy link
Copy Markdown
Contributor

[Feat] Add support for Batch API Rate limiting - PR1 adds support for input based rate limits

This PR adds rate limiting for batch API requests (OpenAI/Azure) based on Tokens Per Minute (TPM) and Requests Per Minute (RPM). The implementation reads batch input files at submission time, counts tokens using tiktoken, and enforces the same rate limits as regular API requests.

Screenshot 2025-10-29 at 4 53 08 PM Screenshot 2025-10-29 at 4 52 17 PM

Key Changes

  • Batch Rate Limiter (litellm/proxy/hooks/batch_rate_limiter.py)
  • New _PROXY_BatchRateLimiter class that integrates with existing rate limiting infrastructure
  • Reads batch input files via litellm.afile_content() to count tokens and requests
  • Uses tiktoken for accurate token counting
  • Validates rate limits before accepting batch submissions
  • Returns 429 errors with detailed messages when limits are exceeded

Relevant issues

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🆕 New Feature
✅ Test

Changes

@vercel

vercel Bot commented Oct 29, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
litellm Ready Ready Preview Comment Oct 30, 2025 1:17am

@ishaan-jaff
ishaan-jaff merged commit aea78b8 into main Oct 30, 2025
31 of 53 checks passed
@ishaan-berri
ishaan-berri deleted the litellm_batch_rate_limits branch March 26, 2026 21:51
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
… input based rate limits (BerriAI#16075)

* add count_input_file_usage

* add count_input_file_usage

* fix count_input_file_usage

* _get_batch_job_input_file_usage

* fixes imports

* use _get_batch_job_input_file_usage

* test_batch_rate_limits

* add _check_and_increment_batch_counters

* add get_rate_limiter_for_call_type

* test_batch_rate_limit_multiple_requests

* fixes for batch limits

* fix linting

* fix MYPY linting
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