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
- Use error.status_code and the body after the 'HTTPStatusError - ' prefix to find the root cause.
- 429: reduce concurrency, add exponential backoff (litellm num_retries or tenacity).
- 401/403: refresh CODESTRAL_API_KEY.
- 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
- Set sensible concurrency limits for async Codestral calls to avoid 429 storms.
- Enable litellm fallbacks (fallbacks=['text-completion-codestral/codestral-latest']) for resilience.
- Alert on repeated 'HTTPStatusError - ' messages to catch key/quota drift early.
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
- response.text
- {e}
- Failed to connect to Braintrust API: {str(e)}
- Invalid Authorization header format. Expected: Bearer <token
- Invalid authorization header format. Expected 'Bearer <token
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/4d2aa997872e5819.
Report an issue: GitHub.