From 0d25ab4096d7d464d2002ef994fd5ba168725b94 Mon Sep 17 00:00:00 2001 From: Maximilian Rink Date: Mon, 12 Oct 2026 20:20:39 +0200 Subject: [PATCH] fix: keep type-check delta stable after cache update --- .../llms/openrouter/image_edit/transformation.py | 12 ++++++------ litellm/llms/sagemaker/common_utils.py | 2 +- .../context_caching/vertex_ai_context_caching.py | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/litellm/llms/openrouter/image_edit/transformation.py b/litellm/llms/openrouter/image_edit/transformation.py index a73a2fe4192..393feefa75a 100644 --- a/litellm/llms/openrouter/image_edit/transformation.py +++ b/litellm/llms/openrouter/image_edit/transformation.py @@ -211,7 +211,7 @@ class OpenRouterImageEditConfig(BaseImageEditConfig): if img is None: continue mime_type = ImageEditRequestUtils.get_image_content_type(img) - image_bytes = self._read_image_bytes(img) + image_bytes = self._read_image_bytes(cast(FileTypes, img)) b64_data = base64.b64encode(image_bytes).decode("utf-8") content_parts.append( { @@ -372,13 +372,13 @@ class OpenRouterImageEditConfig(BaseImageEditConfig): input_image_tokens = prompt_tokens_details.get("image_tokens", 0) model_response.usage = ImageUsage( - input_tokens=prompt_tokens, + input_tokens=int(prompt_tokens), input_tokens_details=ImageUsageInputTokensDetails( - image_tokens=input_image_tokens, - text_tokens=prompt_tokens - input_image_tokens, + image_tokens=int(input_image_tokens), + text_tokens=int(prompt_tokens - input_image_tokens), ), - output_tokens=image_tokens, - total_tokens=total_tokens, + output_tokens=int(image_tokens), + total_tokens=int(total_tokens), ) cost: Final = usage_data.get("cost") diff --git a/litellm/llms/sagemaker/common_utils.py b/litellm/llms/sagemaker/common_utils.py index 14f0e3ead62..66531518888 100644 --- a/litellm/llms/sagemaker/common_utils.py +++ b/litellm/llms/sagemaker/common_utils.py @@ -254,7 +254,7 @@ class AWSEventStreamDecoder: ) return GChunk( - text=_text, + text=_text or "", index=_index, is_finished=is_finished, finish_reason=finish_reason, diff --git a/litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py b/litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py index f8939152326..3208a3e5180 100644 --- a/litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py +++ b/litellm/llms/vertex_ai/context_caching/vertex_ai_context_caching.py @@ -1,4 +1,4 @@ -from collections.abc import Sequence +from collections.abc import Mapping, Sequence from typing import ( Final, Literal, @@ -417,7 +417,7 @@ class ContextCachingEndpoints(VertexBase): "Content-Type": "application/json", } if isinstance(token, dict): - headers.update(token) + headers.update(cast(Mapping[str, str], token)) elif token is not None: headers["Authorization"] = f"Bearer {token}" if extra_headers is not None: @@ -471,7 +471,7 @@ class ContextCachingEndpoints(VertexBase): cached_content_request_body: Final = transform_openai_messages_to_gemini_context_caching( model=model, messages=cached_messages, - cache_key=generated_cache_key, + cache_key=generated_cache_key or "", custom_llm_provider=custom_llm_provider, vertex_project=vertex_project, vertex_location=vertex_location, @@ -496,7 +496,7 @@ class ContextCachingEndpoints(VertexBase): response: Final = client.post( url=url, headers=headers, - json=cached_content_request_body, + json=cast(dict[str, object], cached_content_request_body), ) response.raise_for_status() except httpx.HTTPStatusError as err: @@ -597,7 +597,7 @@ class ContextCachingEndpoints(VertexBase): "Content-Type": "application/json", } if isinstance(token, dict): - headers.update(token) + headers.update(cast(Mapping[str, str], token)) elif token is not None: headers["Authorization"] = f"Bearer {token}" if extra_headers is not None: @@ -648,7 +648,7 @@ class ContextCachingEndpoints(VertexBase): cached_content_request_body: Final = transform_openai_messages_to_gemini_context_caching( model=model, messages=cached_messages, - cache_key=generated_cache_key, + cache_key=generated_cache_key or "", custom_llm_provider=custom_llm_provider, vertex_project=vertex_project, vertex_location=vertex_location, @@ -673,7 +673,7 @@ class ContextCachingEndpoints(VertexBase): response: Final = await client.post( url=url, headers=headers, - json=cached_content_request_body, + json=cast(dict[str, object], cached_content_request_body), ) response.raise_for_status() except httpx.HTTPStatusError as err: