BerriAI/litellm · error · GetAPIKeyError
Failed to save API key
Error message
Failed to save API key: {e} What it means
Error "Failed to save API key: {e}" thrown in BerriAI/litellm.
Solutions
- Saving the API key to disk failed; check write permissions on the litellm copilot token cache path.
When it happens
Trigger: Thrown at litellm/llms/github_copilot/authenticator.py:121 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/7a71d39bf9040d66.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/github_copilot/authenticator.py:121
verbose_logger.warning("Error reading API key from file: %s", e)
except APIKeyExpiredError:
pass # Already logged in the try block
try:
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:View on GitHub (pinned to 77b7c6c40c)