Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
957af30
fix(proxy): optionally surface public team model name in /v1/models
tushar8408 Jun 16, 2026
1a8e11a
fix(proxy): default team model listings to public names
ishaan-jaff Jun 16, 2026
01621d8
test(proxy): cover team model listing metadata
ishaan-jaff Jun 16, 2026
beae9ac
test(proxy): cover empty team listing deployments
ishaan-jaff Jun 16, 2026
09d4dc4
refactor(proxy): simplify team model listing translation
ishaan-jaff Jun 17, 2026
253e058
Merge remote-tracking branch 'upstream/litellm_internal_staging' into…
ishaan-jaff Jun 17, 2026
63df0d3
fix(proxy): resolve public team model name on GET /v1/models/{id}
ishaan-jaff Jun 17, 2026
0bb8166
test(proxy): cover public-name resolution on model retrieve
ishaan-jaff Jun 17, 2026
624734e
refactor(proxy): extract team model-name translation into TeamModelNa…
ishaan-jaff Jun 17, 2026
bb29245
refactor(proxy): use TeamModelNameTranslator in model_list and model_…
ishaan-jaff Jun 17, 2026
2354973
test(proxy): target TeamModelNameTranslator for model-name translation
ishaan-jaff Jun 17, 2026
75a5ec8
fix(proxy): type create_model_info_response return as dict[str, object]
ishaan-jaff Jun 17, 2026
74460f9
fix(proxy): keep internal routing key for team model listing metadata…
ishaan-jaff Jun 17, 2026
6fc4e3a
fix(proxy): build /v1/models metadata from internal key, show public id
ishaan-jaff Jun 17, 2026
801a158
test(proxy): cover team listing fallback metadata via internal key
ishaan-jaff Jun 17, 2026
1d3b830
fix(proxy): use builtin dict generics in create_model_info_response (…
ishaan-jaff Jun 17, 2026
c0bea8a
fix(proxy): scope /v1/models metadata lookup to the caller's models
mateo-berri Jun 17, 2026
1a85206
refactor(proxy): type model listing response with a TypedDict
mateo-berri Jun 17, 2026
f50d6c0
Merge branch 'litellm_internal_staging' of http://127.0.0.1:36717/git…
mateo-berri Jun 17, 2026
74cfb3b
fix(proxy): align /v1/models list and retrieve on first-occurrence dedup
cursoragent Jun 17, 2026
a6acc8b
fix(proxy): mirror /v1/models filters on retrieve
cursoragent Jun 17, 2026
135d8f2
fix(model_listing): skip team rows with empty team_public_model_name
cursoragent Jun 17, 2026
686a708
chore(proxy): sync dashboard types for model_info query params; use b…
mateo-berri Jun 17, 2026
69ed748
fix(proxy): retrieve echoes the listing's public id, not the request …
cursoragent Jun 17, 2026
11b70ac
test: avoid gstatic image url in image_url detail test
mateo-berri Jun 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
165 changes: 165 additions & 0 deletions litellm/proxy/common_utils/model_listing_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
"""Team-scoped (BYOK) model-name translation for the model listing endpoints.

`/v1/models`, `/models`, and `GET /v1/models/{id}` should surface the public
`team_public_model_name` rather than the internal routing key
`model_name_{team_id}_{uuid}`, consistent with `/v1/model/info`. The internal
key still routes regardless; this is a presentation-layer swap only and does not
touch access-group or auth semantics (see issue #28382). Operators can pin the
legacy internal names with `general_settings.use_team_public_model_name: false`.
"""

from __future__ import annotations

from collections.abc import Mapping
from typing import TYPE_CHECKING, cast

if TYPE_CHECKING:
from litellm.router import Router


class TeamModelNameTranslator:
"""Translates internal team routing keys to their public names for the model
listing/retrieve responses. Stateless; the live router and general_settings
are injected per call so the unit tests can drive it without globals.
"""

@staticmethod
def _internal_public_pair(model: object) -> tuple[str, str] | None:
"""`(internal_routing_key, public_name)` for a team-scoped row, else None."""
if not isinstance(model, dict):
return None
model_dict = cast(dict[str, object], model) # any-ok: checked
model_info_raw: object = model_dict.get("model_info")
if not isinstance(model_info_raw, Mapping):
return None
model_info = cast(Mapping[str, object], model_info_raw) # any-ok: checked
team_id = model_info.get("team_id")
team_public = model_info.get("team_public_model_name")
name = model_dict.get("model_name")
if (
isinstance(team_id, str)
and isinstance(team_public, str)
and isinstance(name, str)
and name.startswith(f"model_name_{team_id}_")
):
return name, team_public
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
return None

@staticmethod
def _is_enabled(general_settings: Mapping[str, object]) -> bool:
return general_settings.get("use_team_public_model_name", True) is not False

@staticmethod
def build_internal_to_public_map(
llm_router: "Router | None",
general_settings: Mapping[str, object],
) -> dict[str, str]:
"""Internal team routing key -> public `team_public_model_name`.

Empty when disabled via the legacy flag, the router is absent, or the
router model list is malformed.
"""
if llm_router is None or not TeamModelNameTranslator._is_enabled(
general_settings
):
return {}
router_model_list = llm_router.get_model_list()
if not isinstance(router_model_list, list):
return {}
return dict(
pair
for pair in (
TeamModelNameTranslator._internal_public_pair(model)
for model in router_model_list
)
if pair is not None
)

@staticmethod
def _response_to_lookup_map(
model_names: list[str],
internal_to_public: dict[str, str],
) -> dict[str, str]:
"""Map each public response id to the first internal lookup id seen in
`model_names`, preserving first-occurrence order. First-wins keeps list
and retrieve in agreement on which accessible deployment a shared public
id resolves to: a global iterated before a colliding team alias stays
the listed entry, and sibling team rows collapse to their first
occurrence.
"""
result: dict[str, str] = {}
for name in model_names:
result.setdefault(internal_to_public.get(name, name), name)
return result

@staticmethod
def listing_entries(
model_names: list[str],
llm_router: "Router | None",
general_settings: Mapping[str, object],
) -> list[tuple[str, str]]:
"""`(response_id, metadata_lookup_id)` for each listed model, de-duplicated
by response_id while preserving order.

For team-scoped rows `response_id` is the public name shown to the client,
while `metadata_lookup_id` stays the internal routing key so downstream
metadata/fallback lookups (keyed by the routing name) still resolve. The
lookup id is always one of `model_names` (the caller's accessible set), so
a public name shared across teams never resolves to another team's
internal key. Both ids are identical for unmapped names (globals,
access-group keys).
"""
internal_to_public = TeamModelNameTranslator.build_internal_to_public_map(
llm_router, general_settings
)
if not internal_to_public:
return [(name, name) for name in model_names]
return list(
TeamModelNameTranslator._response_to_lookup_map(
model_names, internal_to_public
).items()
)

@staticmethod
def translate_listing(
model_names: list[str],
llm_router: "Router | None",
general_settings: Mapping[str, object],
) -> list[str]:
"""Public-name view of `model_names` (the `response_id` of each listing
entry). Sibling deployments sharing a public name collapse to one entry
while preserving order; unmapped names pass through.
"""
return [
entry[0]
for entry in TeamModelNameTranslator.listing_entries(
model_names, llm_router, general_settings
)
]

@staticmethod
def resolve_public_name(
model_id: str,
available_models: list[str],
llm_router: "Router | None",
general_settings: Mapping[str, object],
) -> str:
"""Resolve a public team name back to the internal routing key the router
indexes by, so `GET /v1/models/{id}` accepts the name the listing returns.

Resolution is restricted to `available_models` (the caller's accessible
set) so colliding public names across teams never resolve across an access
boundary. Uses the same first-occurrence dedup as `listing_entries` so a
public id advertised by `/v1/models` resolves to the same internal
deployment that the listing's metadata was built from. Returns `model_id`
unchanged when it is not an accessible public team name (already-internal
names and globals pass through).
"""
internal_to_public = TeamModelNameTranslator.build_internal_to_public_map(
llm_router, general_settings
)
if not internal_to_public:
return model_id
return TeamModelNameTranslator._response_to_lookup_map(
available_models, internal_to_public
).get(model_id, model_id)
60 changes: 50 additions & 10 deletions litellm/proxy/proxy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import time
import traceback
import warnings
from collections.abc import Mapping
from datetime import datetime, timedelta, timezone
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -301,6 +302,7 @@ def generate_feedback_box():
get_config_file_contents_from_gcs,
get_file_contents_from_s3,
)
from litellm.proxy.common_utils.model_listing_utils import TeamModelNameTranslator
from litellm.proxy.common_utils.openai_endpoint_utils import (
remove_sensitive_info_from_deployment,
)
Expand Down Expand Up @@ -8376,6 +8378,8 @@ async def model_list(
"""
global llm_model_list, general_settings, llm_router, prisma_client, user_api_key_cache, proxy_logging_obj

settings = cast(dict[str, object], general_settings) # any-ok: legacy settings

from litellm.proxy.management_endpoints.common_utils import (
_user_has_admin_privileges,
)
Expand Down Expand Up @@ -8455,16 +8459,21 @@ async def model_list(
if hidden_names:
all_models = [m for m in all_models if m not in hidden_names]

# Build response data with all proxy models
# Surface the public team name by default; legacy internal keys via flag.
# The internal routing key drives the metadata/fallback lookup, while the
# public name is what the client sees as the model id.
model_data = []
for model in all_models:
for response_id, lookup_id in TeamModelNameTranslator.listing_entries(
all_models, llm_router, settings
):
model_info = create_model_info_response(
model_id=model,
model_id=lookup_id,
provider="openai",
include_metadata=include_metadata or False,
fallback_type=fallback_type,
llm_router=llm_router,
)
model_info["id"] = response_id
model_data.append(model_info)

return dict(
Expand Down Expand Up @@ -8492,16 +8501,21 @@ async def model_list(
if hidden_names:
all_models = [m for m in all_models if m not in hidden_names]

# Build response data
# Surface the public team name by default; legacy internal keys via flag.
# The internal routing key drives the metadata/fallback lookup, while the
# public name is what the client sees as the model id.
model_data = []
for model in all_models:
for response_id, lookup_id in TeamModelNameTranslator.listing_entries(
all_models, llm_router, settings
):
model_info = create_model_info_response(
model_id=model,
model_id=lookup_id,
provider="openai",
include_metadata=include_metadata or False,
fallback_type=fallback_type,
llm_router=llm_router,
)
model_info["id"] = response_id
model_data.append(model_info)

return dict(
Expand All @@ -8523,6 +8537,8 @@ async def model_list(
async def model_info(
model_id: str,
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
team_id: Optional[str] = None,
healthy_only: Optional[bool] = False,
):
"""
Retrieve information about a specific model accessible to your API key.
Expand All @@ -8532,38 +8548,62 @@ async def model_info(

Follows OpenAI API specification for individual model retrieval.
https://platform.openai.com/docs/api-reference/models/retrieve

Query parameters mirror `/v1/models` so the same caller context (team
scoping, health filtering, paused deployments) drives both endpoints; the
listing's public id must resolve to the same internal deployment here.
"""
global llm_model_list, general_settings, llm_router, prisma_client, user_api_key_cache, proxy_logging_obj

settings = cast(dict[str, object], general_settings) # any-ok: legacy settings

from litellm.proxy.utils import (
create_model_info_response,
get_available_models_for_user,
validate_model_access,
)

# Get available models for the user
all_models = await get_available_models_for_user(
user_api_key_dict=user_api_key_dict,
llm_router=llm_router,
general_settings=general_settings,
user_model=user_model,
prisma_client=prisma_client,
proxy_logging_obj=proxy_logging_obj,
team_id=None,
team_id=team_id,
include_model_access_groups=False,
only_model_access_groups=False,
return_wildcard_routes=False,
user_api_key_cache=user_api_key_cache,
)

# Mirror /v1/models' visibility filter so first-occurrence resolution
# cannot land on a deployment the listing had hidden.
blocked_names = (
llm_router.get_fully_blocked_model_names() if llm_router is not None else set()
)
unhealthy_names: Set[str] = set()
if healthy_only and llm_router is not None:
unhealthy_names = await llm_router.async_get_fully_unhealthy_model_names()
hidden_names = blocked_names | unhealthy_names
if hidden_names:
all_models = [m for m in all_models if m not in hidden_names]

resolved_model_id = TeamModelNameTranslator.resolve_public_name(
model_id=model_id,
available_models=all_models,
llm_router=llm_router,
general_settings=settings,
)
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

# Validate that the requested model is accessible
validate_model_access(model_id=model_id, available_models=all_models)
validate_model_access(model_id=resolved_model_id, available_models=all_models)
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved

# Get provider information from the router deployment
if llm_router is None:
raise HTTPException(status_code=500, detail="Router not initialized")

deployment = llm_router.get_deployment_by_model_group_name(model_id)
deployment = llm_router.get_deployment_by_model_group_name(resolved_model_id)
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
if deployment is None:
raise HTTPException(
status_code=404,
Expand Down
Loading
Loading