◉GEMINI LABJP
●ARGON — gemini-4-argon is generally available as of 10/13, aimed at complex coding, agents, math and science●DEEP RES — deep-research-pro-preview-12-2025 shuts down 10/23, 5 days left. Move to deep-research-preview-04-2026●NANO — gemini-nano-banana-2.1 is GA (10/06). gemini-3.1-flash-image is deprecated with no shutdown date yet●MCP — One write-up cut an 85,000-token tool result to 310 tokens by wrapping it in an ADK FunctionTool●FLASH — gemini-3.7-flash and 3.5-flash now route automatically to newer Flash models (10/08)●NEW — Stop Re-Reading Every Crash Report: Gre…●ARGON — gemini-4-argon is generally available as of 10/13, aimed at complex coding, agents, math and science●DEEP RES — deep-research-pro-preview-12-2025 shuts down 10/23, 5 days left. Move to deep-research-preview-04-2026●NANO — gemini-nano-banana-2.1 is GA (10/06). gemini-3.1-flash-image is deprecated with no shutdown date yet●MCP — One write-up cut an 85,000-token tool result to 310 tokens by wrapping it in an ADK FunctionTool●FLASH — gemini-3.7-flash and 3.5-flash now route automatically to newer Flash models (10/08)●NEW — Stop Re-Reading Every Crash Report: Gre…
Articles/API / SDK
◈ API / SDK/2026-06-22Advanced

Structured Product Image Analysis with the Gemini API — A Production Pipeline Built on Thousands of Photos

Turn a one-off image analysis script into a production pipeline that auto-generates tags, descriptions, and categories at scale — covering structured output, resumable batches, measured cost, and model routing learned from real indie-developer operation.

Gemini API250Vision4structured-output28python108batchcost-optimization30indie-dev48

✦ Premium Article

As an indie developer working on apps and store assets, I keep rediscovering how quietly the boring work — tidying up image metadata — eats my time. For a stretch I was tagging and writing descriptions for assets by hand as they grew by the hundreds. Even at a few dozen seconds each, that adds up to half a day gone.

So I switched to multimodal analysis with the Gemini API. But the first script I wrote — "send one image, get one result" — worked as a prototype yet showed its cracks the moment I pushed thousands of images through it. A single mid-run failure meant starting over, my cost estimates were too optimistic, and the category coming back would occasionally drift. After rebuilding it a few times for Dolice Labs, it settled into something that keeps running in production.

This article focuses on that delta — from a one-off prototype to a pipeline that survives failure. We'll start with the basics, then layer in measured cost, a resumable batch, and the operational details you won't find in the docs.

Prerequisites and Setup

What You'll Need

  • Python 3.10 or later
  • A Google AI Studio API key (get one at Google AI Studio)
  • The google-genai package

Setting Up Your Environment

# Create and activate a virtual environment
python -m venv gemini-image-env
source gemini-image-env/bin/activate  # Windows: gemini-image-env\Scripts\activate
 
# Install dependencies
pip install google-genai Pillow

Set your API key as an environment variable:

export GEMINI_API_KEY="your-api-key-here"

If you're new to the Gemini API, the Gemini API Quickstart Guide is a great place to start.

Basic Image Analysis — Extracting Information from a Single Product Photo

Let's start with the simplest case: sending a single product image to the Gemini API and getting a natural language description back.

# basic_image_analysis.py
import os
from google import genai
from google.genai import types
 
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
 
def analyze_product_image(image_path: str) -> str:
    """Analyze a product image and return a description."""
    with open(image_path, "rb") as f:
        image_data = f.read()
 
    response = client.models.generate_content(
        model="gemini-3.1-pro",
        contents=[
            types.Content(
                role="user",
                parts=[
                    types.Part.from_bytes(data=image_data, mime_type="image/jpeg"),
                    types.Part.from_text(
                        "Analyze this product image. Describe the product name, "
                        "category, color, material, and key features in detail."
                    ),
                ],
            )
        ],
    )
    return response.text
 
# Usage
result = analyze_product_image("product_sample.jpg")
print(result)
 
# Expected output:
# This is a white crew-neck T-shirt made from soft cotton fabric.
# It features a minimalist design with a small embroidered logo
# on the chest. The material appears to be 100% cotton, making it
# ideal for casual everyday wear.

This works well enough for a quick analysis, but the free-form text output is hard to process programmatically. Let's fix that with Structured Output.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦Measured cost, latency, and accuracy across thousands of images, plus the break-even point for routing between Flash and Pro
✦A checkpoint-based batch you can stop and resume without losing work — complete, copy-paste-ready code
✦The undocumented gotchas: enum drift, schema strictness, and pre-upload downscaling, with fixes that survive real runs
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

◈ API / SDK2026-05-16
Automating Firebase Crashlytics Analysis with Gemini API — A Real-World Implementation from an Indie App
A real-world implementation record of automating Firebase Crashlytics log analysis with Gemini API, validated during development of an indie wallpaper app (v2.1.0). Includes Before/After code for a RecyclerView crash fix and a production cost breakdown.
◈ API / SDK2026-05-14
Controlling thinking_budget in Gemini 2.5 Pro — Cut Costs by 70% Without Sacrificing Reasoning Quality
Leaving thinking_budget unset in Gemini 2.5 Pro leads to unexpected costs. This guide covers task-level budget design, dynamic control, and production monitoring with working Python code.
◈ API / SDK2026-08-22
Once You Pass Twenty Mediation Groups, How Do You Find the Setting That Went Missing?
As ad mediation groups multiply, missing sources and type drift accumulate quietly. Here is the split I settled on: normalize the settings into one matrix, let code confirm the gaps, and send Gemini only the cells that need judgment.