BerriAI/litellm · error · ValueError

Failed to parse Volcengine response as JSON: {e}

Error message

Failed to parse Volcengine response as JSON: {e}

What it means

After the HTTP call to Volcengine's embedding endpoint returns, the handler does raw_response.json(). If the body is not valid JSON (HTML error page, empty body, proxy interception, auth redirect), this ValueError wraps the parse exception. Note the status code is not checked before parsing here, so non-2xx responses with non-JSON bodies land in this branch.

Source

Thrown at litellm/llms/volcengine/embedding/transformation.py:165

        return data

    def transform_embedding_response(
        self,
        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:
        """Transform Volcengine response to EmbeddingResponse"""
        try:
            response_json: Final = raw_response.json()
        except Exception as e:
            raise ValueError(f"Failed to parse Volcengine response as JSON: {e}")

        # Volcengine response format matches OpenAI format closely
        # Just need to ensure all required fields are present
        transformed_response: Final = {
            "object": "list",
            "data": response_json.get("data", []),
            "model": response_json.get("model", model),
            "usage": response_json.get("usage", {}),
        }

        # Add id if present
        if "id" in response_json:
            transformed_response["id"] = response_json["id"]

        # Create EmbeddingResponse from transformed data
        return EmbeddingResponse(**transformed_response)

    def validate_environment(

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Enable litellm.set_verbose = True or check logging to capture raw_response.text and see what the server actually returned.
  2. Verify the endpoint: it should resolve to https://ark.cn-beijing.volces.com/api/v3/embeddings or your custom base ending in /api/v3.
  3. Check api_key validity - expired Ark keys can produce non-JSON auth errors from gateways.
  4. Bypass/inspect proxies (HTTP_PROXY/HTTPS_PROXY) and confirm the raw response with curl.

Example fix

# before
resp = litellm.embedding(model="volcengine/ep-...", input=["hi"], api_base="https://ark.cn-beijing.volces.com")
# -> ValueError: Failed to parse Volcengine response as JSON ...

# after
resp = litellm.embedding(
    model="volcengine/ep-...",
    input=["hi"],
    api_base="https://ark.cn-beijing.volces.com/api/v3",  # correct base
)
Defensive patterns

Strategy: try-catch

Validate before calling

import socket
from urllib.parse import urlparse

def endpoint_looks_right(api_base: str | None) -> bool:
    base = api_base or "https://ark.cn-beijing.volces.com/api/v3"
    p = urlparse(base)
    return p.scheme in {"http", "https"} and p.netloc.endswith("volces.com")

# fast pre-flight only catches obviously wrong bases; non-JSON bodies still need try/catch

Try / catch

try:
    resp = litellm.embedding(model="volcengine/ep-...", input=inputs)
except ValueError as e:
    if "Failed to parse Volcengine response" in str(e):
        # log and retry once - proxies/WAFs often produce transient non-JSON bodies
        logging.warning("non-JSON Volcengine body: %s", e)
        resp = litellm.embedding(model="volcengine/ep-...", input=inputs)
    else:
        raise

Prevention

When it happens

Trigger: A corporate proxy or gateway returns an HTML block page; the Volcengine endpoint returns an XML/plain-text error (rate limit, WAF) instead of JSON; a wrong api_base pointing at a website; a truncated body from a dropped connection.

Common situations: Self-misconfigured api_base (e.g. missing /api/v3 so the server serves a landing page); Ark region endpoints changed; captive-portal/proxy environments; debugging with verbose logging disabled so the raw text is never seen.

Understand the failure class

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/c43f656d164e51af. Report an issue: GitHub.