{"record":{"id":"d0ee9975e65cf67c","repo":"xtekky/gpt4free","slug":"failed-to-create-chat-data","errorCode":null,"errorMessage":"Failed to create chat: {data}","messagePattern":"Failed to create chat: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/Qwen.py","lineNumber":586,"sourceCode":"                    if conversation is None:\r\n                        chat_payload = {\r\n                            \"title\": \"New Chat\",\r\n                            \"models\": [model_name],\r\n                            \"chat_mode\": \"normal\",\r\n                            \"chat_type\": chat_type,\r\n                            \"timestamp\": now,\r\n                            \"project_id\": \"\",\r\n                        }\r\n                        async with session.post(\r\n                            f\"{cls.url}/api/v2/chats/new\",\r\n                            json=chat_payload,\r\n                            headers=req_headers,\r\n                            proxy=proxy,\r\n                        ) as resp:\r\n                            await cls.raise_for_status(resp)\r\n                            data = await resp.json()\r\n                            if not (data.get(\"success\") and data[\"data\"].get(\"id\")):\r\n                                raise RuntimeError(f\"Failed to create chat: {data}\")\r\n                        conversation = JsonConversation(\r\n                            chat_id=data[\"data\"][\"id\"],\r\n                            cookies={key: value for key, value in resp.cookies.items()},\r\n                            parent_id=None,\r\n                        )\r\n                    files = []\r\n                    media = list(merge_media(media, messages))\r\n                    if media:\r\n                        files = await cls.prepare_files(\r\n                            media, session=session, headers=req_headers\r\n                        )\r\n\r\n                    feature_config = (\r\n                        {\r\n                            \"auto_thinking\": auto_thinking,\r\n                            \"thinking_mode\": thinking_mode,\r\n                            # \"thinking_format\": \"summary\",\r\n                            \"thinking_enabled\": enable_thinking,\r","sourceCodeStart":568,"sourceCodeEnd":604,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/Qwen.py#L568-L604","documentation":"Raised when Qwen's POST to /api/v2/chats/new returns JSON lacking success=true plus data.id — the chat container could not be created on chat.qwen.ai. The full payload is embedded; typical causes are expired/flagged cookies, WAF-adjacent soft failures, or upstream API contract changes.","triggerScenarios":"First message in a conversation (no existing conversation object) when the new-chat API refuses: invalid anonymous cookies, session flagged after the outer loop reset conversation=None, or the response shape changed (id moved).","commonSituations":"Repeated runs with generated cookie jars that get flagged; Qwen A/B-changing its v2 API; race between nodriver cookie harvest and API use; rate pressure causing soft failures without 429.","solutions":["Inspect the embedded data payload for the upstream refusal reason.","Retry — the outer retry loop treats some failures as rate limits; if re-raised, restart the process to regenerate cookies.","Update g4f for the current /api/v2/chats/new contract.","Reduce parallel conversations from the same identity."],"exampleFix":"# before - many concurrent conversations\nawait asyncio.gather(*[Qwen.create_async_generator(model, m) for m in many_msgs])\n\n# after - serial, retry once\nfor m in many_msgs:\n    try:\n        await Qwen.create_async_generator(model, m)\n    except RuntimeError:\n        await asyncio.sleep(5)\n        await Qwen.create_async_generator(model, m)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    r = await Qwen.create_async_generator(model, msgs)\nexcept RuntimeError as e:\n    if 'Failed to create chat' in str(e):\n        await asyncio.sleep(5)\n        r = await Qwen.create_async_generator(model, msgs)  # new chat + new cookies\n    else:\n        raise","preventionTips":["Avoid parallel conversation creation from one identity","Restart the client to regenerate flagged cookies","Inspect embedded data payload for refusal reason","Update g4f for /api/v2/chats/new contract changes"],"tags":["qwen","conversation","api-response","auth","upstream-api"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}