{"record":{"id":"00079442ffb90205","repo":"BerriAI/litellm","slug":"oci-compartment-id-is-required-for-oci-embedding-r","errorCode":null,"errorMessage":"oci_compartment_id is required for OCI embedding requests. Pass it as optional_params or set the OCI_COMPARTMENT_ID env var.","messagePattern":"oci_compartment_id is required for OCI embedding requests\\. Pass it as optional_params or set the OCI_COMPARTMENT_ID env var\\.","errorType":"exception","errorClass":"OCIError","httpStatus":400,"severity":"critical","filePath":"litellm/llms/oci/embed/transformation.py","lineNumber":185,"sourceCode":"            request_data=request_data,\n            api_base=api_base,\n            api_key=api_key,\n            model=model,\n            stream=stream,\n            fake_stream=fake_stream,\n        )\n\n    def transform_embedding_request(\n        self,\n        model: str,\n        input: AllEmbeddingInputValues,\n        optional_params: dict,\n        headers: dict,\n    ) -> dict:\n        creds: Final = resolve_oci_credentials(optional_params)\n        compartment_id: Final = creds[\"oci_compartment_id\"]\n        if not compartment_id:\n            raise OCIError(\n                status_code=400,\n                message=(\n                    \"oci_compartment_id is required for OCI embedding requests. \"\n                    \"Pass it as optional_params or set the OCI_COMPARTMENT_ID env var.\"\n                ),\n            )\n\n        # Normalise input to a flat list of strings\n        if isinstance(input, str):\n            texts = [input]\n        elif isinstance(input, list):\n            texts = []\n            for item in input:\n                if isinstance(item, list):\n                    raise OCIError(\n                        status_code=400,\n                        message=(\n                            \"OCI embedText does not support token-array inputs. \"","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/oci/embed/transformation.py#L167-L203","documentation":"OCIEmbeddingConfig.transform_embedding_request re-checks that oci_compartment_id resolved from optional_params or OCI_COMPARTMENT_ID is non-empty and raises OCIError(400) if not. OCI's embedding endpoint requires onboarding/serving requests to name a compartment, so the request cannot even be built without it.","triggerScenarios":"litellm.embedding with custom_llm_provider='oci' where OCI_COMPARTMENT_ID is unset/empty and no oci_compartment_id was passed; env var set in the shell but not in the deployed process; compartment id set only for the chat path.","commonSituations":"Reusing chat-credential setup for embeddings and forgetting the compartment; multi-tenant apps where the compartment should be selected per request; empty-string defaults from Helm/env templating.","solutions":["Set OCI_COMPARTMENT_ID to the compartment OCID where the embedding model is onboarded.","Or pass it per call: litellm.embedding(..., extra_body={'oci_compartment_id': ocid}).","Grab the OCID from OCI Console > Identity > Compartments (starts with ocid1.compartment.oc1.).","Validate presence at app startup rather than at request time."],"exampleFix":"# before\nlitellm.embedding(model=\"oci/generic.embedding.multilingual.v1.5\", input=texts)\n# OCIError 400: oci_compartment_id required\n\n# after\nos.environ[\"OCI_COMPARTMENT_ID\"] = \"ocid1.compartment.oc1..aaaa...\"\nlitellm.embedding(model=\"oci/generic.embedding.multilingual.v1.5\", input=texts)","handlingStrategy":"validation","validationCode":"import os\ncompartment = os.environ.get(\"OCI_COMPARTMENT_ID\", \"\")\nassert compartment.startswith(\"ocid1.compartment.\"), \\\n    f\"OCI_COMPARTMENT_ID must be a compartment OCID, got {compartment!r}\"","typeGuard":"def is_compartment_ocid(v: object) -> bool:\n    return isinstance(v, str) and v.startswith(\"ocid1.compartment.\")","tryCatchPattern":"from litellm.llms.oci.common_utils import OCIError\ntry:\n    litellm.embedding(model=\"oci/generic.embedding...\", input=texts)\nexcept OCIError as e:\n    if e.status_code == 400 and \"oci_compartment_id is required\" in str(e):\n        os.environ[\"OCI_COMPARTMENT_ID\"] = fetch_compartment_for_tenant()\n    raise","preventionTips":["Set OCI_COMPARTMENT_ID alongside the other OCI_* vars in every environment.","For multi-compartment apps, pass oci_compartment_id per request via extra params.","Validate the OCID format (ocid1.compartment....) at config load."],"tags":["oci","embeddings","compartment","configuration","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}