Flask, Gemini 2.0, and Cloud Run Compatibility Issues

Hi everyone,

I’m developing a Flask server deployed on Google Cloud Run that processes images using Google Vision API for OCR and Gemini 2.0 Pro to extract and structure data.

Goal:
I want to use the new functionality described in the official Gemini documentation, which involves:

from google import genai

client = genai.Client(api_key="MY_API_KEY")

Then calling the model like:

response = client.models.generate_content(...)

The issue:

  1. ImportError when using from google import genai:
  • On versions prior to google-generativeai >= 0.5.0, the import fails or genai.Client doesn’t exist.
  • After upgrading, it works locally, but fails when deployed on Cloud Run.
  1. Cloud Run logs errors such as:
ImportError: cannot import name 'genai' from 'google' (unknown location)

This suggests possible dependency conflicts or environment issues in production.

Environment and configuration:
requirements.txt:

flask
google-cloud-vision
google-cloud-language
google-cloud-translate
google-generativeai>=0.8.0
cryptography
gunicorn

Dockerfile:

FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8080
CMD ["gunicorn", "-b", "0.0.0.0:8080", "app:app"]

Cloud Run:

  • Deployed in europe-southwest1
  • Using GEMINI_API_KEY as an environment variable

Cloud console:

$ pip list | grep google-generativeai
google-generativeai                   0.8.4

$ python --version
Python 3.12.3

Questions:

Are there any known compatibility issues between from google import genai and production deployments in Cloud Run?

Is there any special setup required (in Docker, Python, or auth) to make genai.Client() work correctly in a Flask server?

1 Like