BerriAI/litellm · error · BedrockError

err.response.text

Error message

err.response.text

What it means

Async Bedrock rerank POST returned non-2xx; httpx.HTTPStatusError from raise_for_status() is converted to BedrockError carrying the upstream status code and raw body (err.response.text). The body typically holds the bedrock-agent-runtime error JSON, e.g. ValidationException for a bad query/documents payload or AccessDeniedException for missing permissions.

Source

Thrown at litellm/llms/bedrock/rerank/handler.py:47

    async def arerank(
        self,
        prepared_request: BedrockPreparedRequest,
        timeout: float | httpx.Timeout | None = None,
        client: AsyncHTTPHandler | None = None,
    ):
        if client is None:
            client = get_async_httpx_client(llm_provider=litellm.LlmProviders.BEDROCK)
        try:
            response: Final = await client.post(
                url=prepared_request["endpoint_url"],
                headers=dict(prepared_request["prepped"].headers),
                data=prepared_request["body"],
                timeout=timeout,
            )
            response.raise_for_status()
        except httpx.HTTPStatusError as err:
            error_code: Final = err.response.status_code
            raise BedrockError(status_code=error_code, message=err.response.text)
        except httpx.TimeoutException:
            raise BedrockError(status_code=408, message="Timeout error occurred.")

        return BedrockRerankConfig()._transform_response(response.json())

    def rerank(
        self,
        model: str,
        query: str,
        documents: list[str | dict[str, Any]],
        optional_params: dict,
        logging_obj: LitellmLogging,
        top_n: int | None = None,
        rank_fields: list[str] | None = None,
        return_documents: bool | None = True,
        max_chunks_per_doc: int | None = None,
        _is_async: bool | None = False,
        timeout: float | httpx.Timeout | None = None,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Read the BedrockError message body — it names the AWS exception (ValidationException etc.) and field at fault.
  2. Use a rerank-capable model (e.g. 'bedrock/amazon.rerank-v1:0' / 'bedrock/cohere.rerank-v3-5:0').
  3. Trim documents to the service limits and ensure query/documents are non-empty strings.
  4. Grant IAM bedrock:InvokeModel on the bedrock-agent-runtime rerank resource and enable model access.
Defensive patterns

Strategy: retry

Try / catch

try:
    result = await litellm.rerank(model=model, query=q, documents=docs, timeout=120)
except BedrockError as e:
    if e.status_code == 429 and attempt < MAX:
        await asyncio.sleep(2 ** attempt + random.random())
        continue
    raise

Prevention

When it happens

Trigger: await litellm.rerank(model='bedrock/...') with malformed documents, too many documents exceeding the service limit, model access not enabled, or missing bedrock:InvokeModel on the agent-runtime rerank endpoint.

Common situations: Passing an unsupported model for rerank (only Amazon Rerank / Cohere rerank models serve this endpoint), empty query, documents exceeding size/count limits, IAM role without bedrock-agent-runtime access.

Related errors


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