BerriAI/litellm · error · GetAPIKeyError
Failed to refresh API key
Error message
Failed to refresh API key: {e} What it means
Error "Failed to refresh API key: {e}" thrown in BerriAI/litellm.
Solutions
- Read the wrapped exception; the Copilot token refresh failed. Re-authenticate via the OAuth Device Flow if it persists.
When it happens
Trigger: Thrown at litellm/llms/github_copilot/authenticator.py:126 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/0e2c9cce71770618.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/github_copilot/authenticator.py:126
api_key_info = self._refresh_api_key()
with open(self.api_key_file, "w") as f:
json.dump(api_key_info, f)
token: Final = api_key_info.get("token")
if token:
return token
else:
raise GetAPIKeyError(
message="API key response missing token",
status_code=401,
)
except OSError as e:
verbose_logger.error("Error saving API key to file: %s", e)
raise GetAPIKeyError(
message=f"Failed to save API key: {e}",
status_code=500,
)
except RefreshAPIKeyError as e:
raise GetAPIKeyError(
message=f"Failed to refresh API key: {e}",
status_code=401,
)
def get_api_base(self) -> str | None:
"""
Get the API endpoint from the api-key.json file.
Returns:
Optional[str]: The GitHub Copilot API endpoint, or None if not found.
"""
try:
with open(self.api_key_file, "r") as f:
api_key_info: Final = json.load(f)
endpoints: Final = api_key_info.get("endpoints", {})
api_endpoint: Final = endpoints.get("api")
return api_endpoint
except (OSError, json.JSONDecodeError, KeyError) as e:View on GitHub (pinned to 77b7c6c40c)