Skip to content

fix(models): standardize Anthropic API error handling in AnthropicLlm#5511

Open
sebastienc wants to merge 1 commit intogoogle:mainfrom
sebastienc:feat/anthropic-error-handling
Open

fix(models): standardize Anthropic API error handling in AnthropicLlm#5511
sebastienc wants to merge 1 commit intogoogle:mainfrom
sebastienc:feat/anthropic-error-handling

Conversation

@sebastienc
Copy link
Copy Markdown

Summary

Fixes #5396

Disclaimer: I'm using Claude Code to generate the following text. I find the summary is better than what I would've wrote.

Standardizes how AnthropicLlm handles errors from the Anthropic API, bringing it in line with the error handling pattern used elsewhere in ADK.

  • AnthropicRateLimitError — new exception class (subclasses Exception, not anthropic.RateLimitError) raised when the API returns a 429; includes a helpful mitigation message pointing users toward rate limit remediation options; original error is chained via from e so the full traceback is preserved
  • generate_content_async — wraps the non-streaming messages.create call in a try/except anthropic.RateLimitError block and re-raises as AnthropicRateLimitError
  • _generate_content_streaming — same wrapping around the streaming messages.create call; all other anthropic exceptions propagate unchanged

Testing plan

4 new tests added to tests/unittests/models/test_anthropic_llm.py. Full suite: 63 passed.

tests/unittests/models/test_anthropic_llm.py::test_non_streaming_rate_limit_raises_anthropic_rate_limit_error PASSED
tests/unittests/models/test_anthropic_llm.py::test_streaming_rate_limit_raises_anthropic_rate_limit_error PASSED
tests/unittests/models/test_anthropic_llm.py::test_non_streaming_other_errors_propagate PASSED
tests/unittests/models/test_anthropic_llm.py::test_streaming_other_errors_propagate PASSED

@adk-bot adk-bot added the models [Component] Issues related to model support label Apr 28, 2026
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AnthropicLlm does not translate Anthropic API errors to ADK error codes

2 participants