{"record":{"id":"c7dda0f1e2c96bed","repo":"BerriAI/litellm","slug":"api-base-not-set-for-litellm-proxy-route-set-in-e","errorCode":null,"errorMessage":"api_base not set for LiteLLM Proxy route. Set in env via `LITELLM_PROXY_API_BASE`","messagePattern":"api_base not set for LiteLLM Proxy route\\. Set in env via `LITELLM_PROXY_API_BASE`","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/litellm_proxy/chat/transformation.py","lineNumber":48,"sourceCode":"        supported_openai_params: Final = self.get_supported_openai_params(model)\n        for param, value in non_default_params.items():\n            if param == \"thinking\":\n                optional_params.setdefault(\"extra_body\", {})[\"thinking\"] = value\n            elif param in supported_openai_params:\n                optional_params[param] = value\n        return optional_params\n\n    def _get_openai_compatible_provider_info(\n        self, api_base: str | None, api_key: str | None\n    ) -> tuple[str | None, str | None]:\n        api_base = api_base or get_secret_str(\"LITELLM_PROXY_API_BASE\")\n        dynamic_api_key: Final = api_key or get_secret_str(\"LITELLM_PROXY_API_KEY\")\n        return api_base, dynamic_api_key\n\n    def get_models(self, api_key: str | None = None, api_base: str | None = None) -> list[str]:\n        api_base, api_key = self._get_openai_compatible_provider_info(api_base, api_key)\n        if api_base is None:\n            raise ValueError(\"api_base not set for LiteLLM Proxy route. Set in env via `LITELLM_PROXY_API_BASE`\")\n        models: Final = super().get_models(api_key=api_key, api_base=api_base)\n        return [f\"litellm_proxy/{model}\" for model in models]\n\n    @staticmethod\n    def get_api_key(api_key: str | None = None) -> str | None:\n        return api_key or get_secret_str(\"LITELLM_PROXY_API_KEY\")\n\n    @staticmethod\n    def _should_use_litellm_proxy_by_default(\n        litellm_params: LiteLLM_Params | None = None,\n    ):\n        \"\"\"\n        Returns True if litellm proxy should be used by default for a given request\n\n        Issue: https://github.com/BerriAI/litellm/issues/10559\n\n        Use case:\n        - When using Google ADK, users want a flag to dynamically enable sending the request to litellm proxy or not","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/litellm_proxy/chat/transformation.py#L30-L66","documentation":"When listing models from a downstream LiteLLM Proxy (to populate a client-side model list), the provider resolves api_base from the argument or LITELLM_PROXY_API_BASE. If both are unset, get_models raises ValueError because there is no default proxy address to query {api_base}/models.","triggerScenarios":"Chaining LiteLLM instances (proxy-to-proxy) and calling get_models for the litellm_proxy provider without api_base or LITELLM_PROXY_API_BASE; env var not propagated to the pod querying the upstream proxy.","commonSituations":"Multi-hop setups (SDK → proxy A → proxy B) where proxy A lacks LITELLM_PROXY_API_BASE; variable misspelled; env set at build time but not runtime.","solutions":["Set LITELLM_PROXY_API_BASE to the upstream proxy's base URL (e.g. http://proxy-b:4000)","Or pass api_base explicitly to get_models / the model entry's litellm_params","Also set LITELLM_PROXY_API_KEY for authentication against the upstream proxy"],"exampleFix":"# before\nmodels = provider.get_models(api_key=\"sk-upstream\")\n\n# after\nimport os\nos.environ[\"LITELLM_PROXY_API_BASE\"] = \"http://proxy-b:4000\"\nos.environ[\"LITELLM_PROXY_API_KEY\"] = \"sk-upstream\"\nmodels = provider.get_models()","handlingStrategy":"validation","validationCode":"import os\n\ndef ensure_litellm_proxy_base() -> str:\n    base = os.getenv(\"LITELLM_PROXY_API_BASE\")\n    if not base:\n        raise ValueError(\"LITELLM_PROXY_API_BASE not configured; cannot list upstream proxy models\")\n    return base.rstrip(\"/\")","typeGuard":null,"tryCatchPattern":"try:\n    models = provider.get_models()\nexcept ValueError as e:\n    if \"api_base not set for LiteLLM Proxy\" in str(e):\n        raise RuntimeError(\"Proxy chaining misconfigured: missing upstream LITELLM_PROXY_API_BASE\") from e","preventionTips":["In proxy-to-proxy setups, configure LITELLM_PROXY_API_BASE and LITELLM_PROXY_API_KEY as a pair","Smoke-test {base}/models with the upstream key after any networking change","Assert required env vars at process start rather than failing lazily on first model listing"],"tags":["litellm-proxy","config","environment"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}