{"record":{"id":"9e57e29c1ab93b8a","repo":"chroma-core/chroma","slug":"api-base-must-be-specified-for-azure-openai","errorCode":null,"errorMessage":"api_base must be specified for Azure OpenAI","messagePattern":"api_base must be specified for Azure OpenAI","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/openai_embedding_function.py","lineNumber":99,"sourceCode":"        client_params: Dict[str, Any] = {\"api_key\": self.api_key}\n\n        if self.organization_id is not None:\n            client_params[\"organization\"] = self.organization_id\n        if self.api_base is not None:\n            client_params[\"base_url\"] = self.api_base\n        if self.default_headers is not None:\n            client_params[\"default_headers\"] = self.default_headers\n\n        self.client = openai.OpenAI(**client_params)\n\n        # For Azure OpenAI\n        if self.api_type == \"azure\":\n            if self.api_version is None:\n                raise ValueError(\"api_version must be specified for Azure OpenAI\")\n            if self.deployment_id is None:\n                raise ValueError(\"deployment_id must be specified for Azure OpenAI\")\n            if self.api_base is None:\n                raise ValueError(\"api_base must be specified for Azure OpenAI\")\n\n            from openai import AzureOpenAI\n\n            self.client = AzureOpenAI(\n                api_key=self.api_key,\n                api_version=self.api_version,\n                azure_endpoint=self.api_base,\n                azure_deployment=self.deployment_id,\n                default_headers=self.default_headers,\n            )\n\n    def __call__(self, input: Documents) -> Embeddings:\n        \"\"\"\n        Generate embeddings for the given documents.\n        Args:\n            input: Documents to generate embeddings for.\n        Returns:\n            Embeddings for the documents.","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/openai_embedding_function.py#L81-L117","documentation":"Third of the Azure validation checks in OpenAIEmbeddingFunction.__init__: with api_type=\"azure\", api_base must be provided. api_base becomes AzureOpenAI(azure_endpoint=...) — the HTTPS endpoint of your Azure OpenAI resource (e.g. https://<resource-name>.openai.azure.com). Without it the client has no endpoint to send requests to, so construction fails even though api_version and deployment_id may already be correct.","triggerScenarios":"OpenAIEmbeddingFunction(api_type=\"azure\", api_version=..., deployment_id=...) with api_base omitted. Also triggered when the endpoint is stored in a differently-named setting (e.g. AZURE_OPENAI_ENDPOINT vs OPENAI_API_BASE) and never forwarded to the constructor.","commonSituations":"Copying the endpoint from the wrong portal blade (keys/endpoints page) or pasting only the resource name; config-driven setups where the endpoint key exists in the YAML but is read into a variable that is never passed; migrating code that previously used openai.api_base for the public API.","solutions":["Pass the full resource endpoint: api_base=\"https://<your-resource-name>.openai.azure.com\" — find it in Azure Portal under your Azure OpenAI resource -> Keys and Endpoint.","Prefer loading from env: api_base=os.environ[\"AZURE_OPENAI_ENDPOINT\"] and set AZURE_OPENAI_ENDPOINT in your deployment secrets.","Include the scheme (https://) — a bare hostname or resource name is not a valid endpoint.","Keep all three Azure values (api_base, api_version, deployment_id) in one config object so they are passed together."],"exampleFix":"// before\nazure_ef = OpenAIEmbeddingFunction(\n    api_type=\"azure\", api_version=\"2024-02-01\",\n    deployment_id=\"my-embed-deployment\",\n)  # ValueError: api_base must be specified for Azure OpenAI\n\n# after\nazure_ef = OpenAIEmbeddingFunction(\n    api_type=\"azure\", api_version=\"2024-02-01\",\n    deployment_id=\"my-embed-deployment\",\n    api_base=os.environ[\"AZURE_OPENAI_ENDPOINT\"],  # https://myresource.openai.azure.com\n)","handlingStrategy":"validation","validationCode":"endpoint = os.getenv(\"AZURE_OPENAI_ENDPOINT\", \"\")\nif not endpoint.startswith(\"https://\") or not endpoint.endswith(\".openai.azure.com\"):\n    raise RuntimeError(\n        f\"AZURE_OPENAI_ENDPOINT must look like https://<resource>.openai.azure.com, got: {endpoint!r}\"\n    )","typeGuard":"def is_azure_endpoint(value: str) -> bool:\n    return value.startswith(\"https://\") and \".openai.azure.com\" in value","tryCatchPattern":"try:\n    azure_ef = OpenAIEmbeddingFunction(api_type=\"azure\", api_base=endpoint, api_version=v, deployment_id=d)\nexcept ValueError as e:\n    raise RuntimeError(f\"Azure embedding setup incomplete: {e}\") from e","preventionTips":["Copy the endpoint verbatim from Azure Portal -> Keys and Endpoint, including https://.","Store the endpoint in one canonical env var and derive api_base from it everywhere.","Add a smoke test that constructs the Azure EF during CI so config gaps surface before deploy."],"tags":["azure","openai","embedding","endpoint","configuration","chroma"],"backgroundTag":"azure-openai-missing-config","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}