BerriAI/litellm · error · TextCompletionCodestralError

HTTPStatusError - {e.response.text}

Error message

HTTPStatusError - {e.response.text}

What it means

In the async non-streaming Codestral handler, httpx.HTTPStatusError raised by async_handler.post is caught and re-raised as TextCompletionCodestralError with the upstream status code and an 'HTTPStatusError - {body}' message. Note httpx only raises HTTPStatusError when response raising is enabled (raise_for_status semantics), so this branch covers status failures surfaced by the client.

Source

Thrown at litellm/llms/codestral/completion/handler.py:354

        encoding,
        api_key,
        logging_obj,
        stream,
        data: dict,
        optional_params: dict,
        timeout: float | httpx.Timeout,
        litellm_params=None,
        logger_fn=None,
        headers={},
    ) -> TextCompletionResponse:
        async_handler: Final = get_async_httpx_client(
            llm_provider=litellm.LlmProviders.TEXT_COMPLETION_CODESTRAL,
            params={"timeout": timeout},
        )
        try:
            response: Final = await async_handler.post(api_base, headers=headers, data=json.dumps(data))
        except httpx.HTTPStatusError as e:
            raise TextCompletionCodestralError(
                status_code=e.response.status_code,
                message=f"HTTPStatusError - {e.response.text}",
            )
        except Exception as e:
            raise TextCompletionCodestralError(
                status_code=500, message=f"{e}"
            )  # don't use verbose_logger.exception, if exception is raised
        return self.process_text_completion_response(
            model=model,
            response=response,
            model_response=model_response,
            stream=stream,
            logging_obj=logging_obj,
            api_key=api_key,
            data=data,
            messages=messages,
            print_verbose=print_verbose,
            optional_params=optional_params,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Use error.status_code and the body after the 'HTTPStatusError - ' prefix to find the root cause.
  2. 429: reduce concurrency, add exponential backoff (litellm num_retries or tenacity).
  3. 401/403: refresh CODESTRAL_API_KEY.
  4. 5xx: retry with jitter; check status.mistral.ai.
Defensive patterns

Strategy: retry

Try / catch

from litellm.exceptions import TextCompletionCodestralError

try:
    resp = await litellm.atext_completion(...)
except TextCompletionCodestralError as e:
    if e.status_code >= 500 or e.status_code == 429:
        await asyncio.sleep(backoff())
        return await retry()
    raise

Prevention

When it happens

Trigger: Async text completion (acompletion/text_completion async path) where the HTTP client raises HTTPStatusError: 4xx/5xx from Mistral with response raising on; commonly 401, 429, or 5xx.

Common situations: Async workloads (FastAPI, asyncio scripts) hitting rate limits (429) under concurrency; expired keys; Mistral incidents. The message prefix 'HTTPStatusError - ' identifies this specific catch branch.

Related errors


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