BerriAI/litellm · error · ValueError

Failed to parse v2 chunk

Error message

Failed to parse v2 chunk: {e}, chunk: {chunk}

What it means

Parse failure in the Cohere v2 streaming chunk parser: transforming the incoming chunk dict into a GenericStreamingChunk raised, and the handler reports both the exception and the offending chunk payload for diagnosis.

Solutions

  1. Inspect the logged chunk; the Cohere v2 stream sent data that is not valid JSON or not the expected event shape.
  2. Upgrade litellm to the latest version; Cohere v2 streaming event formats have changed and newer releases handle them.
  3. If the chunk is a non-JSON SSE control line (e.g. '[DONE]'), filter such lines before parsing in your own stream handling.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at litellm/llms/cohere/common_utils.py:350 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/20f05baaa0f3245d. Report an issue: GitHub.

Appendix: source

Thrown at litellm/llms/cohere/common_utils.py:350

            # Handle citations in any chunk type (fallback)
            if "citations" in chunk:
                if provider_specific_fields is None:
                    provider_specific_fields = {}
                provider_specific_fields["citations"] = chunk["citations"]

            return GenericStreamingChunk(
                text=text,
                tool_use=tool_use,
                is_finished=is_finished,
                finish_reason=finish_reason,
                usage=usage,
                index=index,
                provider_specific_fields=provider_specific_fields,
            )

        except Exception as e:
            raise ValueError(f"Failed to parse v2 chunk: {e}, chunk: {chunk}")

    # Sync iterator
    def __iter__(self):
        return self

    def __next__(self):
        try:
            chunk: Final = self.response_iterator.__next__()
        except StopIteration:
            raise StopIteration
        except ValueError as e:
            raise RuntimeError(f"Error receiving chunk from stream: {e}")

        try:
            return self.convert_str_chunk_to_generic_chunk(chunk=chunk)
        except StopIteration:
            raise StopIteration
        except ValueError as e:

View on GitHub (pinned to 77b7c6c40c)