{"record":{"id":"4d2aa997872e5819","repo":"BerriAI/litellm","slug":"httpstatuserror-e-response-text","errorCode":null,"errorMessage":"HTTPStatusError - {e.response.text}","messagePattern":"HTTPStatusError - (.+?)","errorType":"exception","errorClass":"TextCompletionCodestralError","httpStatus":null,"severity":"error","filePath":"litellm/llms/codestral/completion/handler.py","lineNumber":354,"sourceCode":"        encoding,\n        api_key,\n        logging_obj,\n        stream,\n        data: dict,\n        optional_params: dict,\n        timeout: float | httpx.Timeout,\n        litellm_params=None,\n        logger_fn=None,\n        headers={},\n    ) -> TextCompletionResponse:\n        async_handler: Final = get_async_httpx_client(\n            llm_provider=litellm.LlmProviders.TEXT_COMPLETION_CODESTRAL,\n            params={\"timeout\": timeout},\n        )\n        try:\n            response: Final = await async_handler.post(api_base, headers=headers, data=json.dumps(data))\n        except httpx.HTTPStatusError as e:\n            raise TextCompletionCodestralError(\n                status_code=e.response.status_code,\n                message=f\"HTTPStatusError - {e.response.text}\",\n            )\n        except Exception as e:\n            raise TextCompletionCodestralError(\n                status_code=500, message=f\"{e}\"\n            )  # don't use verbose_logger.exception, if exception is raised\n        return self.process_text_completion_response(\n            model=model,\n            response=response,\n            model_response=model_response,\n            stream=stream,\n            logging_obj=logging_obj,\n            api_key=api_key,\n            data=data,\n            messages=messages,\n            print_verbose=print_verbose,\n            optional_params=optional_params,","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/codestral/completion/handler.py#L336-L372","documentation":"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.","triggerScenarios":"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.","commonSituations":"Async workloads (FastAPI, asyncio scripts) hitting rate limits (429) under concurrency; expired keys; Mistral incidents. The message prefix 'HTTPStatusError - ' identifies this specific catch branch.","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from litellm.exceptions import TextCompletionCodestralError\n\ntry:\n    resp = await litellm.atext_completion(...)\nexcept TextCompletionCodestralError as e:\n    if e.status_code >= 500 or e.status_code == 429:\n        await asyncio.sleep(backoff())\n        return await retry()\n    raise","preventionTips":["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."],"tags":["codestral","async","http-error","httpx"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}