{"record":{"id":"4086ba7786322798","repo":"BerriAI/litellm","slug":"api-base-is-required-for-hosted-vllm-embeddings","errorCode":null,"errorMessage":"api_base is required for hosted_vllm embeddings","messagePattern":"api_base is required for hosted_vllm embeddings","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/hosted_vllm/embedding/transformation.py","lineNumber":82,"sourceCode":"        # Merge with existing headers (user's headers take priority)\n        return {**default_headers, **headers}\n\n    def get_complete_url(\n        self,\n        api_base: str | None,\n        api_key: str | None,\n        model: str,\n        optional_params: dict,\n        litellm_params: dict,\n        stream: bool | None = None,\n    ) -> str:\n        \"\"\"\n        Get the complete URL for Hosted VLLM Embedding API endpoint.\n        \"\"\"\n        if api_base is None:\n            api_base = get_secret_str(\"HOSTED_VLLM_API_BASE\")\n            if api_base is None:\n                raise ValueError(\"api_base is required for hosted_vllm embeddings\")\n\n        # Remove trailing slashes\n        api_base = api_base.rstrip(\"/\")\n\n        # Ensure the URL ends with /embeddings\n        if not api_base.endswith(\"/embeddings\"):\n            api_base = f\"{api_base}/embeddings\"\n\n        return api_base\n\n    def transform_embedding_request(\n        self,\n        model: str,\n        input: AllEmbeddingInputValues,\n        optional_params: dict,\n        headers: dict,\n    ) -> dict:\n        \"\"\"","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/hosted_vllm/embedding/transformation.py#L64-L100","documentation":"Raised by HostedVLLM EmbeddingConfig.get_complete_url when no api_base argument was given and the HOSTED_VLLM_API_BASE environment variable is unset. Hosted vLLM is self-hosted (each deployment has its own URL), so LiteLLM has no default endpoint for embeddings and refuses to proceed with a ValueError.","triggerScenarios":"Calling litellm.embedding(model='hosted_vllm/<model>', input=[...]) without api_base and without HOSTED_VLLM_API_BASE in the environment. Note chat calls to hosted_vllm have a separate resolution path; the embeddings handler only checks these two sources.","commonSituations":"Working chat calls (env var set for the chat path or passed there) while the embedding call omits api_base; new deploy of vLLM where the embeddings endpoint env var was not added to the service; docker/k8s config missing the variable in one of several containers.","solutions":["Pass api_base explicitly: litellm.embedding(model='hosted_vllm/<model>', input=[...], api_base='http://vllm-host:8000').","Or set export HOSTED_VLLM_API_BASE=http://vllm-host:8000 (trailing slashes are stripped; /embeddings is appended if missing).","Ensure your vLLM server is actually serving /embeddings (started with --task embed or with an embedding model loaded)."],"exampleFix":"# before\nlitellm.embedding(model='hosted_vllm/bge-large', input=['hello'])\n# raises ValueError: api_base is required for hosted_vllm embeddings\n\n# after\nlitellm.embedding(\n    model='hosted_vllm/bge-large',\n    input=['hello'],\n    api_base='http://localhost:8000',  # /embeddings appended automatically\n)\n","handlingStrategy":"validation","validationCode":"import os\n\ndef vllm_embed_base(api_base: str | None = None) -> str:\n    base = api_base or os.environ.get(\"HOSTED_VLLM_API_BASE\")\n    if not base:\n        raise ValueError(\"api_base or HOSTED_VLLM_API_BASE required for hosted_vllm embeddings\")\n    return base","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set HOSTED_VLLM_API_BASE once per environment (it also covers chat/responses handlers).","Smoke-test embeddings after any vLLM redeploy: a 1-token embedding call catches missing base URLs and unloaded models early."],"tags":["hosted-vllm","embeddings","api-base","configuration","env-vars"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}