{"record":{"id":"22bb7f558da88512","repo":"BerriAI/litellm","slug":"e-22bb7f","errorCode":null,"errorMessage":"{e}","messagePattern":"\\{e\\}","errorType":"exception","errorClass":"TextCompletionCodestralError","httpStatus":500,"severity":"error","filePath":"litellm/llms/codestral/completion/handler.py","lineNumber":359,"sourceCode":"        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,\n            encoding=encoding,\n        )\n\n    @track_llm_api_timing()\n    async def async_streaming(","sourceCodeStart":341,"sourceCodeEnd":377,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/codestral/completion/handler.py#L341-L377","documentation":"The catch-all branch in the async Codestral handler: any exception from async_handler.post that is not an httpx.HTTPStatusError (connect errors, timeouts, DNS failures, TLS errors) is re-raised as TextCompletionCodestralError with status_code=500 and the original exception string as the message. The 500 is local — no server response exists.","triggerScenarios":"Network-level failures during the async POST: httpx.ConnectError, httpx.ConnectTimeout, httpx.ReadTimeout, DNS resolution failure, TLS certificate errors, or a misconfigured api_base hostname.","commonSituations":"Short timeouts with long Codestral generations (ReadTimeout); egress firewall blocking api.mistral.ai; DNS problems in containers; self-signed proxy certificates. Distinguish from a real server 500 by the message text (it contains the httpx exception repr, not a JSON body).","solutions":["Read error.message: 'timed out' means raise the timeout param; 'connect'/'name resolution' means network/DNS/firewall.","Increase timeout on the call (litellm text_completion supports timeout=...).","Fix egress: allow api.mistral.ai:443 from the runtime; verify with curl from the same host.","Retry transient network failures with exponential backoff."],"exampleFix":"# before\nresp = await litellm.atext_completion(\n    model=\"text-completion-codestral/codestral-latest\", prompt=prompt, timeout=10\n)\n\n# after\nresp = await litellm.atext_completion(\n    model=\"text-completion-codestral/codestral-latest\", prompt=prompt, timeout=120\n)","handlingStrategy":"retry","validationCode":"import socket\n\n# fail fast on unreachable endpoint before launching async work\nsocket.getaddrinfo(\"api.mistral.ai\", 443)  # raises on DNS failure","typeGuard":null,"tryCatchPattern":"from litellm.exceptions import TextCompletionCodestralError\n\ntry:\n    resp = await litellm.atext_completion(..., timeout=120)\nexcept TextCompletionCodestralError as e:\n    if e.status_code == 500 and (\"timed out\" in str(e.message) or \"connect\" in str(e.message).lower()):\n        await retry_with_jitter()  # network-level, no server involved\n    else:\n        raise","preventionTips":["Set explicit timeouts sized to your longest expected generation.","Verify egress to api.mistral.ai:443 from the runtime host before deploying.","Treat status_code=500 with a network-flavored message as local, not server, failure."],"tags":["codestral","async","network","timeout"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}