{"record":{"id":"7869a04dfd908c29","repo":"BerriAI/litellm","slug":"vllm-api-base-is-not-set-please-set-the-environme","errorCode":null,"errorMessage":"VLLM_API_BASE is not set. Please set the environment variable, to use VLLM's pass-through - `{LITELLM_API_BASE}/vllm/{endpoint}`.","messagePattern":"VLLM_API_BASE is not set\\. Please set the environment variable, to use VLLM's pass-through - `(.+?)/vllm/(.+?)`\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/vllm/common_utils.py","lineNumber":50,"sourceCode":"    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        messages: list[AllMessageValues],\n        optional_params: dict,\n        litellm_params: dict,\n        api_key: str | None = None,\n        api_base: str | None = None,\n    ) -> dict:\n        if api_key is not None:\n            headers[\"x-api-key\"] = api_key\n        return headers\n\n    @staticmethod\n    def get_api_base(api_base: str | None = None) -> str | None:\n        api_base = api_base or get_secret_str(\"VLLM_API_BASE\")\n        if api_base is None:\n            raise ValueError(\n                \"VLLM_API_BASE is not set. Please set the environment variable, to use VLLM's pass-through - `{LITELLM_API_BASE}/vllm/{endpoint}`.\"\n            )\n        return api_base\n\n    @staticmethod\n    def get_api_key(api_key: str | None = None) -> str | None:\n        return None\n\n    @staticmethod\n    def get_base_model(model: str) -> str | None:\n        return model\n\n    def get_models(self, api_key: str | None = None, api_base: str | None = None) -> list[str]:\n        api_base = VLLMModelInfo.get_api_base(api_base)\n        api_key = VLLMModelInfo.get_api_key(api_key)\n        endpoint: Final = \"/v1/models\"\n        if api_base is None or api_key is None:\n            raise ValueError(","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/vllm/common_utils.py#L32-L68","documentation":"Raised by VLLMModelInfo.get_api_base when neither the api_base argument nor the VLLM_API_BASE environment variable is set. LiteLLM's vLLM pass-through routes ({LITELLM_API_BASE}/vllm/{endpoint}) must proxy to a running vLLM OpenAI-compatible server, and its address has to come from one of those two places.","triggerScenarios":"Using the /vllm pass-through (e.g. /vllm/v1/chat/completions or /vllm/models) without exporting VLLM_API_BASE and without passing api_base in the request/client config.","commonSituations":"Fresh deployments missing the env var in docker-compose/k8s; CI runs that never set VLLM_API_BASE; env vars set in a different shell or dropped by systemd/supervisor; typo'd variable name (VLLM_API_URL).","solutions":["Export VLLM_API_BASE pointing at your vLLM server, e.g. export VLLM_API_BASE=http://localhost:8000","Or pass api_base explicitly in the litellm client/request (litellm.client or route config)","In containers, add the variable to the environment section and restart the proxy","Verify with: python -c \"import os; print(os.environ.get('VLLM_API_BASE'))\""],"exampleFix":"# before\n# nothing set -> ValueError on /vllm/* calls\n\n# after\nexport VLLM_API_BASE=http://localhost:8000\n\n# or per call\nclient.chat.completions.create(\n    model=\"vllm/meta-llama/Meta-Llama-3-8B-Instruct\",\n    messages=[...],\n    base_url=\"http://localhost:8000\",  # or api_base depending on client\n    api_key=\"none\",\n)","handlingStrategy":"validation","validationCode":"import os\n\nVLLM_URL = os.environ.get(\"VLLM_API_BASE\") or \"http://localhost:8000\"\n\nif not os.environ.get(\"VLLM_API_BASE\"):\n    raise ConfigError(\"Set VLLM_API_BASE before using the /vllm pass-through\")","typeGuard":"def has_vllm_api_base() -> bool:\n    import os\n    return bool(os.environ.get(\"VLLM_API_BASE\"))","tryCatchPattern":"try:\n    litellm.Router(model_list=[{\"model_name\": \"vllm/llama3\", \"litellm_params\": {\"model\": \"vllm/llama3\"}}])\nexcept ValueError as e:\n    if \"VLLM_API_BASE is not set\" in str(e):\n        os.environ[\"VLLM_API_BASE\"] = \"http://localhost:8000\"  # then retry once\n    else:\n        raise","preventionTips":["Fail fast at app startup: assert VLLM_API_BASE is present before serving /vllm routes","Declare the env var in docker-compose/k8s and CI settings","Prefer explicit api_base in client config over ambient env vars where possible"],"tags":["vllm","environment-variable","configuration","valueerror","litellm-proxy"],"backgroundTag":"missing-env-var","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}