BerriAI/litellm · error · BedrockError

Error parsing response: {raw_response.text}, error: {e}

Error message

Error parsing response: {raw_response.text}, error: {e}

What it means

Raised in the TwelveLabs Pegasus transformation (Bedrock's twelvelabs embedding/video-understanding model family) when raw_response.json() fails, i.e. the HTTP body is not valid JSON. The BedrockError carries the raw body text and the parser exception, with the status code of the original HTTP response.

Source

Thrown at litellm/llms/bedrock/chat/invoke_transformations/amazon_twelvelabs_pegasus_transformation.py:210

        api_key: str | None = None,
        json_mode: bool | None = None,
    ) -> ModelResponse:
        """
        Transform TwelveLabs Pegasus response to LiteLLM format.

        TwelveLabs response format:
        {
            "message": "...",
            "finishReason": "stop" | "length"
        }

        LiteLLM format:
        ModelResponse with choices[0].message.content and finish_reason
        """
        try:
            completion_response: Final = raw_response.json()
        except Exception as e:
            raise BedrockError(
                message=f"Error parsing response: {raw_response.text}, error: {e}",
                status_code=raw_response.status_code,
            )

        verbose_logger.debug(
            "twelvelabs pegasus response: %s",
            json.dumps(completion_response, indent=4, default=str),
        )

        # Extract message content
        message_content: Final = completion_response.get("message", "")

        # Extract finish reason and map to LiteLLM format
        finish_reason_raw: Final = completion_response.get("finishReason", "stop")
        finish_reason: Final = map_finish_reason(finish_reason_raw)

        # Set the response content
        try:

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Read the raw_response.text embedded in the message - it shows the actual non-JSON body (proxy error page, XML auth error, etc.).
  2. If the body is an AWS/proxy error, fix the underlying auth or endpoint configuration rather than the call.
  3. Check the embedded status code: 5xx suggests retrying later; 4xx suggests config.
  4. Verify AWS_BEDROCK_RUNTIME_ENDPOINT is absent or correct if you did not intend to route through a custom endpoint.

Example fix

# before
resp = litellm.completion(model="bedrock/us.twelvelabs-pegasus-1-0", messages=msgs)

# after
from litellm.exceptions import BedrockError
try:
    resp = litellm.completion(model="bedrock/us.twelvelabs-pegasus-1-0", messages=msgs)
except BedrockError as e:
    if e.status_code >= 500:
        time.sleep(10)
        resp = litellm.completion(model="bedrock/us.twelvelabs-pegasus-1-0", messages=msgs)
    else:
        raise
Defensive patterns

Strategy: try-catch

Try / catch

from litellm.exceptions import BedrockError
try:
    resp = litellm.completion(model="bedrock/us.twelvelabs-pegasus-1-0", messages=msgs)
except BedrockError as e:
    if e.status_code >= 500:
        time.sleep(10)
        resp = litellm.completion(model="bedrock/us.twelvelabs-pegasus-1-0", messages=msgs)
    else:
        raise

Prevention

When it happens

Trigger: Calling bedrock/twelvelabs-pegasus models when the endpoint returns an HTML/XML error page (auth failure at a gateway, proxy error) or an empty body instead of the expected JSON completion payload.

Common situations: Corporate proxies or custom AWS_BEDROCK_RUNTIME_ENDPOINT setups returning non-JSON error pages, Bedrock service errors that emit plain-text bodies, or empty 5xx responses during AWS incidents.

Related errors


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