xtekky/gpt4free · error · RuntimeError

ANTIGRAVITY_SERVICE_ACCOUNT environment variable not set. Pl

Error message

ANTIGRAVITY_SERVICE_ACCOUNT environment variable not set. Please set it or create credentials at {get_antigravity_oauth_creds_path()}

What it means

RuntimeError raised in Antigravity credential resolution: no credentials file exists at either the cache path or the default path returned by get_antigravity_oauth_creds_path(), AND the ANTIGRAVITY_SERVICE_ACCOUNT environment variable is not set. The message is actionable — it names both accepted sources. This is the entry-point error for 'Antigravity is not configured at all'.

Source

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

                self._access_token = cached["access_token"]
                self._expiry = expires_at
                return  # Use cached token if valid

        # Try loading from cache file or default path
        path = AntigravityAuthManager.get_cache_file()
        if not path.exists():
            path = get_antigravity_oauth_creds_path()

        if path.exists():
            try:
                with path.open("r") as f:
                    creds = json.load(f)
            except Exception as e:
                raise RuntimeError(f"Failed to read OAuth credentials from {path}: {e}")
        else:
            # Parse credentials from environment
            if "ANTIGRAVITY_SERVICE_ACCOUNT" not in self.env:
                raise RuntimeError(
                    "ANTIGRAVITY_SERVICE_ACCOUNT environment variable not set. "
                    f"Please set it or create credentials at {get_antigravity_oauth_creds_path()}"
                )
            creds = json.loads(self.env["ANTIGRAVITY_SERVICE_ACCOUNT"])

        # Store project_id from credentials if available
        if creds.get("project_id"):
            self._project_id = creds["project_id"]

        refresh_token = creds.get("refresh_token")
        access_token = creds.get("access_token")
        expiry_date = creds.get("expiry_date")  # milliseconds since epoch

        # Use original access token if still valid
        if access_token and expiry_date:
            expires_at = expiry_date / 1000
            if expires_at - now > self.TOKEN_BUFFER_TIME:
                self._access_token = access_token

View on GitHub (pinned to 973504e177)

Solutions

  1. Export the service account JSON: export ANTIGRAVITY_SERVICE_ACCOUNT='{ ...json... }' in the same environment that runs g4f.
  2. Or create the credentials file at the path printed in the message (get_antigravity_oauth_creds_path()) containing the OAuth creds JSON.
  3. Or run the interactive Antigravity login once so the cache file is written for future runs.
  4. For Docker/CI, pass the env var explicitly: docker run -e ANTIGRAVITY_SERVICE_ACCOUNT=... ...

Example fix

# before
python app.py  # no creds file, no env var

# after
export ANTIGRAVITY_SERVICE_ACCOUNT='{"refresh_token":"...","project_id":"..."}'
python app.py
Defensive patterns

Strategy: validation

Validate before calling

import os, pathlib
configured = ('ANTIGRAVITY_SERVICE_ACCOUNT' in os.environ
              or pathlib.Path(creds_default_path).exists())
if not configured:
    raise SystemExit('Configure Antigravity: set ANTIGRAVITY_SERVICE_ACCOUNT or create the creds file')

Type guard

def antigravity_configured(env: dict, creds_path) -> bool:
    return 'ANTIGRAVITY_SERVICE_ACCOUNT' in env or creds_path.exists()

Try / catch

try:
    ...
except RuntimeError as e:
    if 'ANTIGRAVITY_SERVICE_ACCOUNT' in str(e):
        raise SystemExit('Set ANTIGRAVITY_SERVICE_ACCOUNT=<json> before using Antigravity') from e
    raise

Prevention

When it happens

Trigger: First use of the Antigravity provider with no prior interactive login (no cache file created yet) and no service account configured; the creds file created at a different path than get_antigravity_oauth_creds_path() expects; env var set in a different shell/session than the one running g4f; containerized deployment that forgot to mount creds or pass the env var.

Common situations: New users skipping the auth setup step; CI/Docker deployments missing -e ANTIGRAVITY_SERVICE_ACCOUNT=...; env vars set in .env but never exported into the process environment g4f reads.

Related errors


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