Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_decrease_anys_opus5_r4

mateo-berrif29fdee625c9
diff --cc litellm/llms/base_llm/guardrail_translation/utils.py
index a67ca9bffa8,8dee262001d..94a780f8148
--- a/litellm/llms/base_llm/guardrail_translation/utils.py
+++ b/litellm/llms/base_llm/guardrail_translation/utils.py
@@@ -2,8 -2,10 +2,10 @@@ from __future__ import annotation
import json
from collections.abc import Callable, Iterator, Sequence
-from typing import Any, Final, TypeVar
+from typing import Final, TypeVar
+ from pydantic import BaseModel
+
from litellm.types.llms.anthropic_messages.anthropic_response import AnthropicUsage
from litellm.types.llms.openai import AllMessageValues, ResponseAPIUsage
diff --cc litellm/proxy/vector_store_endpoints/management_endpoints.py
index 6c01ba2b300,c928398a87f..2a6a4c7dab8
--- a/litellm/proxy/vector_store_endpoints/management_endpoints.py
+++ b/litellm/proxy/vector_store_endpoints/management_endpoints.py
@@@ -64,30 -58,8 +58,8 @@@ _LITELLM_PARAMS_MASKER: Final = Sensiti
_REDACT_LITELLM_PARAMS_MAX_DEPTH: Final = 10
- # Use-time embedding-config resolution runs on every vector-store request
- # whose persisted row carries only a model reference (the post-fix shape).
- # Without a cache, that's one ``litellm_proxymodeltable.find_first`` per
- # request — the no-DB-in-critical-path rule. Hold the resolved config in
- # memory for a short TTL so a hot model name pays the DB lookup at most
- # once per ``_EMBEDDING_CONFIG_CACHE_TTL`` seconds. Cleartext credentials
- # only ever live in process memory (never persisted, never echoed in
- # management responses), so the cache doesn't widen the disclosure surface.
- _EMBEDDING_CONFIG_CACHE_TTL: Final = 60
- _EMBEDDING_CONFIG_CACHE_MAX_SIZE: Final = 256
- _embedding_config_cache: InMemoryCache | None = None
-
-
- def _get_embedding_config_cache() -> InMemoryCache:
- global _embedding_config_cache
- if _embedding_config_cache is None:
- _embedding_config_cache = InMemoryCache(
- max_size_in_memory=_EMBEDDING_CONFIG_CACHE_MAX_SIZE,
- default_ttl=_EMBEDDING_CONFIG_CACHE_TTL,
- )
- return _embedding_config_cache
-
-def _redact_sensitive_litellm_params(litellm_params: Any, _depth: int = 0) -> Any:
+def _redact_sensitive_litellm_params(litellm_params: object, _depth: int = 0) -> Any:
"""
Replace credential-bearing values in ``litellm_params`` with
``REDACTED_BY_LITELM`` while preserving non-secret keys (``api_base``,
diff --cc litellm/router_utils/fallback_event_handlers.py
index 2bcac84ec19,f7855cb38ff..4fa5590f3b7
--- a/litellm/router_utils/fallback_event_handlers.py
+++ b/litellm/router_utils/fallback_event_handlers.py
@@@ -264,13 -263,16 +263,16 @@@ def get_pre_routing_selection(kwargs: M
return next((selected for selected in selections if isinstance(selected, str) and selected), None)
-def fallback_lookup_groups(kwargs: Mapping[str, Any], model_group: str | None) -> tuple[str, ...]:
+def fallback_lookup_groups(kwargs: Mapping[str, object], model_group: str | None) -> tuple[str, ...]:
"""
Ordered keys for resolving a fallback chain: the tier a pre-routing hook selected wins,
- and the requested group still resolves when no tier-keyed chain exists, so configs keyed
- on the router name (the documented contract) keep working behind auto-routers.
+ then the routed group, then the requested group. The routed group differs when Claude Code
+ session affinity remaps a subagent's concrete model to its bound router.
"""
- ordered: Final = (get_pre_routing_selection(kwargs), model_group)
+ metadata: Final = kwargs.get(get_metadata_variable_name_from_kwargs(kwargs))
+ routed_group_value: Final = metadata.get("model_group") if isinstance(metadata, Mapping) else None
+ routed_group: Final = routed_group_value if isinstance(routed_group_value, str) else None
+ ordered: Final = (get_pre_routing_selection(kwargs), routed_group, model_group)
return tuple(dict.fromkeys(group for group in ordered if group))