{"record":{"id":"60bea8a7acf278e6","repo":"xtekky/gpt4free","slug":"cannot-validate-glm-account-status-response-stat","errorCode":null,"errorMessage":"Cannot validate GLM account (status {response.status})","messagePattern":"Cannot validate GLM account \\(status (.+?)\\)","errorType":"exception","errorClass":"ProviderException","httpStatus":null,"severity":"error","filePath":"g4f/Provider/glm/__init__.py","lineNumber":274,"sourceCode":"    # ── Session (session.ts: getCurrentUser, getOrCreateChatSession) ────────\n\n    @classmethod\n    def _get_current_user(cls, session) -> dict:\n        \"\"\"Validate JWT and get user info via /api/v1/auths/ (session.ts).\n\n        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","sourceCodeStart":256,"sourceCodeEnd":292,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/glm/__init__.py#L256-L292","documentation":"ProviderException raised in the GLM provider's account validation helper when GET {GLM_BASE_URL}/api/v1/auths/ returns status >= 400. The provider uses a web-session API key (cls.api_key) and validates the account before chatting; any HTTP error (401 invalid key, 403 blocked, 429 rate limit, 5xx) collapses into this single message with the status embedded.","triggerScenarios":"The class-level api_key is expired/wrong (401), the session was rate-limited or the endpoint rejected the request (4xx/5xx) during _validate/_fetch, typically invoked at the start of a chat request or account check.","commonSituations":"Hardcoded or cached GLM API key that expired; regional blocks or Cloudflare challenges on the Z.ai endpoint; key obtained from a different base URL than GLM_BASE_URL points to.","solutions":["Refresh the GLM/Z.ai API key and re-set cls.api_key before calling the provider","Confirm the status: 401/403 means credential problem, 429 means back off, 5xx means retry later","Verify GLM_BASE_URL matches the endpoint the key was issued for (no proxy/region mismatch)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import aiohttp\n\nasync def glm_key_ok(api_key: str) -> bool:\n    async with aiohttp.ClientSession() as s:\n        async with s.get(f'{GLM_BASE_URL}/api/v1/auths/',\n                         headers={'Authorization': f'Bearer {api_key}'}) as r:\n            return r.status < 400","typeGuard":null,"tryCatchPattern":"from g4f.errors import ProviderException\n\ntry:\n    user = await GLM._validate_account(session)\nexcept ProviderException as e:\n    if 'status 401' in str(e) or 'status 403' in str(e):\n        refresh_glm_key()  # credential problem\n    raise","preventionTips":["Validate the GLM key at startup with a cheap auths/ call","Distinguish 401/403 (fix key) from 429/5xx (back off) using the embedded status","Keep the key in config/env, never hardcoded past its expiry"],"tags":["authentication","http-error","glm","api-key"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}