Skip to content

[Fix] Properly raise rate limit errors from Anthropic#722

Open
orthodoX wants to merge 2 commits into
crmne:mainfrom
orthodoX:properly-raise-rate-limit-errors-from-anthropic
Open

[Fix] Properly raise rate limit errors from Anthropic#722
orthodoX wants to merge 2 commits into
crmne:mainfrom
orthodoX:properly-raise-rate-limit-errors-from-anthropic

Conversation

@orthodoX
Copy link
Copy Markdown

@orthodoX orthodoX commented Apr 6, 2026

What this does

This fix should help to properly raise error messages like this one 👇🏻 as rate limit errors:

Screenshot 2026-04-06 at 15 42 17

Anthropic rate limit messages mention "input tokens per minute/hour/day", which matches the /input[_\s-]?token/i pattern in the Error class, and those get misinterpreted as ContextLengthExceededError. These are genuine rate limits, so we should check for rate limit language first and raise RateLimitError instead.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Required for new features

  • I opened an issue before writing code and received maintainer approval
  • Linked issue: #___

PRs for new features or enhancements without a prior approved issue will be closed.

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly
    • For provider changes: Re-recorded VCR cassettes with bundle exec rake vcr:record[provider_name]
    • All tests pass: bundle exec rspec
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

AI-generated code

  • I used AI tools to help write this code
  • I have reviewed and understand all generated code (required if above is checked)

API changes

  • Breaking change
  • New public methods/classes
  • Changed method signatures
  • No API changes

@orthodoX orthodoX changed the title Properly raise rate limit errors from Anthropic [Fix] Properly raise rate limit errors from Anthropic Apr 6, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.04%. Comparing base (4942d6c) to head (a8582e1).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #722      +/-   ##
==========================================
- Coverage   87.05%   87.04%   -0.02%     
==========================================
  Files         119      119              
  Lines        5594     5596       +2     
  Branches     1407     1408       +1     
==========================================
+ Hits         4870     4871       +1     
- Misses        724      725       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants