> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pipecat.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# GoogleDecisionsClassifier

> GoogleDecisionsClassifier and GoogleDecisionsClient answer classifier questions through Google's Decisions API.

## Overview

`GoogleDecisionsClassifier` answers [classifier questions](https://docs.pipecat.ai/api-reference/server/classifiers/overview.md) through Google's Decisions API. All the questions about one state go to Google in one request. Structured state, instructions, and descriptions are sent as JSON. Besides text, it can see images, hear clips of audio, and read files such as PDFs and videos.

A `GoogleDecisionsClassifier` asks through a `GoogleDecisionsClient`, which holds the HTTP/2 connection, retries when Google is busy, and counts tokens. Build the classifier with an API key to give it a client of its own, or pass a `GoogleDecisionsClient` to share one connection between several classifiers.

> [card] [Classifier Questions](https://github.com/pipecat-ai/pipecat/blob/main/examples/features/features-classifiers.py)
>
> Ask yes/no, choice, and score questions about a call transcript. Run with
> `--google`.

> [card] [Questions About an Image](https://github.com/pipecat-ai/pipecat/blob/main/examples/features/features-classifiers-images.py)
>
> Ask about an image, such as a frame from a camera. Run with `--google`.

## Installation

```bash theme={null}
uv add "pipecat-ai[google]"
```

## Prerequisites

A Gemini API key, usually set as an environment variable:

```bash theme={null}
GOOGLE_API_KEY=...
```

## Configuration

### GoogleDecisionsClassifier

```python theme={null}
from pipecat.classifiers.google.decisions.classifier import GoogleDecisionsClassifier
```

**api\_key** `str | None` (default: None)

Gemini API key, when the classifier should have a client of its own. One of
`api_key` and `client` is required.

**client** `GoogleDecisionsClient | None` (default: None)

A client to share with other classifiers. One of `api_key` and `client` is
required.

**model** `str` (default: gemini-decision-1)

The decision model a client of its own asks.

**timeout** `float` (default: 10.0)

Seconds a client of its own waits for an answer, retries included, before
raising `ClassifierError`.

**name** `str | None` (default: None)

Name of the classifier, as it appears in logs and metrics.

### GoogleDecisionsClient

```python theme={null}
from pipecat.classifiers.google.decisions.client import GoogleDecisionsClient
```

**api\_key** `str` *required*

Gemini API key.

**model** `str` (default: gemini-decision-1)

The decision model to ask.

**timeout** `float` (default: 10.0)

Seconds to wait for an answer, retries included, before raising
`ClassifierError`.

**max\_retries** `int` (default: 3)

How many times to retry a request that failed for a reason that may pass, such
as Google being busy, with backoff.

## Usage

### Basic Usage

```python theme={null}
import os

from pipecat.classifiers.base_classifier import YesNoQuestion
from pipecat.classifiers.google.decisions.classifier import GoogleDecisionsClassifier

classifier = GoogleDecisionsClassifier(api_key=os.getenv("GOOGLE_API_KEY"))

results = await classifier.yes_no(
    "Hi, you've reached Dana. Leave a message.",
    {"voicemail": YesNoQuestion(instructions="is this a voicemail?")},
)
results["voicemail"].is_yes
results["voicemail"].probability
```

Most of the time you don't call the classifier yourself: you pass it to a component that asks it, such as [`VoicemailDetector`](https://docs.pipecat.ai/api-reference/server/extensions/voicemail) or [`UIWorker`](https://docs.pipecat.ai/api-reference/server/workers/ui-worker).

### Sharing a Client

Several classifiers can share one `GoogleDecisionsClient`, and with it one connection pool and one token count:

```python theme={null}
from pipecat.classifiers.google.decisions.classifier import GoogleDecisionsClassifier
from pipecat.classifiers.google.decisions.client import GoogleDecisionsClient

client = GoogleDecisionsClient(api_key=os.getenv("GOOGLE_API_KEY"))

voicemail = VoicemailDetector(classifier=GoogleDecisionsClassifier(client=client))
ui_worker = MyUIWorker("ui", llm=ui_llm, classifier=GoogleDecisionsClassifier(client=client))
```

A client the classifier created is closed in the classifier's `cleanup()`. A shared client is left open, so close it yourself with `await client.close()` when every classifier using it is done.

### Asking About Images, Audio, and Files

Pass images, clips of audio, and files in `inputs=` to `ask()`, `yes_no()`, `choice()` or `score()`, as [`ClassifierImage`](https://docs.pipecat.ai/api-reference/server/classifiers/overview#classifierimage), [`ClassifierAudio`](https://docs.pipecat.ai/api-reference/server/classifiers/overview#classifieraudio) and [`ClassifierFile`](https://docs.pipecat.ai/api-reference/server/classifiers/overview#classifierfile) objects:

```python theme={null}
from pipecat.classifiers.base_classifier import ClassifierImage

image = await ClassifierImage.from_frame(frame)  # e.g. a frame from the user's camera
results = await classifier.yes_no(
    "A frame from the user's camera.",
    {"person": YesNoQuestion(instructions="Is there a person in the frame?")},
    inputs=[image],
)
```

The inputs are sent as base64 data after the state, in the order given. Clips of audio are sent as 16 kHz WAV, so `audio_sample_rate` is 16000. Files are sent as bytes or, for a `ClassifierFile` with a `url`, by URL.

### Opening the Connection Early

`setup()` opens the connection to Google ahead of the first question, so the first answer does not pay for the TLS handshake. Components that own a classifier, such as `VoicemailDetector`, call it for you. If the connection cannot be opened at setup, a warning is logged and the first question opens it instead.

## GoogleDecisionsClassifier Properties

| Property | Type | Description |
| - | - | - |
| `client` | `GoogleDecisionsClient` | The client this classifier asks through. |
| `model` | `str` | The decision model the questions go to. |
| `supports_images` | `bool` | Always `True`: the Decisions API can see images. |
| `supports_audio` | `bool` | Always `True`: the Decisions API can hear audio. |
| `audio_sample_rate` | `int` | Always `16000`: clips are resampled to 16 kHz. |
| `file_types` | `frozenset[str]` | The MIME types of the files it reads: PDFs, videos, and images and audio in many formats. |

## GoogleDecisionsClient Reference

### Properties

| Property | Type | Description |
| - | - | - |
| `model` | `str` | The decision model the questions go to. |
| `usage` | `GoogleDecisionsUsage` | Tokens used so far over every request, as `input_tokens` and `output_tokens`. |

### Methods

#### connect

```python theme={null}
await client.connect()
```

Opens the connection to Google by looking up the model, a cheap request that also checks the key and its access to the model. It connects once: a client shared by several classifiers is connected by each of them, and only the first call sends anything. Raises `ClassifierError` if Google could not be reached or refused the request.

#### close

```python theme={null}
await client.close()
```

Closes the connection pool.

## Metrics

After every call, a `GoogleDecisionsClassifier` reports the time it took as `ProcessingMetricsData` and the tokens used as `LLMUsageMetricsData` through its [`on_metrics`](https://docs.pipecat.ai/api-reference/server/classifiers/overview#on_metrics) event.

## Notes

* **Limits**: a choice question takes at most 255 options, available as `GOOGLE_DECISIONS_MAX_CHOICE_OPTIONS` in `pipecat.classifiers.google.decisions.classifier`. A question with more raises `ClassifierError` before anything is sent.
* **File types**: the MIME types of files it reads are listed in `GOOGLE_DECISIONS_FILE_TYPES` in the same module. A file of another type raises `ClassifierError`.
* **Errors**: a rejected request, a busy Google after every retry, an unreachable server, an input Google's filters blocked, or a reply missing an answer all raise `ClassifierError`.
* **Idle connections** are kept open for 240 seconds, so a gap between questions does not cost a new TLS handshake.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.