{"record":{"id":"f74b761a711a3def","repo":"xtekky/gpt4free","slug":"expected-sse-response-but-got-content-type-conte","errorCode":null,"errorMessage":"Expected SSE response but got content-type: {content_type}","messagePattern":"Expected SSE response but got content-type: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/DeepSeek.py","lineNumber":571,"sourceCode":"            and conversation.parent_message_id\n        ):\n            json_data[\"parent_message_id\"] = conversation.parent_message_id\n\n        # debug.log(f\"DeepSeekAuth: Sending request to {CHAT_COMPLETION_ENDPOINT}\")\n\n        async with StreamSession(\n            headers=headers, cookies=cookies, proxy=proxy, impersonate=\"chrome\"\n        ) as session:\n            async with session.post(\n                CHAT_COMPLETION_ENDPOINT, json=json_data\n            ) as response:\n                # debug.log(f\"DeepSeekAuth: Processing response... status={response.status}, content-type={response.headers.get('content-type', 'unknown')}\")\n                await raise_for_status(response)\n\n                # Check if response is actually SSE or regular JSON\n                content_type = response.headers.get(\"content-type\", \"\")\n                if \"text/event-stream\" not in content_type.lower():\n                    raise RuntimeError(\n                        f\"Expected SSE response but got content-type: {content_type}\"\n                    )\n\n                is_thinking = False\n                async for stream_data in sse_stream(response):\n                    # Handle different stream data formats\n                    if isinstance(stream_data, dict):\n                        # Handle first chunk with message IDs (for conversation continuity)\n                        if \"response_message_id\" in stream_data:\n                            conversation.parent_message_id = stream_data[\n                                \"response_message_id\"\n                            ]\n                            # debug.log(f\"DeepSeekAuth: Set parent_message_id to {conversation.parent_message_id}\")\n\n                        # Handle initial response with fragments (most common case)\n                        # Format: {'v': {'response': {'fragments': [{'content': '42', ...}]}}}\n                        if \"v\" in stream_data and isinstance(stream_data[\"v\"], dict):\n                            response_obj = stream_data[\"v\"].get(\"response\", {})","sourceCodeStart":553,"sourceCodeEnd":589,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/DeepSeek.py#L553-L589","documentation":"RuntimeError raised while consuming the DeepSeek chat completion response: the request returned HTTP success but the Content-Type header is not text/event-stream. The provider's streaming parser only understands SSE; a JSON body (usually an inline error or a non-streaming reply) means the conversation flow diverged from expectations, so it fails loudly rather than parsing garbage.","triggerScenarios":"DeepSeek answers with application/json instead of SSE — commonly an error payload delivered with HTTP 200, a PoW/auth check that redirected to a non-stream endpoint, or a backend change. raise_for_status passed, so only the content-type betrays the problem.","commonSituations":"Expired or weak authorization token causing JSON error bodies; anti-bot challenge interposed (PoW not satisfied); DeepSeek A/B change disabling streaming for some accounts; proxies stripping or rewriting content-type.","solutions":["Re-capture/refresh the HAR and cookies so the request looks like a genuine browser session.","Update g4f to the latest version — content-type handling changes when DeepSeek tweaks its API.","Check any corporate proxy in the path for content-type mangling.","Retry with a fresh conversation object; long-lived sessions can fall out of streaming eligibility."],"exampleFix":"# before\nresp = await client.chat.completions.create(model=..., provider=DeepSeek, messages=msgs)\n# RuntimeError: Expected SSE response but got content-type: application/json\n\n# after\n# refresh har_and_cookies + update g4f, then start a fresh conversation\nconversation = None\nresp = await client.chat.completions.create(model=..., provider=DeepSeek, messages=msgs, conversation=conversation)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    async for chunk in stream:\n        handle(chunk)\nexcept RuntimeError as e:\n    if \"Expected SSE response\" in str(e):\n        refresh_har_cookies()\n        stream = retry_with_fresh_conversation()","preventionTips":["Keep browser-accurate cookies/headers so DeepSeek serves SSE as expected.","Update g4f when DeepSeek changes streaming behavior.","Avoid proxies that rewrite response content types."],"tags":["streaming","sse","content-type","deepseek"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}