{"record":{"id":"2bb66d92519b0e0d","repo":"xtekky/gpt4free","slug":"no-user-id-in-auth-response","errorCode":null,"errorMessage":"No user ID in auth response","messagePattern":"No user ID in auth response","errorType":"exception","errorClass":"ProviderException","httpStatus":null,"severity":"error","filePath":"g4f/Provider/glm/__init__.py","lineNumber":280,"sourceCode":"        Returns dict with id, name, email, or raises ProviderException.\n        \"\"\"\n\n        async def _fetch():\n            async with session.get(\n                f\"{GLM_BASE_URL}/api/v1/auths/\",\n                headers={\n                    \"Authorization\": f\"Bearer {cls.api_key}\",\n                    \"Content-Type\": \"application/json\",\n                },\n            ) as response:\n                if response.status >= 400:\n                    raise ProviderException(\n                        f\"Cannot validate GLM account (status {response.status})\"\n                    )\n                data = await response.json()\n                user = data.get(\"user\") or data\n                if not user or not user.get(\"id\"):\n                    raise ProviderException(\"No user ID in auth response\")\n                return {\n                    \"id\": str(user[\"id\"]),\n                    \"name\": user.get(\"name\") or user.get(\"nickname\") or \"User\",\n                    \"email\": user.get(\"email\", \"\"),\n                }\n\n        # Run in the async context — this is called from create_async_generator\n        import asyncio\n\n        return asyncio.get_event_loop().run_until_complete(_fetch())\n\n    @classmethod\n    async def _get_or_create_chat_session(cls, session, model: str) -> str:\n        \"\"\"Create a new chat session via /api/v1/chats/new (session.ts).\n\n        Returns the chat_id string.\n        \"\"\"\n        chat_id = str(uuid.uuid4())","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/glm/__init__.py#L262-L298","documentation":"ProviderException raised when the GLM auth validation endpoint answered 2xx but the JSON payload does not contain a usable user object with an 'id' (neither data['user'] nor the top-level object has id). It guards against schema drift or unexpected payloads (HTML error pages parsed as empty JSON, API changes) so the provider never proceeds with an unidentifiable account.","triggerScenarios":"The /api/v1/auths/ response shape changed (user object renamed/nested differently), or the endpoint returned an empty/error JSON body with status 200 — e.g. behind a captive proxy or after a Z.ai API revision.","commonSituations":"Upstream Z.ai API schema changes not yet reflected in the installed g4f version; responses from a mirror/proxy that strips the user object.","solutions":["Update g4f to the latest version so the response parsing matches the current Z.ai API","Manually curl GET {GLM_BASE_URL}/api/v1/auths/ with the Bearer key and inspect whether 'user.id' exists","If using a proxy/mirror base URL, point GLM_BASE_URL at the official endpoint"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    user = await GLM._validate_account(session)\nexcept ProviderException as e:\n    if 'No user ID' in str(e):\n        log.error('Z.ai auth response schema changed — update g4f')\n    raise","preventionTips":["Pin and promptly update the g4f version when using web-session providers like GLM","Add a canary request after key setup to catch schema drift early","Avoid proxies that rewrite the auths/ response body"],"tags":["glm","schema-drift","validation","api-response"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}