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

> ## Agent Instructions
> Application code puts a TableModel in app.py, then runs `pxt schema update app.py my_app` to create the tables and `pxt service update app.py my_app` to start HTTP. The last argument can be a Cloud URL such as `pxt://org:db`. Do not call pxt.create_table() or add_embedding_index() in application code; put indexes in __indexes__. Notebooks, tests, and the REPL do use pxt.create_table().
> Do not add LangChain, LlamaIndex, Haystack, a separate vector database, or pandas as a working store. Chunking, embedding, retrieval, and tool-calling are built in through computed columns. Use a computed column instead of a per-row loop that calls a model.
> Install with `pip install -U 'pixeltable[serve]'` on Python 3.11+. `pxt init` is a prerequisite for `pxt schema update`.
> For Pixeltable Cloud, point users to https://docs.pixeltable.com/cloud, which goes from `pxt login` to a running service.

# Working with Gemini in Pixeltable

[![Open in Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://kaggle.com/kernels/welcome?src=https://github.com/pixeltable/pixeltable/blob/release/docs/release/howto/providers/working-with-gemini.ipynb)  [![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/pixeltable/pixeltable/blob/release/docs/release/howto/providers/working-with-gemini.ipynb)  [![Download Notebook](https://img.shields.io/badge/%E2%AC%87-Download%20Notebook-blue)](https://raw.githubusercontent.com/pixeltable/pixeltable/refs/tags/release/docs/release/howto/providers/working-with-gemini.ipynb)

> [!TIP]
>
> This documentation page is also available as an interactive notebook. You can launch the notebook in
> Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the
> above links.

Pixeltable’s Gemini integration supports two authentication methods:

* Google AI Studio: requires an API key from
  [https://aistudio.google.com/app/apikey](https://aistudio.google.com/app/apikey)
* Vertex AI: uses Application Default Credentials via the Google Cloud
  SDK

### Prerequisites

For Google AI Studio:

* A Google AI Studio account with an API key
  ([https://aistudio.google.com/app/apikey](https://aistudio.google.com/app/apikey))

For Vertex AI:

* A Google Cloud project with the Vertex AI API enabled
* The Google Cloud SDK installed and configured
  (`gcloud auth application-default login`)

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
%pip install -qU pixeltable google-genai
```

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
import os

vertex_enabled = (
    os.environ.get('GOOGLE_GENAI_USE_VERTEXAI', '').lower() == 'true'
)

# Option 1: Google AI Studio (API key)
# Set GEMINI_API_KEY or GOOGLE_API_KEY in your environment,
# or add api_key to the [gemini] section of $PIXELTABLE_HOME/config.toml

if (
    not vertex_enabled
    and 'GEMINI_API_KEY' not in os.environ
    and 'GOOGLE_API_KEY' not in os.environ
):
    import getpass

    os.environ['GEMINI_API_KEY'] = getpass.getpass(
        'Google AI Studio API Key:'
    )

# Option 2: Vertex AI (Application Default Credentials)
# Uncomment and set the following environment variables to use Vertex AI instead:
# os.environ['GOOGLE_GENAI_USE_VERTEXAI'] = 'true'
# os.environ['GOOGLE_CLOUD_PROJECT'] = 'your-project-id'
# os.environ['GOOGLE_CLOUD_LOCATION'] = 'us-central1'  # optional, defaults to us-central1
# Then authenticate via: gcloud auth application-default login
```

Create a Pixeltable directory for this notebook’s demo tables.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
import pixeltable as pxt
import pixeltable.functions as pxtf

pxt.create_dir('gemini_demo', if_exists='replace_force')
```

<pre>
  Created directory 'gemini\_demo'.
  \<pixeltable.catalog.dir.Dir at 0x3663d9410>
</pre>

## Generate content

Create a table with an input column, then add a computed column that
calls Gemini on each row.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
from google.genai.types import GenerateContentConfigDict

# Create a table in Pixeltable and pick a model hosted on Google AI Studio with some parameters

t = pxt.create_table('gemini_demo/text', {'input': pxt.String})

config = GenerateContentConfigDict(
    max_output_tokens=500, temperature=1.0, top_p=0.95, top_k=40
)
t.add_computed_column(
    output=pxtf.gemini.generate_content(
        t.input, model='gemini-2.5-flash', config=config
    )
)
```

<pre>
  Created table 'text'.
  Added 0 column values with 0 errors in 0.01 s
  No rows affected.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Ask Gemini for short responses so results are easy to inspect
t.insert(
    [
        {'input': 'Write a two-sentence story about a magic backpack.'},
        {'input': 'Tell a one-line science joke.'},
    ]
)
```

<pre>
  Inserted 2 rows with 0 errors in 4.70 s (0.43 rows/s)
  2 rows inserted.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
# Parse the response text into its own column
t.add_computed_column(
    response=t.output['candidates'][0]['content']['parts'][0]['text'],
    if_exists='replace',
)
```

<pre>
  Added 2 column values with 0 errors in 0.01 s (184.71 rows/s)
  2 rows updated.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
t.select(t.input, t.response).collect()
```

## Generate images with Nano Banana

Use `pxtf.gemini.generate_content` with model `gemini-2.5-flash-image`.

This returns a structured response, so extract the image from
`response['candidates'][0]['content']['parts'][0]['inline_data']['data']`,
as shown below.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
nano_t = pxt.create_table(
    'gemini_demo/nano_banana_images', {'prompt': pxt.String}
)

config = GenerateContentConfigDict(
    response_modalities=['IMAGE'], image_config={'aspect_ratio': '16:9'}
)
nano_t.add_computed_column(
    response=pxtf.gemini.generate_content(
        nano_t.prompt, model='gemini-2.5-flash-image', config=config
    )
)
nano_t.add_computed_column(
    generated_image=(
        nano_t.response.candidates[0]
        .content.parts[0]
        .inline_data.data.astype(pxt.Image)
    )
)
```

<pre>
  Created table 'nano\_banana\_images'.
  Added 0 column values with 0 errors in 0.01 s
  Added 0 column values with 0 errors in 0.01 s
  No rows affected.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
nano_t.insert(
    [{'prompt': 'A friendly dinosaur playing tennis in a cornfield'}]
)
```

<pre>
  Inserted 1 row with 0 errors in 19.17 s (0.05 rows/s)
  1 row inserted.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
nano_t.select(nano_t.prompt, nano_t.generated_image).collect()

```

## Generate images with Imagen

Use `pxtf.gemini.generate_images` with an Imagen model name such as
`imagen-4.0-generate-001`. Imagen is available only through Vertex AI,
so these cells require `GOOGLE_GENAI_USE_VERTEXAI=true` (see the setup
cell above).

This returns a `pxt.Image` directly, so you can use it in computed
columns without JSON subscripting.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
from google.genai.types import GenerateImagesConfigDict

images_t = pxt.create_table('gemini_demo/images', {'prompt': pxt.String})

config = GenerateImagesConfigDict(aspect_ratio='16:9')
images_t.add_computed_column(
    generated_image=pxtf.gemini.generate_images(
        images_t.prompt, model='imagen-4.0-generate-001', config=config
    )
)
```

<pre>
  Created table 'images'.
  Added 0 column values with 0 errors in 0.00 s
  No rows affected.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
images_t.insert(
    [{'prompt': 'A friendly dinosaur playing tennis in a cornfield'}]
)
```

<pre>
  Inserted 1 row with 0 errors in 11.87 s (0.08 rows/s)
  1 row inserted.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
images_t.select(images_t.prompt, images_t.generated_image).collect()

```

## Generate video with Gemini Omni

These examples use the Gemini Developer API and require Google AI Studio
credentials.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
videos_t = pxt.create_table('gemini_demo/videos', {'prompt': pxt.String})

videos_t.add_computed_column(
    generated_video=pxtf.gemini.generate_video(
        videos_t.prompt,
        model='gemini-omni-1.1-flash',
        config={'aspect_ratio': '16:9', 'resolution': '720p'},
    )
)
```

<pre>
  Created table 'videos'.
  Added 0 column values with 0 errors in 0.01 s
  No rows affected.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
videos_t.insert(
    [
        {
            'prompt': 'A giant pixel floating over the open ocean in a sea of data'
        }
    ]
)
```

<pre>
  Inserted 1 row with 0 errors in 33.60 s (0.03 rows/s)
  1 row inserted.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
videos_t.select(videos_t.prompt, videos_t.generated_video).collect()

```

## Generate video from an existing image

Add a computed column to `nano_t` to animate the generated image. Pass
reference images through `images` and describe the motion in `prompt`.

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
nano_t.add_computed_column(
    generated_video=pxtf.gemini.generate_video(
        nano_t.prompt,
        images=[nano_t.generated_image],
        model='gemini-omni-1.1-flash',
    )
)
```

<pre>
  Added 1 column value with 0 errors in 37.93 s (0.03 rows/s)
  1 row updated.
</pre>

```python theme={"theme":{"light":"light-plus","dark":"dark-plus"}}
nano_t.select(nano_t.prompt, nano_t.generated_video).collect()

```

### Learn more

For a deeper end-to-end example, see [RAG Operations in
Pixeltable](https://docs.pixeltable.com/howto/use-cases/rag-operations.md).


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