# Google

Run Gemini models on the Antigravity harness with a Gemini API key, Vertex AI, or an LLM gateway.

## Overview

The Antigravity harness runs Gemini models with the prompts and tools of Google Antigravity's agent engine. Each model family runs on the harness its vendor built for it, so a Gemini model receives the instructions and tool shapes it was trained on.

A `GoogleConfig` selects the authentication method, and `AntigravityHarness::selection` names the model. The `GoogleBuilder` trait adds `.google(config)` to the runtime builder, next to `.openai` and `.claude`.

```rust
use nanocode::antigravity::{
    AntigravityHarness, GoogleBuilder, GoogleConfig,
};
use nanocode::Nanocode;

// 1. Find Google credentials in the environment
let runtime = Nanocode::builder()
    .google(GoogleConfig::default())
    .build_async()
    .await?;

// 2. Spawn an agent on the default Gemini model
let (agent, _events) = runtime
    .spawn()
    .harness_model(AntigravityHarness::selection("gemini-4-neon"))
    .build()
    .await?;
```

> [!NOTE]
> The Antigravity harness is available from Rust and `nc`. nanocode-ts supports the `claude` and `codex` providers only.

## Walkthrough

The steps below run one Gemini turn from Rust with a Gemini API key.

### Set the Key

The harness reads `GEMINI_API_KEY`, then `GOOGLE_API_KEY`, and sends requests to the Gemini API.

```bash
# Export a Gemini API key for the program
export GEMINI_API_KEY=...
```

### Run the Agent

`AuthMethod::ApiKey` requires the key and rejects a run without it, instead of falling back to Vertex AI.

```rust title="main.rs"
use nanocode::antigravity::{
    AntigravityHarness, AuthMethod, DEFAULT_MODEL, GoogleBuilder,
    GoogleConfig,
};
use nanocode::Nanocode;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>>
{
    // 1. Build the runtime with the Antigravity harness on an API key
    let runtime = Nanocode::builder()
        .google(GoogleConfig {
            method: Some(AuthMethod::ApiKey),
            ..GoogleConfig::default()
        })
        .build_async()
        .await?;

    // 2. Spawn a Gemini agent and run one turn
    let (agent, _events) = runtime
        .spawn()
        .harness_model(AntigravityHarness::selection(DEFAULT_MODEL))
        .build()
        .await?;
    let result = agent
        .prompt("Name the harness in one sentence.")
        .await?
        .await?;
    println!("{}", result.final_message());

    runtime.shutdown().await?;
    Ok(())
}
```

## Recipes

### Pick a Model

`DEFAULT_MODEL` is `gemini-4-neon`. The harness takes a Gemini model ID as a string, and `AntigravityHarness::selection` turns it into a `ModelSelection`.

In `nc`, `--harness antigravity` selects the harness, and a model ID that starts with `gemini-` selects it too. Without `--model`, the harness uses `gemini-4-neon`.

```bash
# 1. The default Gemini model
nc --harness antigravity

# 2. A Gemini model by its ID
nc -m gemini-4-neon
```

### Choose the Method

`GoogleConfig.method` and `nc --google-auth` select the method. `None` and `auto` try each method in the order of the table.

| `--google-auth`  | `AuthMethod`    | Credentials                                             |
| ---------------- | --------------- | ------------------------------------------------------- |
| `gateway`        | `Gateway`       | `AGY_LLM_GATEWAY_URL`                                   |
| `vertex-express` | `VertexExpress` | A Vertex AI key in `GOOGLE_API_KEY` or `GEMINI_API_KEY` |
| `api-key`        | `ApiKey`        | `GEMINI_API_KEY` or `GOOGLE_API_KEY`                    |
| `vertex`         | `Vertex`        | Application Default Credentials                         |

`auto` uses Vertex AI before an API key only when `GOOGLE_GENAI_USE_VERTEXAI` is `1`, `true`, or `yes`. Then a key with no configured project and no `GOOGLE_CLOUD_PROJECT` selects express mode. Without other credentials, `auto` tries Application Default Credentials last.

```bash
# Require the Gemini API and fail without a key
nc --harness antigravity --google-auth api-key
```

### Use Vertex AI

`AuthMethod::Vertex` signs requests with Application Default Credentials: `GOOGLE_OAUTH_ACCESS_TOKEN`, `GOOGLE_APPLICATION_CREDENTIALS`, the file that `gcloud auth application-default login` writes, or the metadata server.

* **Project:** `--google-project` or `GoogleConfig.project`, then `GOOGLE_CLOUD_PROJECT`, then the project `nanocode setup google` saved. After those come the credentials' project, the gcloud configuration, and a probe of the account's projects.
* **Location:** `--google-location` or `GoogleConfig.location`, then `GOOGLE_CLOUD_LOCATION`. Defaults to `global`.

```rust
use nanocode::antigravity::{AuthMethod, GoogleConfig};

// Vertex AI in one project and region
let google = GoogleConfig {
    location: Some("us-central1".into()),
    method: Some(AuthMethod::Vertex),
    project: Some("my-project".into()),
    ..GoogleConfig::default()
};
```

### Run the Setup

`nanocode setup google` prepares Vertex AI. It signs in with gcloud Application Default Credentials if needed, finds a project where the model answers, and offers to enable `aiplatform.googleapis.com`. It saves the project to `antigravity.json` in the nanocode home.

```bash
# 1. Find and save a working project
nanocode setup google

# 2. Print the resolved method, project, location, and model without changes
nanocode setup google --check
```

`--model` sets the model that the setup probes, and defaults to `gemini-4-neon`. The setup also accepts `--google-auth`, `--google-project`, and `--google-location`.

### Use Express Mode

Vertex AI express mode signs requests with a Vertex AI API key instead of credentials. `AuthMethod::VertexExpress` reads `GOOGLE_API_KEY`, then `GEMINI_API_KEY`. `GOOGLE_VERTEX_BASE_URL` replaces the global Vertex AI URL.

```bash
# A Vertex AI express mode key
GOOGLE_API_KEY=... nc --harness antigravity --google-auth vertex-express
```

### Use a Gateway

`AGY_LLM_GATEWAY_URL` sends requests to an LLM gateway. If `AGY_LLM_GATEWAY_API_KEY` is set, requests carry it as a bearer token. For the Gemini API, `GEMINI_BASE_URL` or `GOOGLE_GEMINI_BASE_URL` replaces the base URL.

```bash
# Route Gemini requests through a gateway
AGY_LLM_GATEWAY_URL=https://llm.example.com AGY_LLM_GATEWAY_API_KEY=... nc --harness antigravity
```

### Combine the Harnesses

One runtime can hold all three harnesses. Each agent selects its harness when it spawns.

```rust
use nanocode::antigravity::{GoogleBuilder, GoogleConfig};
use nanocode::{ClaudeClient, Nanocode, OpenAi};

// Codex, Claude, and Antigravity in one runtime
let runtime = Nanocode::builder()
    .openai(OpenAi::default())
    .claude(ClaudeClient::default())
    .google(GoogleConfig::default())
    .build_async()
    .await?;
```

## More

- [Claude](/docs/models/claude): Run Anthropic's models on the Claude harness.

- [Codex](/docs/models/codex): Run OpenAI's models on the Codex harness.

- [Headless Runs](/docs/guides/exec): Run nc without the terminal UI.

- [Models and Types](/docs/api/rust/types): Reference for model selection types.
