fix(bedrock,vertex): map 413/529 to typed exceptions, matching canonical client#1544
Open
Zawwarsami16 wants to merge 1 commit into
Open
Conversation
…cal client The Bedrock and Vertex clients' `_make_status_error` methods were missing two status codes that the canonical `Anthropic` / `AsyncAnthropic` clients (and the newer Mantle client) already map: - 413 → `RequestTooLargeError` - 529 → `OverloadedError` For users running on Bedrock or Vertex, a 413 from the upstream API came back as the generic `APIStatusError` (no `RequestTooLargeError` handler ever fired), and a 529 "Overloaded" landed in the `>= 500` fall-through as `InternalServerError` — so retry/backoff code that keys off `OverloadedError` was silently broken on these platforms. Both 503 (Bedrock + Vertex) and 504 (Vertex only) are preserved. Adds parametrized parity tests covering every typed status code on both clients (11 cases on Bedrock, 12 on Vertex), modeled on the existing `test_make_status_error_sync_async_parity` in `tests/test_client.py`. All 23 new tests pass on both sync and async variants.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's happening
The Bedrock and Vertex clients'
_make_status_errormethods are missing two status codes that the canonicalAnthropic/AsyncAnthropicclients already map (and that the newer Mantle client also maps):RequestTooLargeErrorOverloadedErrorSo for users running on Bedrock or Vertex:
413from the upstream API comes back as a genericAPIStatusError— noRequestTooLargeErrorhandler ever fires.529"Overloaded" falls into the>= 500branch asInternalServerError— so retry / backoff code that keys offOverloadedErroris silently broken on these platforms.This is purely a drift bug — the canonical client added both mappings ages ago and the platform-specific clients didn't get the same update.
Comparison
_client.pylib/bedrock/_client.py(before)lib/vertex/_client.py(before)lib/bedrock/_mantle.pyBold cells are what this PR adds.
What this PR does
Adds the missing
413and529mappings to bothlib/bedrock/_client.pyandlib/vertex/_client.py. The Bedrock-specific503and Vertex-specific503/504mappings are preserved — those are real platform-frontend statuses and removing them would be a breaking change for users who catch them specifically.Tests
Modeled on the existing
test_make_status_error_sync_async_parityintests/test_client.py, this PR adds parametrized tests that pin the full status-code mapping for both platforms — both sync and async variants:tests/lib/test_bedrock.py::test_bedrock_make_status_error_maps_codes_to_typed_exceptions— 11 status codestests/lib/test_vertex.py::test_vertex_make_status_error_maps_codes_to_typed_exceptions— 12 status codesThe parametrized form will fail loudly the next time someone forgets to add a mapping in just one of the three places.