xtekky/gpt4free · error · MissingAuthError

GitHub Copilot OAuth not configured. Please run 'g4f auth gi

Error message

GitHub Copilot OAuth not configured. Please run 'g4f auth github-copilot' to authenticate.

What it means

Thrown by GithubCopilot.create_async_generator when no API key argument was passed and the stored OAuth credentials contain no Copilot token (creds['token'] is empty). It signals that the device-code login flow (g4f auth github-copilot) was never completed or its stored token exchange failed, so the provider has nothing to authenticate with. The library prefers raising this actionable MissingAuthError over silently failing the upstream request.

Source

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

        messages: Messages,
        api_key: Optional[str] = None,
        base_url: Optional[str] = None,
        **kwargs,
    ) -> AsyncResult:
        """
        Create an async generator for chat completions.

        If api_key is provided, it will be used directly.
        Otherwise, OAuth credentials will be used.
        """
        # If no API key provided, use OAuth token
        if not api_key:
            try:
                token_provider = cls._get_token_provider()
                creds = await token_provider.get_valid_token()
                api_key = creds.get("token")
                if not api_key:
                    raise MissingAuthError(
                        "GitHub Copilot OAuth not configured. "
                        "Please run 'g4f auth github-copilot' to authenticate."
                    )
                if not base_url:
                    base_url = creds.get("endpoint", cls.base_url)
            except TokenManagerError as e:
                if "login" in str(e).lower() or "credentials" in str(e).lower():
                    raise MissingAuthError(
                        "GitHub Copilot OAuth not configured. "
                        "Please run 'g4f auth github-copilot' to authenticate."
                    ) from e
                raise

        # Use parent class for actual API calls
        async for chunk in super().create_async_generator(
            model,
            messages,
            api_key=api_key,

View on GitHub (pinned to 973504e177)

Solutions

  1. Run 'g4f auth github-copilot' and complete the device-code flow in the browser
  2. Verify the saved credentials contain a non-empty Copilot token and delete the stale credential file before re-authenticating
  3. As a workaround, pass an explicit api_key to create_async_generator to bypass OAuth entirely

Example fix

# before
async for chunk in GithubCopilot.create_async_generator(model, messages):
    ...
# after
# terminal: g4f auth github-copilot
async for chunk in GithubCopilot.create_async_generator(model, messages):
    ...
Defensive patterns

Strategy: try-catch

Validate before calling

from g4f.Provider.github.GithubCopilot import GithubCopilot, MissingAuthError

async def has_copilot_auth() -> bool:
    try:
        tp = GithubCopilot._get_token_provider()
        creds = await tp.get_valid_token()
        return bool(creds.get("token"))
    except Exception:
        return False

Try / catch

from g4f.errors import MissingAuthError

try:
    agen = GithubCopilot.create_async_generator(model, messages)
except MissingAuthError:
    # prompt user to run 'g4f auth github-copilot' or fall back to another provider
    ...

Prevention

When it happens

Trigger: Calling create_async_generator (or any chat/completion API) on the GithubCopilot provider without api_key, when the credential file exists but the Copilot token exchange returned an empty 'token' field in get_valid_token().

Common situations: Fresh install without running the auth CLI; a partially completed device-code flow that saved GitHub credentials but never obtained the Copilot token; a corrupted or hand-edited credential file where the token key is missing/empty.

Understand the failure class

Related errors


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