fix(proxy): resolve team wildcard credentials for vector store files

Team-scoped wildcard deployments like openai/* are indexed separately from
global router models, so vector store file requests failed with api_key=None
when a team also had other yaml/db models. Pass team_id into credential
lookup and consult team model indexes and pattern routers.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Shivam Rawat 2026-07-16 21:14:45 -07:00
parent b880ad3134
commit bea11ddedd
2 changed files with 22 additions and 3 deletions

View file

@ -227,6 +227,8 @@ async def _update_request_data_with_model_routing_hint(
model_hint = data.get("model") or user_controlled_model_hint
should_authorize_model_hint = isinstance(model_hint, str) and model_hint == user_controlled_model_hint
caller_team_id = getattr(user_api_key_dict, "team_id", None) if user_api_key_dict else None
should_route = False
credentials = None
if isinstance(model_hint, str) and "*" in model_hint:
@ -237,7 +239,9 @@ async def _update_request_data_with_model_routing_hint(
llm_router=llm_router,
user_api_key_dict=user_api_key_dict,
)
credentials = llm_router.get_deployment_credentials_with_provider(model_id=model_hint)
credentials = llm_router.get_deployment_credentials_with_provider(
model_id=model_hint, team_id=caller_team_id
)
should_route = credentials is not None
else:
if isinstance(model_hint, str) and should_authorize_model_hint:
@ -285,7 +289,7 @@ async def _update_request_data_with_model_routing_hint(
openai_credentials = None
for model_name in model_names_to_check:
credentials = llm_router.get_deployment_credentials_with_provider(model_id=model_name)
credentials = llm_router.get_deployment_credentials_with_provider(model_id=model_name, team_id=caller_team_id)
if credentials is None:
continue

View file

@ -8459,7 +8459,9 @@ class Router:
raise Exception("Model Name invalid - {}".format(type(model)))
return None
def get_deployment_credentials_with_provider(self, model_id: str) -> Optional[Dict[str, Any]]:
def get_deployment_credentials_with_provider(
self, model_id: str, team_id: Optional[str] = None
) -> Optional[Dict[str, Any]]:
"""
Get API credentials and provider info from a model name in model_list.
Useful for passthrough endpoints (files, batches, etc.) that need credentials.
@ -8469,6 +8471,9 @@ class Router:
Args:
model_id: Model ID or model name from model_list (e.g., "gpt-4o-litellm")
team_id: Optional team id of the caller. When set, team-scoped
deployments (indexed by team public model name, including team
wildcard models like "openai/*") are also considered.
Returns:
Dictionary containing api_key, api_base, custom_llm_provider, etc.
@ -8487,9 +8492,19 @@ class Router:
if deployment is None:
deployment = self.get_deployment_by_model_group_name(model_group_name=model_id)
# If not found, check team-scoped deployments (team public model names,
# e.g. team wildcard models like "openai/*", live in a separate index).
if deployment is None and team_id is not None:
team_indices = self.team_model_to_deployment_indices.get((team_id, model_id), [])
if team_indices:
team_model = self.model_list[team_indices[0]]
deployment = Deployment(**team_model) if isinstance(team_model, dict) else team_model
# If still not found, check for wildcard pattern matches
if deployment is None:
potential_wildcard_models = self.pattern_router.route(model_id) or []
if not potential_wildcard_models and team_id is not None and team_id in self.team_pattern_routers:
potential_wildcard_models = self.team_pattern_routers[team_id].route(model_id) or []
if potential_wildcard_models:
# Use the first matching wildcard deployment
deployment_dict = potential_wildcard_models[0]