{"record":{"id":"ec633f2c7ed167fa","repo":"xtekky/gpt4free","slug":"failed-to-parse-session-response-session-data","errorCode":null,"errorMessage":"Failed to parse session response: {session_data}","messagePattern":"Failed to parse session response: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/DeepSeek.py","lineNumber":509,"sourceCode":"                async with session.post(CHAT_SESSION_CREATE_ENDPOINT) as response:\n                    await raise_for_status(response)\n                    session_data = await response.json()\n                    # ID is nested in data.biz_data.id\n                    if (\n                        session_data.get(\"data\")\n                        and \"biz_data\" in session_data[\"data\"]\n                        and \"id\" in session_data[\"data\"][\"biz_data\"]\n                    ):\n                        chat_session_id = session_data[\"data\"][\"biz_data\"][\"id\"]\n                        conversation.chat_session_id = chat_session_id\n                        debug.log(\n                            f\"DeepSeekAuth: Chat session created: {chat_session_id}\"\n                        )\n                    else:\n                        debug.error(\n                            f\"DeepSeekAuth: Unexpected session response: {session_data}\"\n                        )\n                        raise Exception(\n                            f\"Failed to parse session response: {session_data}\"\n                        )\n        else:\n            debug.log(\n                f\"DeepSeekAuth: Reusing existing chat session: {conversation.chat_session_id}\"\n            )\n\n        # Yield conversation object so caller can reuse it for subsequent messages\n        yield conversation\n\n        # Upload file if provided - use HTTP/1.1 to avoid HTTP/2 stream errors\n        ref_file_ids = []\n        if media is not None and len(media) > 0:\n            # Take first file from media list\n            file_bytes, filename = media[0]\n            async with StreamSession(\n                headers=headers,\n                cookies=cookies,","sourceCodeStart":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/DeepSeek.py#L491-L527","documentation":"Generic Exception raised in DeepSeekAuth when creating a new chat session: the POST response parsed as JSON does not match the expected shape data.biz_data.id, so no chat_session_id can be extracted. The entire session response is embedded in the message, which usually reveals an auth or API-version problem disguised as a parse failure.","triggerScenarios":"First message of a conversation (no existing chat_session_id) where DeepSeek returns an error object or changed schema — e.g. expired token returning {\"code\": 401, ...}, rate-limit body, or an API revision that moved the session id.","commonSituations":"Stale HAR token that still passes the local check but is rejected server-side; DeepSeek A/B-changing its session-creation payload; g4f version lagging behind an API change.","solutions":["Read the embedded session_data payload — codes like 401/429 pinpoint expired auth vs rate limiting.","Re-export a fresh HAR with a valid authorization token and retry.","Update g4f to the latest release so the parser matches DeepSeek's current response schema.","If rate-limited, back off and retry new conversations later."],"exampleFix":"# before\nresp = await client.chat.completions.create(model=..., provider=DeepSeek, messages=[{\"role\": \"user\", \"content\": \"hi\"}])\n# Exception: Failed to parse session response: {'code': 401, 'msg': 'unauthorized'}\n\n# after\n# refresh har_and_cookies/deepseek.har with a logged-in capture, then retry\nresp = await client.chat.completions.create(model=..., provider=DeepSeek, messages=[{\"role\": \"user\", \"content\": \"hi\"}])","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    resp = await client.chat.completions.create(model=m, provider=DeepSeek, messages=msgs)\nexcept Exception as e:\n    if \"Failed to parse session response\" in str(e):\n        if \"401\" in str(e) or \"unauthorized\" in str(e).lower():\n            refresh_har_and_retry()\n        else:\n            update_g4f_and_report(e)","preventionTips":["Treat schema-parse failures as probable auth expiry first; check the embedded payload for status codes.","Keep g4f updated to track DeepSeek API changes.","Start conversations with fresh tokens rather than long-lived HARs."],"tags":["response-parsing","deepseek","session","api-change"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}