Skip to content
Authentication - Antigravity SDKsdkAntigravity SDKAntigravity SDKAuthentication - Antigravity SDK Antigravity SDK Antigravity SDKAntigravity SDK

The Google Antigravity SDK supports four authentication paths: the Gemini Developer API, Gemini Enterprise Agent Platform (formerly Vertex AI) in Express Mode or Standard Mode, and offline local model inference with no credentials. You can configure credentials through environment variables, shorthand arguments on LocalAgentConfig, or explicit GeminiAPIEndpoint and VertexEndpoint objects attached to a ModelTarget.

PathConfig or endpointRequired credentialsBest for
Gemini Developer API (default)LocalAgentConfig() or GeminiAPIEndpointGEMINI_API_KEY env var or api_key="..."Fast prototyping, personal projects, and Google AI Studio keys.
Gemini Enterprise Express ModeLocalAgentConfig(vertex=True, api_key=...) or VertexEndpoint(api_key=...)Gemini Enterprise / Vertex AI API keyQuick Gemini Enterprise setup without a Google Cloud project, region, or ADC.
Gemini Enterprise Standard ModeLocalAgentConfig(vertex=True, project=..., location=...) or VertexEndpoint(project=..., location=...)Application Default Credentials (ADC), project, and locationProduction Google Cloud workloads, IAM governance, and regional endpoints.
Local and offline modelsLiteRTAgentConfig or LocalOpenAIAgentConfigNone (local .litertlm file or local base_url)On-device, air-gapped, and zero-key inference with Gemma 4, Ollama, LM Studio, or vLLM.

In all cloud modes, explicit Python keyword arguments take precedence over environment variables.


By default, LocalAgentConfig routes requests to the Gemini Developer API. Create an API key in Google AI Studio and export GEMINI_API_KEY:

export GEMINI_API_KEY="your_gemini_api_key"
import asyncio
from google.antigravity import Agent, LocalAgentConfig


async def main() -> None:
    # Reads GEMINI_API_KEY from the environment automatically
    async with Agent(LocalAgentConfig()) as agent:
        response = await agent.chat("Hello from the Gemini Developer API.")
        print(await response.text())


asyncio.run(main())

To supply the key directly in code (for example, after fetching it from a secret manager), pass api_key to LocalAgentConfig:

config = LocalAgentConfig(api_key=secret_api_key)

If neither api_key nor GEMINI_API_KEY is set, starting the agent fails with AntigravityValidationError (or RuntimeError during runtime initialization if GeminiAPIEndpoint(base_url=...) bypassed client-side validation).

Advanced endpoint options with GeminiAPIEndpoint

Section titled “Advanced endpoint options with GeminiAPIEndpoint”

Use GeminiAPIEndpoint inside a ModelTarget when you need custom proxy URLs, custom HTTP headers, an explicit API key, or GeminiModelOptions (such as thinking_level, service_tier, or max_output_tokens):

import os
from google.antigravity import (
    GeminiAPIEndpoint,
    GeminiModelOptions,
    LocalAgentConfig,
    ModelTarget,
    ThinkingLevel,
)

secret_api_key = os.environ["MY_API_KEY"]

endpoint = GeminiAPIEndpoint(
    api_key=secret_api_key,  # Omit to fall back to GEMINI_API_KEY
    base_url="https://my-gemini-gateway.example.com",
    http_headers={"X-Client-Env": "staging"},
    options=GeminiModelOptions(thinking_level=ThinkingLevel.HIGH),
)

config = LocalAgentConfig(
    api_key=secret_api_key,
    model=ModelTarget(name="gemini-4-hydrogen", endpoint=endpoint),
)

You can also redirect empty GeminiAPIEndpoint.base_url fields using the GOOGLE_GEMINI_BASE_URL environment variable (in os.environ or config.env). Precedence is: explicit GeminiAPIEndpoint(base_url=...) > config.env["GOOGLE_GEMINI_BASE_URL"] > os.environ["GOOGLE_GEMINI_BASE_URL"]. While an explicit base_url on GeminiAPIEndpoint skips Python’s preflight key validator (unlike GOOGLE_GEMINI_BASE_URL alone), the localharness runtime still requires a non-empty api_key or GEMINI_API_KEY at session start (pass your gateway key or a placeholder if your proxy authenticates with http_headers, or use VertexEndpoint(base_url=...) for gateways without an API key). GOOGLE_GEMINI_BASE_URL does not affect VertexEndpoint.


Gemini Enterprise Agent Platform (formerly Vertex AI) supports API key authentication through Express Mode, so you can call the backend without configuring a Google Cloud project, regional location, or Application Default Credentials.

Set vertex=True with api_key on LocalAgentConfig (the SDK does not read VERTEX_API_KEY from os.environ automatically, so pass the key explicitly to api_key):

import asyncio
import os
from google.antigravity import Agent, LocalAgentConfig


async def main() -> None:
    config = LocalAgentConfig(
        vertex=True,
        api_key=os.environ["VERTEX_API_KEY"],
    )
    async with Agent(config) as agent:
        response = await agent.chat("Summarize README.md in three bullets.")
        print(await response.text())


asyncio.run(main())

Or construct a VertexEndpoint directly when attaching GeminiModelOptions (passing vertex=True and api_key on LocalAgentConfig so the default ModelType.IMAGE target also uses a valid Express Mode endpoint):

import os
from google.antigravity import (
    GeminiModelOptions,
    LocalAgentConfig,
    ModelTarget,
    ThinkingLevel,
    VertexEndpoint,
)

vertex_api_key = os.environ["VERTEX_API_KEY"]

config = LocalAgentConfig(
    vertex=True,
    api_key=vertex_api_key,
    model=ModelTarget(
        name="gemini-4-hydrogen",
        endpoint=VertexEndpoint(
            api_key=vertex_api_key,
            options=GeminiModelOptions(thinking_level=ThinkingLevel.MEDIUM),
        ),
    ),
)

For Google Cloud deployments that route through regional aiplatform.googleapis.com endpoints with IAM access control, authenticate with Application Default Credentials (ADC) and provide your Google Cloud project and location.

For local development, sign in with the Google Cloud CLI:

gcloud auth application-default login

In Google Cloud runtimes (Cloud Run, GKE Workload Identity, Compute Engine) or CI workflows with Workload Identity Federation, ADC automatically discovers the attached service account credentials without running gcloud.

Configure with Python arguments or environment variables

Section titled “Configure with Python arguments or environment variables”

Pass vertex=True, project, and location on LocalAgentConfig:

import asyncio
from google.antigravity import Agent, LocalAgentConfig


async def main() -> None:
    config = LocalAgentConfig(
        vertex=True,
        project="your-gcp-project",
        location="us-central1",
    )
    async with Agent(config) as agent:
        response = await agent.chat("Hello from Gemini Enterprise.")
        print(await response.text())


asyncio.run(main())

Alternatively, export environment variables and instantiate LocalAgentConfig() with no auth arguments. Either GOOGLE_GENAI_USE_VERTEXAI or GOOGLE_GENAI_USE_ENTERPRISE (set to True or 1, case-insensitive) enables the Gemini Enterprise backend:

export GOOGLE_GENAI_USE_VERTEXAI=True  # Or: export GOOGLE_GENAI_USE_ENTERPRISE=True
export GOOGLE_CLOUD_PROJECT="your-gcp-project"
export GOOGLE_CLOUD_LOCATION="us-central1"
config = LocalAgentConfig()  # Uses VertexEndpoint with project/location from env

Both project and location must be present (from arguments or environment variables) unless api_key or a custom base_url is set. See vertex.py for a runnable script covering both Express Mode and Standard Mode.

To route Gemini Enterprise traffic through an enterprise API gateway or proxy, pass base_url and optional http_headers on VertexEndpoint:

from google.antigravity import (
    LocalAgentConfig,
    ModelTarget,
    ModelType,
    VertexEndpoint,
)

gateway_endpoint = VertexEndpoint(
    base_url="https://ai-gateway.internal.example.com/vertex",
    http_headers={"Authorization": f"Bearer {gateway_token}"},
)

config = LocalAgentConfig(
    models=[
        ModelTarget(
            name="gemini-4-hydrogen",
            types=[ModelType.TEXT],
            endpoint=gateway_endpoint,
        ),
        ModelTarget(
            name="gemini-3.1-flash-lite-image",
            types=[ModelType.IMAGE],
            endpoint=gateway_endpoint,
        ),
    ],
)

When base_url is specified on VertexEndpoint, the SDK skips auto-populating GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION from your shell environment (preventing unintended /projects/.../locations/... path rewriting) and leaves authentication checks to the gateway. Configure both ModelType.TEXT and ModelType.IMAGE targets in models (or provide valid top-level shorthand credentials): if you override model alone, LocalAgentConfig still appends and validates the default ModelType.IMAGE target at session start, even when BuiltinTools.GENERATE_IMAGE is disabled (see Models and configuration).


To run agents completely offline without cloud API keys or Google Cloud credentials, use one of the local configuration classes:

  • LiteRTAgentConfig: Runs .litertlm checkpoints (such as Gemma 4 26B A4B) directly on your GPU, NPU, or CPU through a managed local LiteRT-LM server.
  • LocalOpenAIAgentConfig: Connects to an external local server exposing an OpenAI-compatible API, such as Ollama (http://localhost:11434/v1), LM Studio (http://localhost:1234/v1), or vLLM (http://localhost:8000/v1).
import os
from google.antigravity import LiteRTAgentConfig, LocalOpenAIAgentConfig

# Managed on-device LiteRT checkpoint (no API key)
litert_config = LiteRTAgentConfig(
    model_path=os.path.expanduser(
        "~/.litert-lm/models/gemma4-26b/model.litertlm"
    ),
)

# External local OpenAI-compatible server (no API key)
ollama_config = LocalOpenAIAgentConfig(
    model="gemma4:26b",
    base_url="http://localhost:11434/v1",
).lightweight()

See Local models for installation, hardware requirements, on-device vision, and configuration options.


The table below lists all 8 environment variables read directly by the Python SDK (in addition to standard Google Cloud ADC variables such as GOOGLE_APPLICATION_CREDENTIALS in Standard Mode). Except for GOOGLE_GEMINI_BASE_URL and ANTIGRAVITY_HARNESS_PATH, these variables are validated from os.environ rather than config.env (pass api_key=... instead of setting env={"GEMINI_API_KEY": ...}):

VariableAccepted valuesUsed byDescription
GEMINI_API_KEYAPI key stringGeminiAPIEndpoint, LocalAgentConfigDefault API key for the Gemini Developer API when api_key is not passed in code.
GOOGLE_GEMINI_BASE_URLURL string (or "" in config.env to clear)LocalConnectionStrategy (GeminiAPIEndpoint)Populates empty GeminiAPIEndpoint.base_url fields. config.env overrides os.environ, and an explicit endpoint.base_url overrides both. Does not apply to VertexEndpoint.
GOOGLE_GENAI_USE_VERTEXAI"true" or "1" (case-insensitive)LocalAgentConfigSets vertex=True when vertex is not passed explicitly, switching the default endpoint to VertexEndpoint.
GOOGLE_GENAI_USE_ENTERPRISE"true" or "1" (case-insensitive)LocalAgentConfigAlias for GOOGLE_GENAI_USE_VERTEXAI that sets vertex=True for Gemini Enterprise Agent Platform when vertex is omitted.
GOOGLE_CLOUD_PROJECTGoogle Cloud project IDVertexEndpointPopulates VertexEndpoint.project in Standard Mode when neither project, api_key, nor base_url is specified.
GOOGLE_CLOUD_LOCATIONRegion (for example, "us-central1" or "global")VertexEndpointPopulates VertexEndpoint.location in Standard Mode when neither location, api_key, nor base_url is specified.
ANTIGRAVITY_HARNESS_PATHFile path to localharnessLocalConnectionStrategyOverrides automatic wheel discovery of the localharness binary. Checked in config.env first, then os.environ.
ANTIGRAVITY_ALLOW_CPU"1"LiteRTConnectionStrategySuppresses the startup warning when running LiteRTAgentConfig on a host without verified Metal or CUDA GPU acceleration.

  • Keep secrets out of source code: Read API keys and gateway tokens from environment variables or a secret manager instead of hardcoding api_key in committed files or notebooks.
  • Prefer ADC in production and CI: Use Standard Mode (vertex=True with project and location) backed by attached service accounts or Workload Identity Federation rather than long-lived API keys.
  • Be deliberate with subprocess environments: The localharness subprocess (and any allowed run_command tool calls) inherits os.environ merged with config.env. Pass keys through api_key instead of exporting ambient shell variables when enabling shell execution, and restrict run_command with Policies and sandboxing.
  • Avoid mixing endpoints accidentally: Pass explicit vertex=False if your code must target the Gemini Developer API even in shells where GOOGLE_GENAI_USE_VERTEXAI or GOOGLE_GENAI_USE_ENTERPRISE is exported.
  • Models and configuration: Configure ModelTarget, GeminiModelOptions, retries, presets, and LocalAgentConfig parameters.
  • Local models: Run agents without API keys using LiteRTAgentConfig or LocalOpenAIAgentConfig.
  • Policies and sandboxing: Enforce runtime tool approvals, workspace confinement, and OS command sandboxing.