ml frameworksimpleOfficial

Gemini Integration

Call Gemini generate_content, embed_content, generate_images, and generate_videos from Pixeltable computed columns. AI Studio key or Vertex ADC.

Challenge

Gemini covers text, images, embeddings, Imagen, and Veo. An application that calls the Google GenAI client still has to store the prompt, the response JSON, and a rule for when to call again. Image generation returns inline bytes that you must decode. Vertex versus AI Studio is a second client setup. Pixeltable already has String and Image columns. The integration is pixeltable.functions.gemini: generate_content for text and Nano Banana images, embed_content for vectors, generate_images for Imagen (Vertex), and generate_videos for Veo.

Solution

pip install pixeltable google-genai. For AI Studio set GEMINI_API_KEY or GOOGLE_API_KEY. For Vertex set GOOGLE_GENAI_USE_VERTEXAI=true, GOOGLE_CLOUD_PROJECT, optional GOOGLE_CLOUD_LOCATION, and gcloud auth application-default login. Assign generate_content(body, model=gemini-2.5-flash) on the class. The return is the GenerateContent response dict; candidates[0].content.parts[0].text is the text. For gemini-2.5-flash-image, extract inline_data.data.astype(pxt.Image). embed_content.using(model=...) can sit on EmbeddingIndex. Imagen via generate_images needs Vertex. The notebook uses create_table; an app uses TableModel and pxt schema update.

Integration Steps

Step 1 of 4

One environment for Google AI Studio, another for Vertex ADC. Do not mix them in one process without a restart.

# pip install -U 'pixeltable[serve]' google-genai
# AI Studio:
# export GEMINI_API_KEY=...
# Vertex:
# export GOOGLE_GENAI_USE_VERTEXAI=true
# export GOOGLE_CLOUD_PROJECT=your-project-id
# export GOOGLE_CLOUD_LOCATION=us-central1
# gcloud auth application-default login
# pxt init
import pixeltable as pxt
from pixeltable.functions.gemini import generate_content
TableModel = pxt.model_base()

💡 The key can also live in the [gemini] section of $PIXELTABLE_HOME/config.toml as api_key. Vertex uses Application Default Credentials, not that key.

Use arrow keys to navigate

Key Benefits

One module for text, image generation, embeddings, Imagen, and Veo
AI Studio key or Vertex ADC, not two client stacks in app code
Per-row cache on generate_content
inline_data.data.astype(pxt.Image) for Nano Banana stills
embed_content.using on EmbeddingIndex

Use Cases

•Summarize stored text with gemini-2.5-flash
•Vision over an Image column in the contents list
•Generate stills from a prompt column
•Semantic search with Gemini embeddings
•Veo clips from a prompt or from a generated still

Technical Requirements

•Python 3.11+
•pip install -U 'pixeltable[serve]' google-genai
•GEMINI_API_KEY or Vertex ADC with GOOGLE_GENAI_USE_VERTEXAI=true
•Vertex for generate_images (Imagen)

Related Integrations

  • OpenAI

    Modality: Model API

    Computed column: OpenAI: Setup OpenAI Integration

    Docs
  • Anthropic

    Modality: Model API

    Computed column: Anthropic: Install and set the API key

    Docs
  • Hugging Face

    Modality: Model API

    Computed column: Hugging Face: Index images with CLIP

    Docs

Ready to Integrate Gemini?

Get started with Pixeltable and Gemini in minutes.

pip install pixeltable