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.

Solutions

  1. Enable g4f debug logging to see the underlying exception text.
  2. Retry once for transient network/upstream failures.
  3. Set ANTIGRAVITY_PROJECT_ID to bypass discovery entirely.
  4. 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

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

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/98de975fc6ba0de8. Report an issue: GitHub.

Appendix: 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)