{"record":{"id":"71a7e1ebd1773ad0","repo":"BerriAI/litellm","slug":"failed-to-transform-streaming-response","errorCode":null,"errorMessage":"Failed to transform streaming response","messagePattern":"Failed to transform streaming response","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/google_genai/adapters/handler.py","lineNumber":93,"sourceCode":"            completion_response: Final = await litellm.acompletion(**completion_kwargs)\n\n            if stream:\n                # Check if completion_response is actually a stream or a ModelResponse\n                # This can happen in error cases or when stream is not properly supported\n                if not hasattr(completion_response, \"__aiter__\"):\n                    # If it's not a stream, treat it as a regular response\n                    generate_content_response = GOOGLE_GENAI_ADAPTER.translate_completion_to_generate_content(\n                        cast(ModelResponse, completion_response)\n                    )\n                    return generate_content_response\n                else:\n                    # Transform streaming completion response to generate_content format\n                    transformed_stream: Final = GOOGLE_GENAI_ADAPTER.translate_completion_output_params_streaming(\n                        completion_response\n                    )\n                    if transformed_stream is not None:\n                        return transformed_stream\n                    raise ValueError(\"Failed to transform streaming response\")\n            else:\n                # Transform completion response back to generate_content format\n                generate_content_response = GOOGLE_GENAI_ADAPTER.translate_completion_to_generate_content(\n                    cast(ModelResponse, completion_response)\n                )\n                return generate_content_response\n\n        except Exception as e:\n            raise ValueError(f\"Error calling litellm.acompletion for generate_content: {e}\")\n\n    @staticmethod\n    def generate_content_handler(\n        model: str,\n        contents: list[dict[str, object]] | dict[str, object],\n        litellm_params: GenericLiteLLMParams,\n        config: dict[str, object] | None = None,\n        stream: bool = False,\n        _is_async: bool = False,","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/google_genai/adapters/handler.py#L75-L111","documentation":"In the async Google GenAI generate_content adapter, a streaming completion result is converted chunk-by-chunk via translate_completion_output_params_streaming. That helper returns None when a chunk cannot be transformed (e.g. a CustomStreamWrapper or chunk shape it does not recognize); the adapter treats None as failure and raises this ValueError.","triggerScenarios":"Calling the adapter-backed acompletion path with stream=True where the completion response object is not a recognized streaming chunk type — for example a provider config was not found so the adapter path ran, and the returned wrapper's first yielded object fails the streaming transform.","commonSituations":"Using litellm.google_genai generate_content passthrough with stream=True for models/providers the adapter doesn't fully map; LiteLLM version drift where new chunk types (e.g. usage-only chunks, thinking chunks) aren't handled by the translator.","solutions":["Update litellm — the streaming translator gains coverage for new chunk shapes over releases","Retry with stream=False to confirm the non-streaming transform path works for the same model/params","Call litellm.acompletion directly with the equivalent model (e.g. 'gemini/gemini-2.5-flash') instead of the generate_content adapter if you don't need the Google-native response shape","Report the chunk type that fails: log type(completion_response) and its first chunk to help pinpoint the unhandled case"],"exampleFix":"# before\nresp = await agenerate_content(model='gemini-2.5-flash', contents=[...], stream=True)\n\n# after\nresp = await agenerate_content(model='gemini-2.5-flash', contents=[...], stream=False)\n# or bypass the adapter:\nresp = await litellm.acompletion(model='gemini/gemini-2.5-flash', messages=[...], stream=True)","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    stream = await agenerate_content(model=m, contents=c, stream=True)\nexcept ValueError as e:\n    if \"Failed to transform streaming response\" in str(e):\n        stream = None\n        result = await agenerate_content(model=m, contents=c, stream=False)  # fallback","preventionTips":["Pin litellm versions you tested adapters with","Prefer litellm.acompletion('gemini/...') when the native shape isn't needed"],"tags":["google-genai","streaming","adapter"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}