{"record":{"id":"d623c9fc417e0f15","repo":"xtekky/gpt4free","slug":"failed-to-fetch-copilot-usage-resp-status-text","errorCode":null,"errorMessage":"Failed to fetch Copilot usage: {resp.status} {text}","messagePattern":"Failed to fetch Copilot usage: (.+?) (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/github/GithubCopilot.py","lineNumber":342,"sourceCode":"                \"Please run 'g4f auth github-copilot' to authenticate.\"\n            )\n\n        github_token = github_creds[\"access_token\"]\n        url = f\"https://api.github.com/copilot_internal/user\"\n        headers = {\n            \"accept\": \"application/json\",\n            \"authorization\": f\"token {github_token}\",\n            \"editor-version\": EDITOR_VERSION,\n            \"editor-plugin-version\": EDITOR_PLUGIN_VERSION,\n            \"user-agent\": USER_AGENT,\n            \"x-github-api-version\": API_VERSION,\n            \"x-vscode-user-agent-library-version\": \"electron-fetch\",\n        }\n        async with aiohttp.ClientSession() as session:\n            async with session.get(url, headers=headers) as resp:\n                if resp.status != 200:\n                    text = await resp.text()\n                    raise RuntimeError(\n                        f\"Failed to fetch Copilot usage: {resp.status} {text}\"\n                    )\n                usage = await resp.json()\n        return usage\n\n\nasync def main(args: Optional[list[str]] = None):\n    \"\"\"CLI entry point for GitHub Copilot OAuth authentication.\"\"\"\n    import argparse\n\n    parser = argparse.ArgumentParser(\n        description=\"GitHub Copilot OAuth Authentication for gpt4free\",\n        formatter_class=argparse.RawDescriptionHelpFormatter,\n        epilog=\"\"\"\nExamples:\n  %(prog)s login                    # Interactive device code login\n  %(prog)s status                   # Check authentication status\n  %(prog)s logout                   # Remove saved credentials","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/github/GithubCopilot.py#L324-L360","documentation":"A RuntimeError raised in get_quota() when the GitHub copilot_internal/user API returns any non-200 status. The response body text is embedded so the developer can see GitHub's actual error (401 bad token, 403 no Copilot subscription, 404 wrong editor headers, etc.). It is a generic catch-all because the quota endpoint has several failure modes.","triggerScenarios":"GET https://api.github.com/copilot_internal/user with a token whose Copilot entitlement lapsed (403), an expired/revoked GitHub token (401), or wrong editor-version headers (404), after credentials passed the existence check in error 64.","commonSituations":"Copilot subscription expired or was removed from the account; token valid for GitHub but not entitled to Copilot; GitHub API transient 5xx; API version header mismatch after a library update.","solutions":["Read the embedded status/text: 401/403 means re-run 'g4f auth github-copilot' and confirm the account still has a Copilot subscription","Retry once after a short delay for 5xx responses","Update the g4f library so EDITOR_VERSION/EDITOR_PLUGIN_VERSION headers match what GitHub currently accepts"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"import asyncio\n\nfor attempt in range(3):\n    try:\n        return await GithubCopilot.get_quota()\n    except RuntimeError as e:\n        msg = str(e)\n        if 'Failed to fetch Copilot usage: 5' in msg or ' 429 ' in msg:\n            await asyncio.sleep(2 ** attempt)\n            continue\n        raise  # 401/403 need re-auth, do not retry","preventionTips":["Refresh credentials proactively on 401/403 rather than retrying","Cache quota results for several minutes to avoid hammering the internal endpoint","Log the embedded status text — it distinguishes entitlement vs outage"],"tags":["quota","http-error","github-api","github-copilot"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}