Google Gen AI Image Config | Generated by AI

Home 2025.08

Here’s a quick overview: the image_size parameter isn’t supported in the Google Gen AI (Gemini/Imagen) Python SDK. Instead, you select among model variants (which each have implicit default resolutions), control the aspect ratio, and—if you need higher pixel counts—apply an upscale. You can also tweak compression and output format, plus the usual “number of images,” “negative prompt,” “safety” and “person” settings.

Model Variants

You choose a model name—each variant has its own default resolution and performance profile:

Default Resolution

By default, a square (“1:1”) output from these models is 1024 × 1024 pixels. If you need a smaller file, you can downsample locally; if you need higher resolution, see Upscaling below. (raymondcamden.com)

Aspect Ratios

Rather than specifying absolute dimensions, use the aspect_ratio field in your GenerateImagesConfig. Supported values:

You’ll find the same list documented in community tutorials:

Upscaling

If you need true “2K” or “4K” outputs, call the upscale mode:

from google.genai import types
config = types.GenerateImagesConfig(
    mode="upscale",
    upscale_config=types.UpscaleConfig(upscale_factor="x2"),
)

Compression & Formats

Additional Config Options

Everything else lives in GenerateImagesConfig:

config = types.GenerateImagesConfig(
    number_of_images=1,           # how many images to generate
    seed=1234,                    # for deterministic outputs
    enhance_prompt=True,          # LLM-based prompt rewriting
    negative_prompt="exclude dogs",
    language="en",
    safety_filter_level="block_medium_and_above",  
    person_generation="allow_adult",
)

These let you control randomness, prompt enhancement, safety thresholds, and whether the model can include people. (Google Cloud)

Recommendation

Remove your image_size="2K" line—there is no such flag. Instead:

  1. Pick the right model for speed vs. quality.
  2. Use aspect_ratio for framing.
  3. If you truly need higher pixel counts, generate at base resolution then apply the built-in upscale (“x2” or “x4”).
  4. Tweak compression_quality or downsample locally for smaller files.

With these knobs you can achieve square or cinematic framing, small or high-res outputs, without an unsupported image_size parameter.


Back Donate