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.
Run the same AI prompt against multiple images automatically, without
writing loops or managing API calls.
Problem
You have a collection of images that all need the same analysis—like
“Describe this image”, “Is this product damaged?”, or “What objects are
visible?”.Writing a loop to call an API for each image is tedious and error-prone.
You need to handle rate limits, retries, and track which images
succeeded or failed.
Solution
What’s in this recipe:
Analyze multiple images with a single prompt using
openai.chat_completions()
Get all results at once, stored in your table
No loops or manual API calls
You add a computed column that applies openai.chat_completions() with
multimodal messages to every image in your table. Pixeltable handles the
API calls, retries, and result storage automatically.When you insert new images, the analysis runs automatically—no extra
code needed.
Setup
%pip install -qU pixeltable openaiimport getpassimport osif 'OPENAI_API_KEY' not in os.environ: os.environ['OPENAI_API_KEY'] = getpass.getpass('OpenAI API Key: ')
Load images
import pixeltable as pxtfrom pixeltable.functions import openai# Create a fresh directorypxt.drop_dir('vision_demo', force=True)pxt.create_dir('vision_demo')
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/asiegel/.pixeltable/pgdata
Created directory ‘vision_demo’.
<pixeltable.catalog.dir.Dir at 0x12264d1b0>
t = pxt.create_table('vision_demo/images', {'image': pxt.Image})
When you insert more images, the analysis runs without any extra code:
# Insert a new image - analysis happens automaticallyt.insert( [ { 'image': 'https://raw.githubusercontent.com/pixeltable/pixeltable/main/docs/resources/images/000000000139.jpg' } ])# View all results including the new imaget.select( t.image, t.description, t.description['choices'][0]['message']['content'],).collect()
Explanation
How it works:
Add images to your table
Define a computed column with openai.chat_completions()
Pixeltable executes the API call for each row automatically
Results are cached—rerunning won’t re-call the API
New rows trigger automatic computation
Changing the prompt:To use a different prompt, add a new computed column with
if_exists='replace':