xtekky/gpt4free · warning · RuntimeError
Failed to retrieve user quota: {response.status} {error_body
Error message
Failed to retrieve user quota: {response.status} {error_body} What it means
The quota lookup POST (get_quota) sent {'project': project_id} to the Code Assist quota endpoint and got a non-OK response; status and body are embedded. This is an informational endpoint used to report remaining quota, so failure usually mirrors a bad project ID, an auth problem, or a quota endpoint change.
Source
Thrown at g4f/Provider/needs_auth/GeminiCLI.py:1025
url = f"{self.base_url}:retrieveUserQuota"
headers = {
"Authorization": f"Bearer {self.auth_manager.get_access_token()}",
"Content-Type": "application/json",
"User-Agent": f"GeminiCLI/1.0.0/gemini-2.5-pro ({platform.system()}; {platform.machine()})",
}
project_id = await self.discover_project_id()
debug.log(f"Retrieving user quota for project: {project_id}")
async with aiohttp.ClientSession() as session:
async with session.post(
url, headers=headers, json={"project": project_id}
) as response:
if response.ok:
return await response.json()
else:
error_body = await response.text()
raise RuntimeError(
f"Failed to retrieve user quota: {response.status} {error_body}"
)
class GeminiCLI(AsyncGeneratorProvider, ProviderModelMixin):
label = "Google Gemini CLI"
login_url = "https://github.com/GewoonJaap/gemini-cli-openai"
default_model = "gemini-3-pro-preview"
fallback_models = ["gemini-2.5-pro", "gemini-2.5-flash", "gemini-3-pro-preview"]
working = True
supports_message_history = True
supports_system_message = True
needs_auth = True
supports_native_tools = True
auth_manager: Optional[AuthManager] = NoneView on GitHub (pinned to 973504e177)
Solutions
- Read the embedded status and body to distinguish 401/403 (auth or project) from 5xx (transient)
- Confirm the project id is valid and Code Assist-enabled, or unset GEMINI_PROJECT_ID to let discovery choose
- Re-login to refresh the access token
- Update g4f to the latest version
Defensive patterns
Strategy: try-catch
Try / catch
try:
quota = await GeminiCLI.get_quota(api_key=creds)
except RuntimeError as e:
if "Failed to retrieve user quota" in str(e):
quota = None # quota display is optional; continue generating
else:
raise Prevention
- Treat quota lookup as best-effort; never hard-fail the request path on it
- Ensure GEMINI_PROJECT_ID, if set, refers to a Code Assist-enabled project
When it happens
Trigger: Calling GeminiCLI.get_quota() after discover_project_id when the quota endpoint returns 4xx or 5xx — for example invalid project id, expired token, or endpoint moved.
Common situations: GEMINI_PROJECT_ID points to a project without the API enabled; token expired between discovery and quota call; g4f version out of sync with the internal quota API.
Related errors
- API call failed with status {resp.status}: {text}
- Token refresh failed: {text}
- No project information found in API response.
- Could not discover project ID. Ensure authentication or set
- Token exchange failed: {error_text}
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/6bda8889e0f332c0.
Report an issue: GitHub.