{"record":{"id":"9f854ba90da6cb90","repo":"BerriAI/litellm","slug":"failed-to-convert-modelresponse-to-modelresponsest","errorCode":null,"errorMessage":"Failed to convert ModelResponse to ModelResponseStream: {model_response}. Error: {e}","messagePattern":"Failed to convert ModelResponse to ModelResponseStream: (.+?)\\. Error: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/base_llm/base_model_iterator.py","lineNumber":63,"sourceCode":"                    ),\n                    finish_reason=choice.finish_reason,\n                )\n            )\n        processed_chunk: Final = ModelResponseStream(\n            id=model_response.id,\n            object=\"chat.completion.chunk\",\n            created=model_response.created,\n            model=model_response.model,\n            choices=streaming_choices,\n        )\n        # Carry usage onto the streaming chunk so fake-streamed responses\n        # (e.g. Vertex AI Gemma :predict) still report token counts.\n        usage: Final = getattr(model_response, \"usage\", None)\n        if usage is not None:\n            setattr(processed_chunk, \"usage\", usage)\n        return processed_chunk\n    except Exception as e:\n        raise ValueError(f\"Failed to convert ModelResponse to ModelResponseStream: {model_response}. Error: {e}\")\n\n\nclass BaseModelResponseIterator:\n    def __init__(self, streaming_response, sync_stream: bool, json_mode: bool | None = False):\n        self.streaming_response = streaming_response\n        self.response_iterator = self.streaming_response\n        self.json_mode = json_mode\n        self.http_response: httpx.Response | None = None\n\n    async def aclose(self) -> None:\n        \"\"\"Close the upstream HTTP response so the provider connection is\n        released (and a backend like vLLM aborts generation) when the stream\n        is abandoned before its natural end.\n\n        ``streaming_response`` is usually a bare ``aiter_lines()`` generator\n        that holds no reference to the response, so the handler that owns the\n        response attaches it here after construction.\"\"\"\n        if self.http_response is not None:","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/base_llm/base_model_iterator.py#L45-L81","documentation":"Error \"Failed to convert ModelResponse to ModelResponseStream: {model_response}. Error: {e}\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/llms/base_llm/base_model_iterator.py:63 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the ModelResponse in the error; it cannot be converted to a stream chunk. Check the provider response shape."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}