xtekky/gpt4free · error · RuntimeError
Could not discover project ID. Ensure authentication or set
Error message
Could not discover project ID. Ensure authentication or set ANTIGRAVITY_PROJECT_ID.
What it means
Generic wrapper for any exception raised during project discovery that is not MissingAuthError (network errors, HTTP errors, JSON decode failures inside _fetch_project_id). The original exception is logged via debug.error before this RuntimeError replaces it, so enable debug logging to see the root cause.
Source
Thrown at g4f/Provider/needs_auth/Antigravity.py:1032
raise RuntimeError(
"No valid access token available for project discovery"
)
async with aiohttp.ClientSession() as session:
project = await self.auth_manager._fetch_project_id(
session=session, access_token=access_token
)
if project:
self._project_id = project
return project
raise RuntimeError(
"Project ID discovery failed - set ANTIGRAVITY_PROJECT_ID in environment."
)
except MissingAuthError:
raise
except Exception as e:
debug.error(f"Failed to discover project ID: {e}")
raise RuntimeError(
"Could not discover project ID. Ensure authentication or set ANTIGRAVITY_PROJECT_ID."
)
@staticmethod
def _messages_to_gemini_format(
messages: list, media: MediaListType
) -> List[Dict[str, Any]]:
format_messages = []
for msg in messages:
# Convert a ChatMessage dict to GeminiFormattedMessage dict
role = "model" if msg["role"] == "assistant" else "user"
# Handle tool role (OpenAI style)
# Group consecutive tool responses into a single user turn so that
# the number of functionResponse parts equals the number of functionCall parts.
if msg["role"] == "tool":
tool_result = msg.get("content", "")
func_response_part = {View on GitHub (pinned to 973504e177)
Solutions
- Enable g4f debug logging to see the underlying exception text.
- Retry once for transient network/upstream failures.
- Set ANTIGRAVITY_PROJECT_ID to bypass discovery entirely.
- Fix network/proxy issues blocking googleapis.com domains.
Defensive patterns
Strategy: retry
Try / catch
try:
await antigravity.create_async_generator(...)
except RuntimeError as e:
if "Could not discover project ID" in str(e):
# transient network case: retry once; else pin ANTIGRAVITY_PROJECT_ID
raise Prevention
- Enable g4f debug logging to expose the wrapped root-cause exception
- Set ANTIGRAVITY_PROJECT_ID so discovery never runs in production
- Ensure outbound network access to googleapis.com from the runtime
When it happens
Trigger: _fetch_project_id throws aiohttp client errors (DNS, timeout, TLS), non-200 HTTP responses that raise inside the helper, or unexpected response shapes — all caught by the broad 'except Exception' and re-raised as this message.
Common situations: Transient network failure or Google API 5xx during discovery; proxy blocking googleapis.com; response schema change in the discovery endpoint.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- Token refresh failed: {text}
- All Antigravity endpoints failed. Last error: {last_error}
- No valid access token available for project discovery
- Project ID discovery failed - set ANTIGRAVITY_PROJECT_ID in
- Cannot fetch usage without valid authentication
AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14).
Data as JSON: /api/errors/98de975fc6ba0de8.
Report an issue: GitHub.