Skip to content

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

Open
MukundaKatta wants to merge 2 commits intogoogle:mainfrom
MukundaKatta:codex/adk-anthropic-rate-limit
Open

fix(models): wrap Anthropic rate limit errors#5401
MukundaKatta wants to merge 2 commits intogoogle:mainfrom
MukundaKatta:codex/adk-anthropic-rate-limit

Conversation

@MukundaKatta
Copy link
Copy Markdown

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] Issues related to model support label Apr 20, 2026
@adk-bot
Copy link
Copy Markdown
Collaborator

adk-bot commented Apr 20, 2026

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
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
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
Copy link
Copy Markdown
Collaborator

rohityan commented May 8, 2026

Hi @Jacksunwei , can you please review this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

models [Component] Issues 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.

3 participants