BerriAI/litellm · error · OCIError

Failed to parse OCI embed response as JSON: {e}

Error message

Failed to parse OCI embed response as JSON: {e}

What it means

The OCI embedding adapter expects the endpoint to return JSON (it calls `raw_response.json()` inside transform_embedding_response). If the body cannot be parsed as JSON — even with a 200 status — this error wraps the parse exception and includes it in the message, preserving the upstream status code.

Source

Thrown at litellm/llms/oci/embed/transformation.py:268

        model: str,
        raw_response: httpx.Response,
        model_response: EmbeddingResponse,
        logging_obj: LiteLLMLoggingObj,
        api_key: str | None,
        request_data: dict,
        optional_params: dict,
        litellm_params: dict,
    ) -> EmbeddingResponse:
        if raw_response.status_code != 200:
            raise OCIError(
                status_code=raw_response.status_code,
                message=raw_response.text,
            )

        try:
            json_response: Final = raw_response.json()
        except Exception as e:
            raise OCIError(
                status_code=raw_response.status_code,
                message=f"Failed to parse OCI embed response as JSON: {e}",
            )

        try:
            parsed: Final = OCIEmbedResponse(**json_response)
        except Exception as e:
            raise OCIError(
                status_code=500,
                message=f"OCI embed response does not match expected schema: {e}",
            )

        model_response.model = parsed.modelId
        model_response.data = [
            {
                "object": "embedding",
                "index": i,
                "embedding": embedding,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Verify the api_base URL points to the OCI generative-ai endpoint (https://inference.generativeai.<region>.oci.oraclecloud.com/...).
  2. Reproduce the request with curl to inspect what body is actually returned; if it is a proxy login/block page, fix proxy or network config.
  3. If the body is empty intermittently, check for connection resets and retry.
Defensive patterns

Strategy: try-catch

Try / catch

try:
    resp = litellm.embedding(model="oci/...", input=texts)
except Exception as e:
    if "Failed to parse OCI embed response as JSON" in str(e):
        # body wasn't JSON: likely proxy/gateway or wrong api_base
        log_raw_probe(api_base)
        raise

Prevention

When it happens

Trigger: The endpoint returns HTML (auth proxy login page, WAF block page), an empty body, a truncated stream, or plain-text error text with Content-Type confusion. Typically happens when api_base points at a gateway/proxy rather than the real OCI generative-ai service.

Common situations: Corporate proxies or API gateways (Kong, nginx, Cloudflare) intercepting the request and returning HTML; a wrong api_base that hits a generic web server; or a middlebox closing the connection mid-body.

Understand the failure class

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/62bb88a8fc2f065b. Report an issue: GitHub.