From 757f7991bfeac99eec95234d14cb8b2691f3fcf6 Mon Sep 17 00:00:00 2001 From: Abdel <62770500+hktitof@users.noreply.github.com> Date: Sun, 18 Oct 2026 19:13:11 +0000 Subject: [PATCH] fix(vertex_ai): guard the model cost map lookup with a pyright ignore the try/except form added a blind except that the strict ruff gate counts as BLE001, one over the merge-base. keep the membership check and suppress only the reportUnknownMemberType on the dynamically typed registry, the same pattern the complexity router already uses. ruff strict is identical to the base, ruff format and ruff check clean, focused vertex anthropic tests 42 passed --- .../vertex_ai_partner_models/anthropic/transformation.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/transformation.py b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/transformation.py index 77e4e31465d..fde1dd18752 100644 --- a/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/transformation.py +++ b/litellm/llms/vertex_ai/vertex_ai_partner_models/anthropic/transformation.py @@ -66,12 +66,11 @@ class VertexAIAnthropicConfig(AnthropicConfig): @staticmethod def get_max_tokens_for_model(model: str | None = None) -> int: if model is not None: - try: - vertex_max: Final = get_max_tokens(f"vertex_ai/{model}") + vertex_key: Final = f"vertex_ai/{model}" + if vertex_key in litellm.model_cost: # pyright: ignore[reportUnknownMemberType] # registry is dynamically typed + vertex_max: Final = get_max_tokens(vertex_key) if vertex_max is not None: return vertex_max - except Exception: - return AnthropicConfig.get_max_tokens_for_model(model) return AnthropicConfig.get_max_tokens_for_model(model) def _add_context_management_beta_headers(self, beta_set: set, context_management: dict) -> None: