> ## Documentation Index
> Fetch the complete documentation index at: https://patter-06b046ce-feat-gemini-3x-catalog.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Google

> Google Gemini LLM provider — Developer API or Vertex AI, streaming with function calling.

# Google Gemini LLM

`GoogleLLM` plugs Google Gemini chat models into Patter's pipeline mode via the `google-genai` SDK. It supports both the Gemini Developer API (with an API key) and Vertex AI (with GCP project + location). Streams normalise to Patter's unified `{type: "text" | "tool_call" | "done"}` chunk protocol, and Gemini `function_call` parts map directly onto Patter tools.

<Note>
  This page covers Google Gemini in **chat-completions** mode for the pipeline (STT → LLM → TTS). For Gemini's bidirectional speech-to-speech engine, see the separate `gemini-live` adapter under [Engines](/python-sdk/engines).
</Note>

## Install

```bash theme={null}
pip install "getpatter[google]"
```

```bash theme={null}
npm install getpatter
```

## Usage

<CodeGroup>
  ```python Python theme={null}
  # Namespaced import
  from getpatter.llm import google

  llm = google.LLM()                                          # reads GEMINI_API_KEY (or GOOGLE_API_KEY)
  llm = google.LLM(api_key="AIza...", model="gemini-2.5-flash")

  # Vertex AI
  llm = google.LLM(
      vertexai=True,
      project="my-gcp-project",
      location="us-central1",
  )

  # Flat alias (equivalent)
  from getpatter import GoogleLLM

  llm = GoogleLLM()
  ```

  ```ts TypeScript theme={null}
  // Namespaced import
  import * as google from "getpatter/llm/google";

  const llm = new google.LLM();                               // reads GEMINI_API_KEY or GOOGLE_API_KEY
  const llm = new google.LLM({ apiKey: "AIza...", model: "gemini-2.5-flash" });

  // Flat alias (equivalent)
  import { GoogleLLM } from "getpatter";

  const llm2 = new GoogleLLM();
  ```
</CodeGroup>

<Note>
  The namespaced import (`from getpatter.llm import google` / `import * as google from "getpatter/llm/google"`) auto-resolves the API key from `GEMINI_API_KEY` first, then `GOOGLE_API_KEY` for parity with other SDKs, and exposes a uniform `LLM` class.
</Note>

Plug it into an agent:

<CodeGroup>
  ```python Python theme={null}
  import asyncio
  from getpatter import Patter, Twilio, DeepgramSTT, GoogleLLM, ElevenLabsTTS

  phone = Patter(carrier=Twilio(), phone_number="+15550001234")

  agent = phone.agent(
      stt=DeepgramSTT(),
      llm=GoogleLLM(),                                        # GEMINI_API_KEY from env
      tts=ElevenLabsTTS(voice_id="rachel"),
      system_prompt="You are a helpful assistant.",
      first_message="Hi, how can I help?",
  )

  asyncio.run(phone.serve(agent))
  ```

  ```ts TypeScript theme={null}
  import { Patter, Twilio, DeepgramSTT, GoogleLLM, ElevenLabsTTS } from "getpatter";

  const phone = new Patter({ carrier: new Twilio(), phoneNumber: "+15550001234" });

  const agent = phone.agent({
    stt: new DeepgramSTT(),
    llm: new GoogleLLM(),                                     // GEMINI_API_KEY from env
    tts: new ElevenLabsTTS({ voiceId: "rachel" }),
    systemPrompt: "You are a helpful assistant.",
    firstMessage: "Hi, how can I help?",
  });

  await phone.serve(agent);
  ```
</CodeGroup>

## Supported models

Pricing in USD per 1M tokens.

| Model                             | Input  | Output  | Notes                                                                                |
| --------------------------------- | ------ | ------- | ------------------------------------------------------------------------------------ |
| `gemini-3.7-flash`                | \$0.75 | \$3.75  | Latest, most capable Flash — GA 2026-08-13. Steps up to $1.50 / $7.50 on 2027-01-01. |
| `gemini-3.6-flash`                | \$0.75 | \$3.75  | Same rate card as 3.7-flash. Steps up to $1.50 / $7.50 on 2027-01-01.                |
| `gemini-3.5-flash`                | \$1.50 | \$9.00  |                                                                                      |
| `gemini-3.5-flash-lite` (default) | \$0.30 | \$2.50  | Best price/perf for voice.                                                           |
| `gemini-3.1-flash-lite`           | \$0.25 | \$1.50  |                                                                                      |
| `gemini-3.1-pro-preview`          | \$2.00 | \$12.00 | Preview. Rate for prompts ≤200k tokens.                                              |
| `gemini-3-flash-preview`          | \$0.50 | \$3.00  | Preview.                                                                             |
| `gemini-2.5-flash`                | \$0.30 | \$2.50  |                                                                                      |
| `gemini-2.5-pro`                  | \$1.25 | \$10.00 | Highest quality. Rate for prompts ≤200k tokens.                                      |

`gemini-2.0-flash`, `gemini-2.0-flash-lite`, `gemini-1.5-flash`, and `gemini-1.5-pro` are shut down and no longer supported.

For the speech-to-speech variants — `gemini-3.1-flash-live-preview` (text in $0.75 / out $4.50, audio in $3.00/1M tokens = $0.005/min / out $12.00/1M tokens = $0.018/min) and `gemini-2.5-flash-native-audio-preview` (text in $0.50 / out $2.00, audio in $3.00 / out $12.00) — see the [Engines](/python-sdk/engines) page; they are separate Realtime adapters, not chat-completions models.

## Environment variables

| Variable                    | Required     | Notes                                            |
| --------------------------- | ------------ | ------------------------------------------------ |
| `GEMINI_API_KEY`            | one of these | Preferred — Google's CLI tooling uses this name. |
| `GOOGLE_API_KEY`            | one of these | Legacy/alt name accepted for parity.             |
| `GOOGLE_GENAI_USE_VERTEXAI` | optional     | Set to `1` / `true` to default `vertexai=True`.  |
| `GOOGLE_CLOUD_PROJECT`      | Vertex AI    | GCP project ID when `vertexai=True`.             |
| `GOOGLE_CLOUD_LOCATION`     | Vertex AI    | GCP region (defaults to `us-central1`).          |

## Options

| Option                                  | Default                   | Notes                                                                        |
| --------------------------------------- | ------------------------- | ---------------------------------------------------------------------------- |
| `api_key` / `apiKey`                    | `None`                    | Reads `GEMINI_API_KEY`, then `GOOGLE_API_KEY`. Ignored when `vertexai=True`. |
| `model`                                 | `"gemini-3.5-flash-lite"` | Any Gemini chat model id.                                                    |
| `vertexai`                              | `False`                   | Use Vertex AI instead of the Developer API.                                  |
| `project`                               | `None`                    | GCP project (Vertex AI).                                                     |
| `location`                              | `"us-central1"`           | GCP region (Vertex AI).                                                      |
| `temperature`                           | unset                     | Optional sampling temperature.                                               |
| `max_output_tokens` / `maxOutputTokens` | unset                     | Output token cap.                                                            |

## Vertex AI

Switch to Vertex AI when you need GCP-native auth (service accounts), VPC Service Controls, regional residency, or per-project billing isolation.

```python theme={null}
from getpatter.llm import google

llm = google.LLM(
    vertexai=True,
    project="my-gcp-project",
    location="europe-west4",                               # GoogleVertexLocation enum
    model="gemini-2.5-pro",
)
```

The `google-genai` SDK picks up Application Default Credentials automatically — set `GOOGLE_APPLICATION_CREDENTIALS` to a service-account key path or run `gcloud auth application-default login` for local dev.

## Function calling

Gemini's `function_call` parts map directly onto Patter tools — define a tool once and it works on every LLM provider. Patter assigns a monotonically increasing index per `function_call` part since Gemini does not provide a stable per-call index across stream chunks. Token usage is collected from `usage_metadata` (cumulative on each chunk; only the last value is yielded as a `usage` event to avoid double-counting).
