2626 GeminiPart ,
2727 GeminiMimeType ,
2828)
29- from comfy_api_nodes .apis .gemini_api import GeminiImageGenerationConfig , GeminiImageGenerateContentRequest
29+ from comfy_api_nodes .apis .gemini_api import GeminiImageGenerationConfig , GeminiImageGenerateContentRequest , GeminiImageConfig
3030from comfy_api_nodes .apis .client import (
3131 ApiEndpoint ,
3232 HttpMethod ,
@@ -63,6 +63,7 @@ class GeminiImageModel(str, Enum):
6363 """
6464
6565 gemini_2_5_flash_image_preview = "gemini-2.5-flash-image-preview"
66+ gemini_2_5_flash_image = "gemini-2.5-flash-image"
6667
6768
6869def get_gemini_endpoint (
@@ -538,7 +539,7 @@ def INPUT_TYPES(cls) -> InputTypeDict:
538539 {
539540 "tooltip" : "The Gemini model to use for generating responses." ,
540541 "options" : [model .value for model in GeminiImageModel ],
541- "default" : GeminiImageModel .gemini_2_5_flash_image_preview .value ,
542+ "default" : GeminiImageModel .gemini_2_5_flash_image .value ,
542543 },
543544 ),
544545 "seed" : (
@@ -579,6 +580,14 @@ def INPUT_TYPES(cls) -> InputTypeDict:
579580 # "tooltip": "How many images to generate",
580581 # },
581582 # ),
583+ "aspect_ratio" : (
584+ IO .COMBO ,
585+ {
586+ "tooltip" : "Defaults to matching the output image size to that of your input image, or otherwise generates 1:1 squares." ,
587+ "options" : ["auto" , "1:1" , "2:3" , "3:2" , "3:4" , "4:3" , "4:5" , "5:4" , "9:16" , "16:9" , "21:9" ],
588+ "default" : "auto" ,
589+ },
590+ ),
582591 },
583592 "hidden" : {
584593 "auth_token" : "AUTH_TOKEN_COMFY_ORG" ,
@@ -600,15 +609,17 @@ async def api_call(
600609 images : Optional [IO .IMAGE ] = None ,
601610 files : Optional [list [GeminiPart ]] = None ,
602611 n = 1 ,
612+ aspect_ratio : str = "auto" ,
603613 unique_id : Optional [str ] = None ,
604614 ** kwargs ,
605615 ):
606- # Validate inputs
607616 validate_string (prompt , strip_whitespace = True , min_length = 1 )
608- # Create parts list with text prompt as the first part
609617 parts : list [GeminiPart ] = [create_text_part (prompt )]
610618
611- # Add other modal parts
619+ if not aspect_ratio :
620+ aspect_ratio = "auto" # for backward compatability with old workflows; to-do remove this in December
621+ image_config = GeminiImageConfig (aspectRatio = aspect_ratio )
622+
612623 if images is not None :
613624 image_parts = create_image_parts (images )
614625 parts .extend (image_parts )
@@ -625,7 +636,8 @@ async def api_call(
625636 ),
626637 ],
627638 generationConfig = GeminiImageGenerationConfig (
628- responseModalities = ["TEXT" ,"IMAGE" ]
639+ responseModalities = ["TEXT" ,"IMAGE" ],
640+ imageConfig = None if aspect_ratio == "auto" else image_config ,
629641 )
630642 ),
631643 auth_kwargs = kwargs ,
0 commit comments