BerriAI/litellm · error · BedrockError

Error setting response content

Error message

Error setting response content: {e}. Response: {completion_response}

What it means

Assignment failure while writing the extracted message content into model_response.choices[0].message.content: the response object shape did not accept the content (missing message attribute or unexpected structure), surfacing both the error and the parsed response for diagnosis.

Solutions

  1. Inspect completion_response to see what the provider actually returned.
  2. Verify the request matches the Pegasus model's expected input format.
  3. Upgrade litellm if the response schema changed upstream.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at litellm/llms/bedrock/chat/invoke_transformations/amazon_twelvelabs_pegasus_transformation.py:239 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

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

        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:
            if (
                message_content
                and hasattr(model_response.choices[0], "message")
                and getattr(model_response.choices[0].message, "tool_calls", None) is None
            ):
                model_response.choices[0].message.content = message_content
                model_response.choices[0].finish_reason = finish_reason
            else:
                raise Exception("Unable to set message content")
        except Exception as e:
            raise BedrockError(
                message=f"Error setting response content: {e}. Response: {completion_response}",
                status_code=raw_response.status_code,
            )

        # Calculate usage from headers
        bedrock_input_tokens: Final = raw_response.headers.get("x-amzn-bedrock-input-token-count", None)
        bedrock_output_tokens: Final = raw_response.headers.get("x-amzn-bedrock-output-token-count", None)

        prompt_tokens: Final = int(bedrock_input_tokens or litellm.token_counter(messages=messages))

        completion_tokens: Final = int(
            bedrock_output_tokens
            or litellm.token_counter(
                text=model_response.choices[0].message.content,
                count_response_tokens=True,
            )
        )

View on GitHub (pinned to 77b7c6c40c)