I’m working with the code provided in the official documentation for generating content using the gemini-2.5-flash-image model. However, when I run the code, I encounter the following error:
ERROR:utils.logger:Error generating thumbnail for screenshot.jpg: module ‘google.genai.types’ has no attribute ‘ImageConfig’
ERROR:utils.logger:Exception type: AttributeError
ERROR:utils.logger:Traceback (most recent call last):
generate_thumbnail_with_genai
image_config=types.ImageConfig(
^^^^^^^^^^^^^^^^^^
AttributeError: module ‘google.genai.types’ has no attribute ‘ImageConfig’
ERROR:utils.logger:Product extraction failed: Thumbnail generation failed: AttributeError: module ‘google.genai.types’ has no attribute ‘ImageConfig’
It seems that the ImageConfig attribute is not being recognized within the google.genai.types module.
I have checked the documentation, and it looks like I’m using the correct syntax. Could this issue be related to a specific version of Python or the Google GenAI library? Or is there something I’m missing in the setup or the environment?
Has anyone encountered this problem, and if so, how did you resolve it?
Could you please share your full payload along with the prompt you are using? This will help us reproduce the issue in detail and provide a more accurate analysis.
def generate_thumbnail_with_genai(screenshot_path: str, max_size_kb: int = 100):
logger.info(f"Generating thumbnail using screenshot at {screenshot_path}")
prompt = f"""
Generate a strict YouTube thumbnail designed for **desktop view (horizontally)** only,
in **landscape format (16:9 aspect ratio, 1280x720 resolution)**.
Context: Indian clothing sale.
Product Context: Pick context of products for the thumbnail directly from the image it captures.
Visuals:
- Incorporate the provided image of an Indian woman (face and appearance unchanged). The character's clothes must not be changed.
- Create a distinct outline of the character in the image to make her stand out from the background.
- The background must be vibrant, colorful, and subtly showcase a variety of elegant Indian ladies' suits.
Text & Graphics:
- Add prominent '₹' symbols and 'shocked/excited' emojis.
- Title must be large, **bold**, and **optimized for desktop thumbnail readability**, not for mobile. The font text should be highlighted and non-italic.
- Use a Hindi-English mix with catchy, sales-driven wording.
- Ensure text remains within safe thumbnail margins and is fully visible in desktop YouTube grid view.
Example Titles:
- 'Bumper Offer Abhi Grab Karo!'
- 'Naye Designs Dekho!'
- 'Sabse Sasta Deal!'
- 'Limited Stock Jaldi Karo!'
- 'Jo Dikhta Hai Wo Milta Hai!'
- 'Trustable Purchase!'
- 'High Quality Product!'
Overall:
- Professional and highly click-worthy.
- Maintain clear desktop YouTube thumbnail proportions and design standards, ensuring a strictly horizontal orientation.
"""
try:
image = Image.open(screenshot_path)
except Exception as e:
logger.error(f"Failed to open screenshot image {screenshot_path}: {str(e)}")
raise ProductExtractionError(f"Error opening screenshot image: {str(e)}")
try:
response = client.models.generate_content(
model="gemini-2.5-flash-image",
contents=[prompt, image],
config=types.GenerateContentConfig(
image_config=types.ImageConfig(
aspect_ratio="16:9",
)
),
)
# Extract generated image
for part in response.candidates[0].content.parts:
if part.inline_data is not None:
gen_image = Image.open(BytesIO(part.inline_data.data))
# gen_image = enforce_16_9(gen_image)
# Compress the image
gen_image.save("thumbnail.png")
compressed_data = compress_image_for_frontend(
gen_image,
max_size_kb=max_size_kb,
target_width=1280, # YouTube thumbnail standard
)
# Save locally (optional)
logger.info("Thumbnail generated successfully.")
# Encode compressed version
encoded = base64.b64encode(compressed_data).decode("utf-8")
logger.info(
f"Thumbnail compressed and encoded (size: {len(encoded)/1024:.2f} KB)"
)
return encoded
logger.error("Failed to generate thumbnail: No valid inline data.")
raise ProductExtractionError("Thumbnail generation failed")
except Exception as e:
import traceback
logger.error(f"Error generating thumbnail for {screenshot_path}: {str(e)}")
logger.error(f"Exception type: {type(e).__name__}")
logger.error("Traceback:\n" + traceback.format_exc())
raise ProductExtractionError(
f"Thumbnail generation failed: {type(e).__name__}: {str(e)}"
)