xtekky/gpt4free · error · MissingAuthError

Cannot fetch usage without valid authentication

Error message

Cannot fetch usage without valid authentication

What it means

get_quota() requires both a valid access token AND a resolved project ID; this MissingAuthError fires when either is absent after initialize_auth(). Quota/usage queries are per-project, so both pieces of state are mandatory. It usually means login was never completed or credentials were deleted.

Source

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

            return models
        except Exception as e:
            debug.log(f"Failed to fetch models: {e}")
            return []

    @classmethod
    async def get_quota(cls, api_key: Optional[str] = None) -> dict:
        """
        Fetch usage/quota information from the Antigravity API.
        """
        if cls.auth_manager is None:
            cls.auth_manager = AntigravityAuthManager(env=os.environ)
        await cls.auth_manager.initialize_auth()

        access_token = cls.auth_manager.get_access_token()
        project_id = cls.auth_manager.get_project_id()
        if not access_token or not project_id:
            raise MissingAuthError("Cannot fetch usage without valid authentication")

        return await cls.auth_manager.call_endpoint(
            method="fetchAvailableModels",
            body={"project": cls.auth_manager.get_project_id()},
        )

    @classmethod
    async def create_async_generator(
        cls,
        model: str,
        messages: Messages,
        stream: bool = False,
        media: MediaListType = None,
        tools: Optional[list] = None,
        **kwargs,
    ) -> AsyncResult:
        """Create an async generator for streaming responses."""
        if cls.auth_manager is None:

View on GitHub (pinned to 973504e177)

Solutions

  1. Complete the login flow (which caches token + project) before calling get_quota().
  2. Set ANTIGRAVITY_PROJECT_ID if the token is valid but the project is unknown.
  3. Catch MissingAuthError and re-prompt for authentication in long-running services.

Example fix

from g4f.errors import MissingAuthError

try:
    quota = await Antigravity.get_quota()
except MissingAuthError:
    await Antigravity.login()  # or refresh credentials interactively
    quota = await Antigravity.get_quota()
Defensive patterns

Strategy: try-catch

Validate before calling

await Antigravity.auth_manager.initialize_auth()
if not (Antigravity.auth_manager.get_access_token() and Antigravity.auth_manager.get_project_id()):
    raise MissingAuthError("login required before get_quota()")

Try / catch

from g4f.errors import MissingAuthError

try:
    quota = await Antigravity.get_quota()
except MissingAuthError:
    await Antigravity.login()
    quota = await Antigravity.get_quota()  # single retry after fresh auth

Prevention

When it happens

Trigger: Calling Antigravity.get_quota() on a machine without saved credentials, or where initialize_auth() could not restore a token (refresh failed) or where the project ID never got cached/discovered.

Common situations: Monitoring/usage-dashboards calling get_quota() before any chat request has forced login; credentials revoked; project discovery never ran.

Understand the failure class

Related errors


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