{"record":{"id":"ef326b285c5c0016","repo":"xtekky/gpt4free","slug":"response-line","errorCode":null,"errorMessage":"Response: {line}","messagePattern":"Response: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/hf/HuggingChat.py","lineNumber":178,"sourceCode":"        response = session.post(\n            f\"{cls.url}/conversation/{conversationId}\",\n            headers=headers,\n            multipart=data,\n            stream=True,\n        )\n        raise_for_status(response)\n\n        sources = None\n        for line in response.iter_lines():\n            if not line:\n                continue\n            try:\n                line = json.loads(line)\n            except json.JSONDecodeError as e:\n                debug.error(f\"Failed to decode JSON: {line}, error: {e}\")\n                continue\n            if \"type\" not in line:\n                raise RuntimeError(f\"Response: {line}\")\n            elif line[\"type\"] == \"stream\":\n                yield line[\"token\"].replace(\"\\u0000\", \"\")\n            elif line[\"type\"] == \"finalAnswer\":\n                if sources is not None:\n                    yield sources\n                yield FinishReason(\"stop\")\n                break\n            elif line[\"type\"] == \"file\":\n                url = f\"{cls.url}/conversation/{conversationId}/output/{line['sha']}\"\n                yield ImageResponse(\n                    url,\n                    format_media_prompt(messages, prompt),\n                    options={\"cookies\": auth_result.cookies},\n                )\n            elif line[\"type\"] == \"webSearch\" and \"sources\" in line:\n                sources = Sources(line[\"sources\"])\n            elif line[\"type\"] == \"title\":\n                yield TitleGeneration(line[\"title\"])","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/hf/HuggingChat.py#L160-L196","documentation":"Raised while iterating HuggingChat's streaming response when a JSON line decodes successfully but has no \"type\" field. The SSE/stream protocol from huggingface.co conversations is expected to carry typed events (stream, finalAnswer, file, reasoning); an untyped line means the protocol changed or an unexpected event shape arrived, and the provider fails fast with the raw line included.","triggerScenarios":"Streaming a HuggingChat conversation where response.iter_lines() yields a valid JSON object lacking the \"type\" key (e.g. HuggingFace adds a new event kind or returns an error object inline).","commonSituations":"HuggingFace ships a streaming protocol change (new event types, error frames); g4f version lagging behind the API; account-level notices injected into the stream.","solutions":["Update g4f — protocol drift against HuggingChat's stream is handled in newer releases","Inspect the logged line to see what the untyped event contains","Check HuggingFace status/changelog for conversation API changes","Fall back to a different chat provider while the fix lands"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    async for chunk in HuggingChat.create_async_generator(model, messages, auth_result=auth):\n        ...\nexcept RuntimeError as e:\n    if str(e).startswith(\"Response:\"):\n        # untyped stream event: protocol drift — switch provider\n        async for chunk in fallback_provider.create_async_generator(model, messages):\n            ...\n    else:\n        raise","preventionTips":["Stay current with g4f releases when using scraped/streaming HuggingChat endpoints","Wrap provider calls in a router that can switch providers on protocol errors","Enable g4f debug logging to capture the offending line for bug reports"],"tags":["huggingchat","streaming","protocol-change","runtime-error"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}