BerriAI/litellm · error · BedrockError

{error_message}

Error message

{error_message}

What it means

For InvokeAgent responses with non-200 status, the body is decoded and combined with the ':exception-type' response header (prepended to the message) into a BedrockError preserving the upstream status code. The message may be JSON-encoded text when the body was an object, so the AWS error code appears as an 'exceptionType message' string.

Source

Thrown at litellm/llms/bedrock/chat/invoke_agent/transformation.py:245

        try:
            response_dict: Final = event.to_response_dict()
            verbose_logger.debug("Response dict: %s", response_dict)

            # Use the same response shape parsing as the existing decoder
            parsed_response: Final = parser.parse(response_dict, self._get_response_stream_shape())
            verbose_logger.debug("Parsed response: %s", parsed_response)

            if response_dict["status_code"] != 200:
                decoded_body: Final = response_dict["body"].decode()
                if isinstance(decoded_body, dict):
                    error_message = decoded_body.get("message")
                elif isinstance(decoded_body, str):
                    error_message = decoded_body
                else:
                    error_message = ""
                exception_status: Final = response_dict["headers"].get(":exception-type")
                error_message = exception_status + " " + error_message
                raise BedrockError(
                    status_code=response_dict["status_code"],
                    message=(json.dumps(error_message) if isinstance(error_message, dict) else error_message),
                )

            if "chunk" in parsed_response:
                chunk = parsed_response.get("chunk")
                if not chunk:
                    return None
                return chunk.get("bytes").decode()
            else:
                chunk = response_dict.get("body")
                if not chunk:
                    return None
                return chunk.decode()

        except Exception as e:
            verbose_logger.debug("Error parsing message from event: %s", e)
            return None

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Read the exception-type prefix in the message for the AWS error code and map it to the specific fix
  2. Confirm the agent id + alias id pair still exists (console: Agents → Aliases) and re-copy them
  3. Grant bedrock:InvokeModel on the agent alias ARN in IAM when seeing 403
  4. For 429 configure Router retries/fallbacks; for 400 check sessionId and memory parameters
Defensive patterns

Strategy: try-catch

Try / catch

from litellm.exceptions import BedrockError

try:
    resp = litellm.completion(model=f"agent/{AGENT_ID}/{ALIAS_ID}", messages=msgs)
except BedrockError as e:
    reason = str(e)  # ':exception-type' prefix + AWS message
    if e.status_code == 404:
        raise ConfigError(f"Agent/alias not found — re-check ids: {reason}") from e
    if e.status_code == 403:
        raise PermissionError(f"Grant bedrock:InvokeModel on the alias ARN: {reason}") from e
    if e.status_code == 429:
        time.sleep(2)
        resp = litellm.completion(model=f"agent/{AGENT_ID}/{ALIAS_ID}", messages=msgs)
    else:
        raise

Prevention

When it happens

Trigger: 404 when the agent id or alias id no longer exists; 403 when the caller lacks permission on the agent alias; 429 throttling; 400 for invalid sessionId or memory configuration; accessDeniedException on cross-account invocations.

Common situations: Agent re-created or re-deployed so the alias id changed; IAM role missing bedrock:InvokeModel on the agent alias ARN; session id reuse across concurrent invocations violating constraints; expired alias after agent deletion.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


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