{"record":{"id":"629b3ee9f352a2de","repo":"BerriAI/litellm","slug":"chunk-cannot-be-parsed-as-json-e","errorCode":null,"errorMessage":"Chunk cannot be parsed as JSON: {e}","messagePattern":"Chunk cannot be parsed as JSON: (.+?)","errorType":"exception","errorClass":"OCIError","httpStatus":500,"severity":"error","filePath":"litellm/llms/oci/chat/transformation.py","lineNumber":754,"sourceCode":"        # tool calls. The Cohere handler uses this to decide whether the\n        # terminal consolidation chunk's tool calls are duplicates (suppress)\n        # or the only copy of the tool calls (pass through).\n        self._cohere_tool_calls_emitted = False\n        # Analogous flag for text content. Lets the Cohere handler distinguish\n        # the common case (prior deltas already streamed the text, so the\n        # terminal chunk's text is a duplicate to suppress) from the degenerate\n        # single-event case (terminal chunk carries the only copy of the text).\n        self._cohere_text_emitted = False\n\n    def chunk_creator(self, chunk: Any) -> ModelResponseStream:\n        if not isinstance(chunk, str):\n            raise ValueError(f\"Chunk is not a string: {chunk}\")\n        if not chunk.startswith(\"data:\"):\n            raise ValueError(f\"Chunk does not start with 'data:': {chunk}\")\n        try:\n            dict_chunk: Final = json.loads(chunk[5:])\n        except json.JSONDecodeError as e:\n            raise OCIError(\n                status_code=500,\n                message=f\"Chunk cannot be parsed as JSON: {e}\",\n            )\n\n        if dict_chunk.get(\"apiFormat\") == \"COHERE\":\n            result: Final = handle_cohere_stream_chunk(\n                dict_chunk,\n                prior_tool_calls_emitted=self._cohere_tool_calls_emitted,\n                prior_text_emitted=self._cohere_text_emitted,\n            )\n            if not self._cohere_tool_calls_emitted:\n                for choice in result.choices:\n                    if getattr(choice.delta, \"tool_calls\", None) is not None:\n                        self._cohere_tool_calls_emitted = True\n                        break\n            if not self._cohere_text_emitted:\n                for choice in result.choices:\n                    if getattr(choice.delta, \"content\", None):","sourceCodeStart":736,"sourceCodeEnd":772,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/oci/chat/transformation.py#L736-L772","documentation":"Error \"Chunk cannot be parsed as JSON: {e}\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/llms/oci/chat/transformation.py:754 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["The stream chunk was not valid JSON; check the wrapped error {e}, verify endpoint stability, and retry."],"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"}