{"record":{"id":"4f703dec48e82592","repo":"BerriAI/litellm","slug":"error-parsing-response-raw-response-text-error","errorCode":null,"errorMessage":"Error parsing response: {raw_response.text}, error: {e}","messagePattern":"Error parsing response: (.+?), error: (.+?)","errorType":"http","errorClass":"BedrockError","httpStatus":null,"severity":"error","filePath":"litellm/llms/bedrock/chat/invoke_transformations/amazon_twelvelabs_pegasus_transformation.py","lineNumber":210,"sourceCode":"        api_key: str | None = None,\n        json_mode: bool | None = None,\n    ) -> ModelResponse:\n        \"\"\"\n        Transform TwelveLabs Pegasus response to LiteLLM format.\n\n        TwelveLabs response format:\n        {\n            \"message\": \"...\",\n            \"finishReason\": \"stop\" | \"length\"\n        }\n\n        LiteLLM format:\n        ModelResponse with choices[0].message.content and finish_reason\n        \"\"\"\n        try:\n            completion_response: Final = raw_response.json()\n        except Exception as e:\n            raise BedrockError(\n                message=f\"Error parsing response: {raw_response.text}, error: {e}\",\n                status_code=raw_response.status_code,\n            )\n\n        verbose_logger.debug(\n            \"twelvelabs pegasus response: %s\",\n            json.dumps(completion_response, indent=4, default=str),\n        )\n\n        # Extract message content\n        message_content: Final = completion_response.get(\"message\", \"\")\n\n        # Extract finish reason and map to LiteLLM format\n        finish_reason_raw: Final = completion_response.get(\"finishReason\", \"stop\")\n        finish_reason: Final = map_finish_reason(finish_reason_raw)\n\n        # Set the response content\n        try:","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/bedrock/chat/invoke_transformations/amazon_twelvelabs_pegasus_transformation.py#L192-L228","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the raw_response.text embedded in the message - it shows the actual non-JSON body (proxy error page, XML auth error, etc.).","If the body is an AWS/proxy error, fix the underlying auth or endpoint configuration rather than the call.","Check the embedded status code: 5xx suggests retrying later; 4xx suggests config.","Verify AWS_BEDROCK_RUNTIME_ENDPOINT is absent or correct if you did not intend to route through a custom endpoint."],"exampleFix":"# before\nresp = litellm.completion(model=\"bedrock/us.twelvelabs-pegasus-1-0\", messages=msgs)\n\n# after\nfrom litellm.exceptions import BedrockError\ntry:\n    resp = litellm.completion(model=\"bedrock/us.twelvelabs-pegasus-1-0\", messages=msgs)\nexcept BedrockError as e:\n    if e.status_code >= 500:\n        time.sleep(10)\n        resp = litellm.completion(model=\"bedrock/us.twelvelabs-pegasus-1-0\", messages=msgs)\n    else:\n        raise","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from litellm.exceptions import BedrockError\ntry:\n    resp = litellm.completion(model=\"bedrock/us.twelvelabs-pegasus-1-0\", messages=msgs)\nexcept BedrockError as e:\n    if e.status_code >= 500:\n        time.sleep(10)\n        resp = litellm.completion(model=\"bedrock/us.twelvelabs-pegasus-1-0\", messages=msgs)\n    else:\n        raise","preventionTips":["Inspect the raw body in the message to distinguish proxy errors from AWS errors.","Do not route twelvelabs traffic through custom endpoints that emit HTML error pages.","Retry only on 5xx; non-JSON 4xx bodies indicate configuration problems."],"tags":["aws","bedrock","twelvelabs","json-parsing","http"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}