xtekky/gpt4free · error · TokenManagerError
NO_TOKEN
NO_TOKEN
Error message
No GitHub OAuth token available. Please login first.
What it means
TokenManagerError with code NO_TOKEN, raised in CopilotTokenProvider when the cached Copilot token is absent/expired and the shared manager has no stored GitHub OAuth credentials to exchange. This is the root-cause error that GithubCopilot surfaces as the 'OAuth not configured' MissingAuthError (errors 60-62).
Source
Thrown at g4f/Provider/github/copilotTokenProvider.py:49
self._copilot_token_expires_at = 0
async def get_copilot_token(self) -> Optional[str]:
"""
Get a valid Copilot API token.
This exchanges the GitHub OAuth token for a Copilot-specific token.
Returns:
The Copilot API token, or None if not available.
"""
# Check if we have a valid cached token
if self._copilot_token and time.time() < self._copilot_token_expires_at - 60:
return self._copilot_token
# Get GitHub OAuth token
github_creds = await self.shared_manager.getValidCredentials(self.github_client)
if not github_creds or not github_creds.get("access_token"):
raise TokenManagerError(
"NO_TOKEN", "No GitHub OAuth token available. Please login first."
)
github_token = github_creds["access_token"]
# Exchange for Copilot token
async with aiohttp.ClientSession() as session:
async with session.get(
self.COPILOT_TOKEN_URL,
headers={
"Authorization": f"token {github_token}",
"Accept": "application/json",
"User-Agent": USER_AGENT,
"Editor-Version": EDITOR_VERSION,
"Editor-Plugin-Version": EDITOR_PLUGIN_VERSION,
"Openai-Organization": "github-copilot",
"X-GitHub-Api-Version": API_VERSION,
},View on GitHub (pinned to 973504e177)
Solutions
- Run 'g4f auth github-copilot' to store GitHub OAuth credentials
- Verify the credential file path resolves to the same location in the process that reads it (check HOME and XDG vars in services/containers)
- If tokens must be injected externally, write a valid credentials file with an access_token matching the expected schema
Defensive patterns
Strategy: try-catch
Try / catch
from g4f.Provider.github.sharedTokenManager import TokenManagerError
try:
token = await provider.get_valid_token()
except TokenManagerError as e:
if e.code == 'NO_TOKEN':
# trigger device-code login flow or switch provider
... Prevention
- Branch on TokenManagerError.code rather than parsing message strings
- Run login during provisioning so NO_TOKEN never occurs at request time
- Verify credential file presence in container health checks
When it happens
Trigger: Calling get_valid_token()/getCopilotToken() when the credentials file is missing, empty, or has no access_token, and the in-memory Copilot token cache is cold (first call or >expiry-60s since last exchange).
Common situations: First use after install; credentials stored under a different user/HOME (Docker, systemd service, cron); logout or credential-file cleanup between runs.
Related errors
- GitHub Copilot OAuth not configured. Please run 'g4f auth gi
- device_code is required for polling
- AUTH_FAILED
- Token refresh failed: {text}
- No access_token in refresh response.
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/c3e5f35e1e59f8ca.
Report an issue: GitHub.