xtekky/gpt4free · error · RuntimeError

Failed to fetch Copilot usage: {resp.status} {text}

Error message

Failed to fetch Copilot usage: {resp.status} {text}

What it means

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.

Source

Thrown at g4f/Provider/github/GithubCopilot.py:342

                "Please run 'g4f auth github-copilot' to authenticate."
            )

        github_token = github_creds["access_token"]
        url = f"https://api.github.com/copilot_internal/user"
        headers = {
            "accept": "application/json",
            "authorization": f"token {github_token}",
            "editor-version": EDITOR_VERSION,
            "editor-plugin-version": EDITOR_PLUGIN_VERSION,
            "user-agent": USER_AGENT,
            "x-github-api-version": API_VERSION,
            "x-vscode-user-agent-library-version": "electron-fetch",
        }
        async with aiohttp.ClientSession() as session:
            async with session.get(url, headers=headers) as resp:
                if resp.status != 200:
                    text = await resp.text()
                    raise RuntimeError(
                        f"Failed to fetch Copilot usage: {resp.status} {text}"
                    )
                usage = await resp.json()
        return usage


async def main(args: Optional[list[str]] = None):
    """CLI entry point for GitHub Copilot OAuth authentication."""
    import argparse

    parser = argparse.ArgumentParser(
        description="GitHub Copilot OAuth Authentication for gpt4free",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog="""
Examples:
  %(prog)s login                    # Interactive device code login
  %(prog)s status                   # Check authentication status
  %(prog)s logout                   # Remove saved credentials

View on GitHub (pinned to 973504e177)

Solutions

  1. Read the embedded status/text: 401/403 means re-run 'g4f auth github-copilot' and confirm the account still has a Copilot subscription
  2. Retry once after a short delay for 5xx responses
  3. Update the g4f library so EDITOR_VERSION/EDITOR_PLUGIN_VERSION headers match what GitHub currently accepts
Defensive patterns

Strategy: retry

Try / catch

import asyncio

for attempt in range(3):
    try:
        return await GithubCopilot.get_quota()
    except RuntimeError as e:
        msg = str(e)
        if 'Failed to fetch Copilot usage: 5' in msg or ' 429 ' in msg:
            await asyncio.sleep(2 ** attempt)
            continue
        raise  # 401/403 need re-auth, do not retry

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/d623c9fc417e0f15. Report an issue: GitHub.