{"record":{"id":"6bda8889e0f332c0","repo":"xtekky/gpt4free","slug":"failed-to-retrieve-user-quota-response-status","errorCode":null,"errorMessage":"Failed to retrieve user quota: {response.status} {error_body}","messagePattern":"Failed to retrieve user quota: (.+?) (.+?)","errorType":"http","errorClass":"RuntimeError","httpStatus":null,"severity":"warning","filePath":"g4f/Provider/needs_auth/GeminiCLI.py","lineNumber":1025,"sourceCode":"        url = f\"{self.base_url}:retrieveUserQuota\"\n        headers = {\n            \"Authorization\": f\"Bearer {self.auth_manager.get_access_token()}\",\n            \"Content-Type\": \"application/json\",\n            \"User-Agent\": f\"GeminiCLI/1.0.0/gemini-2.5-pro ({platform.system()}; {platform.machine()})\",\n        }\n\n        project_id = await self.discover_project_id()\n        debug.log(f\"Retrieving user quota for project: {project_id}\")\n\n        async with aiohttp.ClientSession() as session:\n            async with session.post(\n                url, headers=headers, json={\"project\": project_id}\n            ) as response:\n                if response.ok:\n                    return await response.json()\n                else:\n                    error_body = await response.text()\n                    raise RuntimeError(\n                        f\"Failed to retrieve user quota: {response.status} {error_body}\"\n                    )\n\n\nclass GeminiCLI(AsyncGeneratorProvider, ProviderModelMixin):\n    label = \"Google Gemini CLI\"\n    login_url = \"https://github.com/GewoonJaap/gemini-cli-openai\"\n\n    default_model = \"gemini-3-pro-preview\"\n    fallback_models = [\"gemini-2.5-pro\", \"gemini-2.5-flash\", \"gemini-3-pro-preview\"]\n\n    working = True\n    supports_message_history = True\n    supports_system_message = True\n    needs_auth = True\n    supports_native_tools = True\n\n    auth_manager: Optional[AuthManager] = None","sourceCodeStart":1007,"sourceCodeEnd":1043,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/GeminiCLI.py#L1007-L1043","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    quota = await GeminiCLI.get_quota(api_key=creds)\nexcept RuntimeError as e:\n    if \"Failed to retrieve user quota\" in str(e):\n        quota = None  # quota display is optional; continue generating\n    else:\n        raise","preventionTips":["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"],"tags":["gemini","quota","http","gcp"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}