{"record":{"id":"4cfc7c91fb787fb5","repo":"xtekky/gpt4free","slug":"github-copilot-oauth-not-configured-please-run-g","errorCode":null,"errorMessage":"GitHub Copilot OAuth not configured. Please run 'g4f auth github-copilot' to authenticate.","messagePattern":"GitHub Copilot OAuth not configured\\. Please run 'g4f auth github-copilot' to authenticate\\.","errorType":"exception","errorClass":"MissingAuthError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/github/GithubCopilot.py","lineNumber":135,"sourceCode":"        messages: Messages,\n        api_key: Optional[str] = None,\n        base_url: Optional[str] = None,\n        **kwargs,\n    ) -> AsyncResult:\n        \"\"\"\n        Create an async generator for chat completions.\n\n        If api_key is provided, it will be used directly.\n        Otherwise, OAuth credentials will be used.\n        \"\"\"\n        # If no API key provided, use OAuth token\n        if not api_key:\n            try:\n                token_provider = cls._get_token_provider()\n                creds = await token_provider.get_valid_token()\n                api_key = creds.get(\"token\")\n                if not api_key:\n                    raise MissingAuthError(\n                        \"GitHub Copilot OAuth not configured. \"\n                        \"Please run 'g4f auth github-copilot' to authenticate.\"\n                    )\n                if not base_url:\n                    base_url = creds.get(\"endpoint\", cls.base_url)\n            except TokenManagerError as e:\n                if \"login\" in str(e).lower() or \"credentials\" in str(e).lower():\n                    raise MissingAuthError(\n                        \"GitHub Copilot OAuth not configured. \"\n                        \"Please run 'g4f auth github-copilot' to authenticate.\"\n                    ) from e\n                raise\n\n        # Use parent class for actual API calls\n        async for chunk in super().create_async_generator(\n            model,\n            messages,\n            api_key=api_key,","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/github/GithubCopilot.py#L117-L153","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","solutions":["Run 'g4f auth github-copilot' and complete the device-code flow in the browser","Verify the saved credentials contain a non-empty Copilot token and delete the stale credential file before re-authenticating","As a workaround, pass an explicit api_key to create_async_generator to bypass OAuth entirely"],"exampleFix":"# before\nasync for chunk in GithubCopilot.create_async_generator(model, messages):\n    ...\n# after\n# terminal: g4f auth github-copilot\nasync for chunk in GithubCopilot.create_async_generator(model, messages):\n    ...","handlingStrategy":"try-catch","validationCode":"from g4f.Provider.github.GithubCopilot import GithubCopilot, MissingAuthError\n\nasync def has_copilot_auth() -> bool:\n    try:\n        tp = GithubCopilot._get_token_provider()\n        creds = await tp.get_valid_token()\n        return bool(creds.get(\"token\"))\n    except Exception:\n        return False","typeGuard":null,"tryCatchPattern":"from g4f.errors import MissingAuthError\n\ntry:\n    agen = GithubCopilot.create_async_generator(model, messages)\nexcept MissingAuthError:\n    # prompt user to run 'g4f auth github-copilot' or fall back to another provider\n    ...","preventionTips":["Run 'g4f auth github-copilot' during environment provisioning, not lazily at first request","In provider-agnostic code, treat MissingAuthError as 'provider unavailable' and select a fallback provider","Add a health check that asserts stored Copilot credentials exist before starting long jobs"],"tags":["authentication","oauth","github-copilot","missing-credentials"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}