refactor(proxy): take a read-only mapping for the model-id lookup

_get_model_id_from_response only reads its request payload, so a Mapping
says what it needs and the two metadata hops are narrowed instead of
assumed to be dicts.
This commit is contained in:
Yucheng He 2026-09-07 02:11:16 -07:00
parent 2e138511ed
commit 7ac5002f8d

View file

@ -2158,13 +2158,13 @@ class ProxyBaseLLMRequestProcessing:
return fallback_model_group
@staticmethod
def _get_model_id_from_response(hidden_params: Mapping[str, object], data: dict) -> str:
def _get_model_id_from_response(hidden_params: Mapping[str, object], data: Mapping[str, object]) -> str:
"""Extract model_id from hidden_params with fallback to litellm_metadata."""
model_id = hidden_params.get("model_id", None) or ""
if not model_id:
litellm_metadata: Final = data.get("litellm_metadata", {}) or {}
model_info: Final = litellm_metadata.get("model_info", {}) or {}
model_id = model_info.get("id", "") or ""
litellm_metadata: Final = data.get("litellm_metadata")
model_info: Final = litellm_metadata.get("model_info") if isinstance(litellm_metadata, Mapping) else None
model_id = (model_info.get("id") or "") if isinstance(model_info, Mapping) else ""
return str(model_id) if model_id else ""
def _stream_response_headers(