diff --git a/tests/entrypoints/openai/responses/test_errors.py b/tests/entrypoints/openai/responses/test_errors.py index 0ef9bb901a..e21f6aa2a4 100644 --- a/tests/entrypoints/openai/responses/test_errors.py +++ b/tests/entrypoints/openai/responses/test_errors.py @@ -6,7 +6,9 @@ from unittest.mock import MagicMock import pytest +import vllm.envs as envs from vllm.entrypoints.openai.engine.serving import GenerationError, OpenAIServing +from vllm.envs import disable_envs_cache @pytest.mark.asyncio @@ -60,3 +62,35 @@ async def test_convert_generation_error_to_streaming_response(): assert isinstance(error_json, str) assert "Internal server error" in error_json assert "InternalServerError" in error_json + + +def test_is_model_supported_skip_name_validation_env( + monkeypatch: pytest.MonkeyPatch, +) -> None: + """When VLLM_SKIP_MODEL_NAME_VALIDATION is set, accept any model id.""" + disable_envs_cache() + monkeypatch.delenv("VLLM_SKIP_MODEL_NAME_VALIDATION", raising=False) + + mock_engine = MagicMock() + mock_engine.model_config = MagicMock() + mock_engine.model_config.max_model_len = 100 + mock_models = MagicMock() + mock_models.is_base_model.return_value = False + + serving = OpenAIServing( + engine_client=mock_engine, + models=mock_models, + request_logger=None, + ) + + assert serving._is_model_supported("not-a-registered-model") is False + + monkeypatch.setenv("VLLM_SKIP_MODEL_NAME_VALIDATION", "1") + disable_envs_cache() + assert envs.VLLM_SKIP_MODEL_NAME_VALIDATION is True + assert serving._is_model_supported("not-a-registered-model") is True + + monkeypatch.setenv("VLLM_SKIP_MODEL_NAME_VALIDATION", "true") + disable_envs_cache() + assert envs.VLLM_SKIP_MODEL_NAME_VALIDATION is True + assert serving._is_model_supported("another-alias") is True diff --git a/vllm/entrypoints/openai/engine/serving.py b/vllm/entrypoints/openai/engine/serving.py index 77cce6bec5..5e4cc34828 100644 --- a/vllm/entrypoints/openai/engine/serving.py +++ b/vllm/entrypoints/openai/engine/serving.py @@ -755,6 +755,8 @@ class OpenAIServing: def _is_model_supported(self, model_name: str | None) -> bool: if not model_name: return True + if envs.VLLM_SKIP_MODEL_NAME_VALIDATION: + return True return self.models.is_base_model(model_name) diff --git a/vllm/envs.py b/vllm/envs.py index fa7a5fe70f..d55732cb6a 100755 --- a/vllm/envs.py +++ b/vllm/envs.py @@ -255,6 +255,10 @@ if TYPE_CHECKING: VLLM_LORA_DISABLE_PDL: bool = False VLLM_ENABLE_CUDA_COMPATIBILITY: bool = False VLLM_CUDA_COMPATIBILITY_PATH: str | None = None + VLLM_SKIP_MODEL_NAME_VALIDATION: bool = False + """If set, vLLM will skip model name validation in API requests. + This allows any model name to be accepted in the 'model' field of requests, + making the server model-name agnostic. Useful for proxy/gateway scenarios.""" VLLM_ELASTIC_EP_SCALE_UP_LAUNCH: bool = False VLLM_ELASTIC_EP_DRAIN_REQUESTS: bool = False VLLM_MEMORY_PROFILER_ESTIMATE_CUDAGRAPHS: bool = True @@ -1711,6 +1715,14 @@ environment_variables: dict[str, Callable[[], Any]] = { "VLLM_CUDA_COMPATIBILITY_PATH": lambda: os.environ.get( "VLLM_CUDA_COMPATIBILITY_PATH", None ), + # Skip model name validation in OpenAI API requests. + # When set to 1, any model name will be accepted in the 'model' field + # of API requests. This is useful for proxy/gateway scenarios where + # the actual model is served but different names may be used in requests. + "VLLM_SKIP_MODEL_NAME_VALIDATION": lambda: ( + os.getenv("VLLM_SKIP_MODEL_NAME_VALIDATION", "0").strip().lower() + in ("1", "true") + ), # Whether it is a scale up launch engine for elastic EP, # Should only be set by EngineCoreClient. "VLLM_ELASTIC_EP_SCALE_UP_LAUNCH": lambda: bool( @@ -1886,6 +1898,7 @@ def compile_factors() -> dict[str, object]: "VLLM_TEST_FORCE_LOAD_FORMAT", "VLLM_ENABLE_CUDA_COMPATIBILITY", "VLLM_CUDA_COMPATIBILITY_PATH", + "VLLM_SKIP_MODEL_NAME_VALIDATION", "LOCAL_RANK", "CUDA_VISIBLE_DEVICES", "NO_COLOR",