From 7e6d0d7691ec55fdde440ec3f429c49e8dfaf37c Mon Sep 17 00:00:00 2001 From: akraines Date: Sun, 11 Jan 2026 00:23:45 +0200 Subject: [PATCH] fix: Support batch requests with comma-separated models in validate_model_access (#18909) This fixes a breaking change where batch completion requests with comma-separated model strings (e.g., 'gpt-3.5-turbo,fake-openai-endpoint') were failing validation. The validate_model_access function now: - Detects comma-separated model strings - Validates each model individually - Provides clear error messages for inaccessible models in batch requests - Maintains backward compatibility for single model validation Fixes test_batch_chat_completions test failure. --- litellm/proxy/utils.py | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index 171898b163..9ea2ea7d5c 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -4479,21 +4479,35 @@ def validate_model_access( ) -> None: """ Validate that a model is accessible to the user. + Supports batch requests with comma-separated model IDs. Args: - model_id: The model ID to validate + model_id: The model ID to validate (can be comma-separated for batch requests) available_models: List of models available to the user Raises: HTTPException: If the model is not accessible """ - if model_id not in available_models: - raise HTTPException( - status_code=404, - detail="The model `{}` does not exist or is not accessible".format( - model_id - ), - ) + # Handle batch requests with comma-separated models + if "," in model_id: + models = [m.strip() for m in model_id.split(",")] + inaccessible_models = [m for m in models if m not in available_models] + if inaccessible_models: + raise HTTPException( + status_code=404, + detail="The following model(s) do not exist or are not accessible: {}".format( + ", ".join(inaccessible_models) + ), + ) + else: + # Single model validation + if model_id not in available_models: + raise HTTPException( + status_code=404, + detail="The model `{}` does not exist or is not accessible".format( + model_id + ), + ) def _path_matches_pattern(path: str, pattern: str) -> bool: