BerriAI/litellm · error · OCIError
Chunk cannot be parsed as JSON
Error message
Chunk cannot be parsed as JSON: {e} What it means
Error "Chunk cannot be parsed as JSON: {e}" thrown in BerriAI/litellm.
Solutions
- The stream chunk was not valid JSON; check the wrapped error {e}, verify endpoint stability, and retry.
When it happens
Trigger: Thrown at litellm/llms/oci/chat/transformation.py:754 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/629b3ee9f352a2de.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/oci/chat/transformation.py:754
# tool calls. The Cohere handler uses this to decide whether the
# terminal consolidation chunk's tool calls are duplicates (suppress)
# or the only copy of the tool calls (pass through).
self._cohere_tool_calls_emitted = False
# Analogous flag for text content. Lets the Cohere handler distinguish
# the common case (prior deltas already streamed the text, so the
# terminal chunk's text is a duplicate to suppress) from the degenerate
# single-event case (terminal chunk carries the only copy of the text).
self._cohere_text_emitted = False
def chunk_creator(self, chunk: Any) -> ModelResponseStream:
if not isinstance(chunk, str):
raise ValueError(f"Chunk is not a string: {chunk}")
if not chunk.startswith("data:"):
raise ValueError(f"Chunk does not start with 'data:': {chunk}")
try:
dict_chunk: Final = json.loads(chunk[5:])
except json.JSONDecodeError as e:
raise OCIError(
status_code=500,
message=f"Chunk cannot be parsed as JSON: {e}",
)
if dict_chunk.get("apiFormat") == "COHERE":
result: Final = handle_cohere_stream_chunk(
dict_chunk,
prior_tool_calls_emitted=self._cohere_tool_calls_emitted,
prior_text_emitted=self._cohere_text_emitted,
)
if not self._cohere_tool_calls_emitted:
for choice in result.choices:
if getattr(choice.delta, "tool_calls", None) is not None:
self._cohere_tool_calls_emitted = True
break
if not self._cohere_text_emitted:
for choice in result.choices:
if getattr(choice.delta, "content", None):View on GitHub (pinned to 77b7c6c40c)