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 4One 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 initimport pixeltable as pxtfrom pixeltable.functions.gemini import generate_contentTableModel = 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.
Key Benefits
Use Cases
Technical Requirements
Related articles
Ready to Integrate Gemini?
Get started with Pixeltable and Gemini in minutes.
pip install pixeltable