Skip to content

fix(models): wrap Anthropic rate limit errors - #5401

Closed
MukundaKatta wants to merge 2 commits into
google:mainfrom
MukundaKatta:codex/adk-anthropic-rate-limit
Closed

MukundaKatta wants to merge 2 commits into
google:mainfrom
MukundaKatta:codex/adk-anthropic-rate-limit

Conversation

@MukundaKatta

Copy link
Copy Markdown
Contributor

Summary

  • wrap Anthropic in a dedicated ADK exception with mitigation guidance
  • apply the wrapper consistently for both streaming and non-streaming Claude requests
  • add regression tests for both code paths

Testing

  • python3 -m py_compile src/google/adk/models/anthropic_llm.py tests/unittests/models/test_anthropic_llm.py
  • python3 -m pytest tests/unittests/models/test_anthropic_llm.py -k "wraps_anthropic_rate_limit_error" (fails in this environment because the pytest interpreter is missing the package during collection)

@adk-bot adk-bot added the models [Component] This issue is related to model support label Apr 20, 2026
@adk-bot

adk-bot commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator

Response from ADK Triaging Agent

Hello @MukundaKatta, thank you for your contribution!

To help us track and manage changes effectively, could you please associate this PR with a GitHub issue? If an issue doesn't exist yet, you can create one and link it.

This will help our reviewers better understand the context of your fix. Thanks!

@rohityan rohityan self-assigned this Apr 20, 2026
@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label Apr 20, 2026
@rohityan

Copy link
Copy Markdown
Collaborator

Hi @MukundaKatta , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing mypy-diff tests and formatting errors.

@MukundaKatta

Copy link
Copy Markdown
Contributor Author

@rohityan Fixed in a3de866:

  • # type: ignore[misc] on class _AnthropicRateLimitError(RateLimitError) (RateLimitError is typed Any from the anthropic package)
  • -> str annotation on __str__
  • Re-ran autoformat.sh (pyink + isort clean)

Thanks!

@rohityan

Copy link
Copy Markdown
Collaborator

Hi @MukundaKatta , can you resolve the conflicts as well.

@MukundaKatta
MukundaKatta force-pushed the codex/adk-anthropic-rate-limit branch from d95514d to 36b874f Compare April 28, 2026 02:07
@MukundaKatta

Copy link
Copy Markdown
Contributor Author

@rohityan rebased onto latest main. Same diff as before (_AnthropicRateLimitError wrapper + try/except in generate_content_async, plus the two regression tests using _make_rate_limit_error). New tests are appended at the end of the file since test_non_streaming_does_not_pass_stream_param is no longer the last test. Ready for another look.

@rohityan rohityan added needs review [Status] The PR/issue is awaiting review from the maintainer and removed request clarification [Status] The maintainer need clarification or more information from the author labels May 8, 2026
@rohityan
rohityan requested a review from Jacksunwei May 8, 2026 23:36
@rohityan

rohityan commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Hi @Jacksunwei , can you please review this.

@haranrk haranrk assigned haranrk and unassigned rohityan Jun 18, 2026
copybara-service Bot pushed a commit that referenced this pull request Jul 30, 2026
Merge #5401

## Summary
- wrap Anthropic RateLimitError in a dedicated ADK exception with mitigation guidance
- apply the wrapper consistently for both streaming and non-streaming Claude requests
- add regression tests for both code paths

## Testing
- python3 -m py_compile src/google/adk/models/anthropic_llm.py tests/unittests/models/test_anthropic_llm.py
- python3 -m pytest tests/unittests/models/test_anthropic_llm.py -k "wraps_anthropic_rate_limit_error" *(fails in this environment because the pytest interpreter is missing the  package during collection)*

Co-authored-by: George Weale <gweale@google.com>
COPYBARA_INTEGRATE_REVIEW=#5401 from MukundaKatta:codex/adk-anthropic-rate-limit e08c51b
PiperOrigin-RevId: 956692885
@adk-bot

adk-bot commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Thank you @MukundaKatta for your contribution! 🎉

Your changes have been successfully imported and merged via Copybara in commit cde301b.

Closing this PR as the changes are now in the main branch.

@adk-bot adk-bot added the merged [Status] This PR is merged label Jul 30, 2026
@adk-bot adk-bot closed this Jul 30, 2026
FrigaZzz pushed a commit to FrigaZzz/adk-python that referenced this pull request Aug 11, 2026
Merge google#5401

## Summary
- wrap Anthropic RateLimitError in a dedicated ADK exception with mitigation guidance
- apply the wrapper consistently for both streaming and non-streaming Claude requests
- add regression tests for both code paths

## Testing
- python3 -m py_compile src/google/adk/models/anthropic_llm.py tests/unittests/models/test_anthropic_llm.py
- python3 -m pytest tests/unittests/models/test_anthropic_llm.py -k "wraps_anthropic_rate_limit_error" *(fails in this environment because the pytest interpreter is missing the  package during collection)*

Co-authored-by: George Weale <gweale@google.com>
COPYBARA_INTEGRATE_REVIEW=google#5401 from MukundaKatta:codex/adk-anthropic-rate-limit e08c51b
PiperOrigin-RevId: 956692885
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged [Status] This PR is merged models [Component] This issue is related to model support needs review [Status] The PR/issue is awaiting review from the maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants