{"record":{"id":"11d28d6901a2ae01","repo":"xtekky/gpt4free","slug":"auth-failed","errorCode":"AUTH_FAILED","errorMessage":"GitHub token is invalid or expired. Please login again.","messagePattern":"GitHub token is invalid or expired\\. Please login again\\.","errorType":"exception","errorClass":"TokenManagerError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/github/copilotTokenProvider.py","lineNumber":70,"sourceCode":"\n        github_token = github_creds[\"access_token\"]\n\n        # Exchange for Copilot token\n        async with aiohttp.ClientSession() as session:\n            async with session.get(\n                self.COPILOT_TOKEN_URL,\n                headers={\n                    \"Authorization\": f\"token {github_token}\",\n                    \"Accept\": \"application/json\",\n                    \"User-Agent\": USER_AGENT,\n                    \"Editor-Version\": EDITOR_VERSION,\n                    \"Editor-Plugin-Version\": EDITOR_PLUGIN_VERSION,\n                    \"Openai-Organization\": \"github-copilot\",\n                    \"X-GitHub-Api-Version\": API_VERSION,\n                },\n            ) as resp:\n                if resp.status == 401:\n                    raise TokenManagerError(\n                        \"AUTH_FAILED\",\n                        \"GitHub token is invalid or expired. Please login again.\",\n                    )\n                if resp.status != 200:\n                    text = await resp.text()\n                    raise TokenManagerError(\n                        \"TOKEN_ERROR\",\n                        f\"Failed to get Copilot token: {resp.status} - {text}\",\n                    )\n\n                data = await resp.json()\n                self._copilot_token = data.get(\"token\")\n\n                # Parse expiration\n                expires_at = data.get(\"expires_at\")\n                if expires_at:\n                    try:\n                        # Parse ISO format datetime","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/github/copilotTokenProvider.py#L52-L88","documentation":"TokenManagerError with code AUTH_FAILED, raised when the Copilot token exchange endpoint (https://api.github.com/copilot_internal/token) answers HTTP 401. The stored GitHub OAuth token was rejected as invalid or expired, so exchanging it for a Copilot API token is impossible and a fresh login is required.","triggerScenarios":"GET copilot_internal/token with Authorization: token <github_token> returning 401 — revoked OAuth app grant, expired token, user password reset/2FA change invalidating tokens, or a truncated/corrupted stored token.","commonSituations":"The GitHub OAuth grant was revoked in GitHub settings; long-lived credentials that GitHub invalidated; manual editing of the credentials file corrupting the token string.","solutions":["Re-run 'g4f auth github-copilot' to obtain a fresh OAuth token","Check https://github.com/settings/applications and remove stale g4f grants, then re-authenticate","Delete the credential file first if re-login keeps failing, to force a clean device flow"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    token = await provider.get_valid_token()\nexcept TokenManagerError as e:\n    if e.code == 'AUTH_FAILED':\n        await run_device_login()  # non-retryable: must re-login\n        token = await provider.get_valid_token()","preventionTips":["Do not retry on AUTH_FAILED — the token is dead; re-authenticate immediately","Monitor for 401s from GitHub and auto-trigger re-login","Avoid storing tokens in multiple places so revocation is total"],"tags":["authentication","http-401","token-exchange","github-copilot"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}