{"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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/codestral/completion/handler.py#L336-L372","documentation":"TextCompletionCodestralError raised when the async POST to the Codestral text-completion endpoint returns an error status (raise_for_status fired). The message embeds the upstream response body, so the exact provider error — invalid model, bad credentials, malformed request — is visible. The upstream status code is preserved on the exception.","triggerScenarios":"POSTing to the Codestral completion API with an invalid model name, invalid/expired key (401), malformed request body (422), rate limit (429), or upstream 5xx.","commonSituations":"Model renamed/removed by Mistral (e.g. codestral-latest variants); expired API key; prompt exceeding context limits; bursts hitting rate limits; sending chat-format fields to the text-completion endpoint.","solutions":["Read the embedded response text and status: 401 -> refresh the key, 404 -> fix the model name, 422 -> fix payload fields, 429 -> back off","Verify the model identifier matches one currently offered on La Plateforme (e.g. codestral-latest)","Add retry with exponential backoff for 429/5xx and cap concurrency","Ensure the request body matches the text-completion schema (prompt, suffix, stop, temperature) — not chat messages"],"exampleFix":"# before\nresp = await litellm.atext_completion(\n    model=\"text-completion-codestral\", prompt=\"def fib(\", temperature=2.5\n)\n\n# after\nresp = await litellm.atext_completion(\n    model=\"text-completion-codestral\", prompt=\"def fib(\", temperature=0.7\n)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from litellm.llms.codestral.completion.handler import TextCompletionCodestralError\n\ntry:\n    resp = await litellm.atext_completion(model=\"text-completion-codestral\", prompt=prompt)\nexcept TextCompletionCodestralError as e:\n    if e.status_code == 429 or e.status_code >= 500:\n        await asyncio.sleep(2 ** attempt)\n        resp = await litellm.atext_completion(model=\"text-completion-codestral\", prompt=prompt)\n    elif e.status_code == 401:\n        raise RuntimeError(\"Codestral API key invalid or expired\") from e\n    elif e.status_code == 404:\n        raise RuntimeError(\"Unknown codestral model id\") from e\n    else:\n        raise","preventionTips":["Verify model ids against La Plateforme before shipping (404s are cheap to prevent)","Wrap calls in bounded retry with backoff for 429/5xx only","Keep request bodies within the text-completion schema; do not send chat-only fields"],"tags":["codestral","mistral","http-status","provider-error","text-completion"],"backgroundTag":"http-error-response","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}