xtekky/gpt4free · error · RuntimeError

No valid access token available for project discovery

Error message

No valid access token available for project discovery

What it means

While resolving the Google Cloud project for the request, the provider had no cached project ID (neither in-memory nor in the credentials file) and auth_manager.get_access_token() returned None, so the Cloud Resource Manager project-discovery API call cannot be made. It means authentication was never initialized or has fully expired with no refresh path.

Source

Thrown at g4f/Provider/needs_auth/Antigravity.py:1014

        # Check environment variable first
        if self.env.get("ANTIGRAVITY_PROJECT_ID"):
            return self.env["ANTIGRAVITY_PROJECT_ID"]

        # Check cached project ID
        if self._project_id:
            return self._project_id

        # Check auth manager's cached project ID (from credentials file)
        auth_project_id = self.auth_manager.get_project_id()
        if auth_project_id:
            self._project_id = auth_project_id
            return auth_project_id

        # Fall back to API discovery
        try:
            access_token = self.auth_manager.get_access_token()
            if not access_token:
                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(

View on GitHub (pinned to 973504e177)

Solutions

  1. Run the interactive login flow first so a valid access token and project ID are cached.
  2. Set ANTIGRAVITY_PROJECT_ID in the environment to skip discovery entirely — this is the fastest unblock.
  3. Ensure initialize_auth() is awaited before making requests in custom code.

Example fix

# before: request fires before auth is ready
await Antigravity.create_async_generator(...)

# after: initialize auth (or login) first
await Antigravity.auth_manager.initialize_auth()
# or pin the project explicitly:
# export ANTIGRAVITY_PROJECT_ID=my-gcp-project
Defensive patterns

Strategy: validation

Validate before calling

await Antigravity.auth_manager.initialize_auth()
assert Antigravity.auth_manager.get_access_token(), "run login first — no access token"
assert Antigravity.auth_manager.get_project_id() or os.environ.get("ANTIGRAVITY_PROJECT_ID"), "set ANTIGRAVITY_PROJECT_ID"

Type guard

def auth_ready_for_discovery(auth_manager) -> bool:
    """True when a token exists so project discovery can proceed."""
    return bool(auth_manager.get_access_token()) or bool(auth_manager.get_project_id())

Try / catch

try:
    await antigravity.create_async_generator(...)
except RuntimeError as e:
    if "No valid access token" in str(e):
        await Antigravity.login()  # then retry once
        raise

Prevention

When it happens

Trigger: Calling create_async_generator/get_quota before initialize_auth() completed, or after the token cache and refresh both failed, leaving get_access_token() == None while a project ID is still unknown.

Common situations: First use on a fresh machine without saved credentials; credentials file deleted; token refresh failing (see errors 100/101) before a project was ever cached.

Related errors


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