mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-21 06:27:00 +00:00
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.
This commit is contained in:
+22
-8
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user