@@ -34,9 +34,14 @@ const DEFAULT_FAL_EDIT_SUBPATH = "image-to-image";
3434const FAL_KREA_2_MODEL_PREFIX = "krea/v2/" ;
3535const FAL_KREA_2_MEDIUM_MODEL = "krea/v2/medium/text-to-image" ;
3636const FAL_KREA_2_LARGE_MODEL = "krea/v2/large/text-to-image" ;
37+ const FAL_NANO_BANANA_MODEL = "fal-ai/nano-banana" ;
38+ const FAL_NANO_BANANA_2_LITE_MODEL = "google/nano-banana-2-lite" ;
39+ const FAL_GROK_IMAGINE_MODEL = "xai/grok-imagine-image" ;
3740const DEFAULT_OUTPUT_FORMAT = "png" ;
3841const GPT_IMAGE_EDIT_MAX_INPUT_IMAGES = 10 ;
42+ const NANO_BANANA_LEGACY_EDIT_MAX_INPUT_IMAGES = 3 ;
3943const NANO_BANANA_EDIT_MAX_INPUT_IMAGES = 14 ;
44+ const GROK_IMAGINE_EDIT_MAX_INPUT_IMAGES = 3 ;
4045const KREA_STYLE_REFERENCE_MAX_INPUT_IMAGES = 10 ;
4146const FAL_OUTPUT_FORMATS = [ "png" , "jpeg" ] as const ;
4247const FAL_SUPPORTED_SIZES = [
@@ -73,6 +78,18 @@ const KREA_SUPPORTED_ASPECT_RATIOS = [
7378 "2:3" ,
7479 "9:16" ,
7580] as const ;
81+ const NANO_BANANA_LEGACY_SUPPORTED_ASPECT_RATIOS = [
82+ "21:9" ,
83+ "16:9" ,
84+ "3:2" ,
85+ "4:3" ,
86+ "5:4" ,
87+ "1:1" ,
88+ "4:5" ,
89+ "3:4" ,
90+ "2:3" ,
91+ "9:16" ,
92+ ] as const ;
7693const NANO_BANANA_SUPPORTED_ASPECT_RATIOS = [
7794 "21:9" ,
7895 "16:9" ,
@@ -89,20 +106,39 @@ const NANO_BANANA_SUPPORTED_ASPECT_RATIOS = [
89106 "8:1" ,
90107 "1:8" ,
91108] as const ;
109+ const GROK_IMAGINE_SUPPORTED_ASPECT_RATIOS = [
110+ "2:1" ,
111+ "20:9" ,
112+ "19.5:9" ,
113+ "16:9" ,
114+ "4:3" ,
115+ "3:2" ,
116+ "1:1" ,
117+ "2:3" ,
118+ "3:4" ,
119+ "9:16" ,
120+ "9:19.5" ,
121+ "9:20" ,
122+ "1:2" ,
123+ ] as const ;
124+ const GROK_IMAGINE_SUPPORTED_RESOLUTIONS : readonly ( "1K" | "2K" | "4K" ) [ ] = [ "1K" , "2K" ] as const ;
92125const KREA_CREATIVITY_LEVELS = [ "raw" , "low" , "medium" , "high" ] as const ;
93126
94127const FAL_IMAGE_MALFORMED_RESPONSE = "fal image generation response malformed" ;
95128const DEFAULT_GENERATED_IMAGE_MAX_BYTES = 6 * 1024 * 1024 ;
96129
97130type FalImageSize = string | { width : number ; height : number } ;
131+ type FalEditEndpointSuffix = "edit" | "image-to-image" ;
98132type FalImageModelSchema = {
99133 geometry : "image_size" | "native_aspect_ratio" ;
100134 aspectRatios ?: readonly string [ ] ;
135+ resolutions ?: readonly ( "1K" | "2K" | "4K" ) [ ] ;
136+ resolutionCase ?: "lower" ;
101137 referenceImages : "image_url" | "image_urls" | "image_style_references" ;
102138 maxInputImages : number ;
103139 referenceLimitLabel : string ;
104140 referenceLimitNoun : "reference image" | "style reference" ;
105- appendEditPath : false | "edit" | "image-to-image" ;
141+ appendEditPath : false | FalEditEndpointSuffix ;
106142 supportsCount : boolean ;
107143 supportsOutputFormat : boolean ;
108144 defaultBody ?: Record < string , unknown > ;
@@ -178,24 +214,18 @@ function resolveFalNetworkPolicy(params: {
178214function ensureFalModelPath ( model : string | undefined , hasInputImages : boolean ) : string {
179215 const trimmed = model ?. trim ( ) || DEFAULT_FAL_IMAGE_MODEL ;
180216 const schema = resolveFalImageModelSchema ( trimmed ) ;
181- if ( hasInputImages && schema . appendEditPath === false ) {
182- return trimmed ;
183- }
184- if ( ! hasInputImages ) {
217+ if ( ! hasInputImages || schema . appendEditPath === false ) {
185218 return trimmed ;
186219 }
187220 if (
221+ trimmed . endsWith ( `/${ schema . appendEditPath } ` ) ||
188222 trimmed . endsWith ( "/edit" ) ||
189223 trimmed . endsWith ( `/${ DEFAULT_FAL_EDIT_SUBPATH } ` ) ||
190224 trimmed . includes ( "/image-to-image/" )
191225 ) {
192226 return trimmed ;
193227 }
194- // GPT Image 2 and Nano Banana 2 use /edit; Flux uses /image-to-image.
195- if ( trimmed . startsWith ( "openai/gpt-image-" ) || trimmed . startsWith ( "fal-ai/nano-banana-" ) ) {
196- return `${ trimmed } /edit` ;
197- }
198- return `${ trimmed } /${ DEFAULT_FAL_EDIT_SUBPATH } ` ;
228+ return `${ trimmed } /${ schema . appendEditPath } ` ;
199229}
200230
201231function resolveFalImageModelSchema ( model : string ) : FalImageModelSchema {
@@ -213,8 +243,22 @@ function resolveFalImageModelSchema(model: string): FalImageModelSchema {
213243 defaultBody : { creativity : "medium" } ,
214244 } ;
215245 }
216- if ( model . startsWith ( "openai/gpt-image-" ) || model . startsWith ( "fal-ai/nano-banana-" ) ) {
217- const isNanoBanana = model . startsWith ( "fal-ai/nano-banana-" ) ;
246+ if ( model === FAL_NANO_BANANA_MODEL || model . startsWith ( `${ FAL_NANO_BANANA_MODEL } /` ) ) {
247+ return {
248+ geometry : "native_aspect_ratio" ,
249+ aspectRatios : NANO_BANANA_LEGACY_SUPPORTED_ASPECT_RATIOS ,
250+ resolutions : [ ] ,
251+ referenceImages : "image_urls" ,
252+ maxInputImages : NANO_BANANA_LEGACY_EDIT_MAX_INPUT_IMAGES ,
253+ referenceLimitLabel : "fal Nano Banana" ,
254+ referenceLimitNoun : "reference image" ,
255+ appendEditPath : "edit" ,
256+ supportsCount : true ,
257+ supportsOutputFormat : true ,
258+ } ;
259+ }
260+ if ( model . startsWith ( "openai/gpt-image-" ) || model . startsWith ( `${ FAL_NANO_BANANA_MODEL } -` ) ) {
261+ const isNanoBanana = model . startsWith ( `${ FAL_NANO_BANANA_MODEL } -` ) ;
218262 return {
219263 geometry : isNanoBanana ? "native_aspect_ratio" : "image_size" ,
220264 ...( isNanoBanana ? { aspectRatios : NANO_BANANA_SUPPORTED_ASPECT_RATIOS } : { } ) ,
@@ -229,6 +273,41 @@ function resolveFalImageModelSchema(model: string): FalImageModelSchema {
229273 supportsOutputFormat : true ,
230274 } ;
231275 }
276+ // Nano Banana 2 Lite (Gemini 3.1 Flash Lite Image) uses /edit and the same
277+ // aspect_ratio/image_urls contracts as Nano Banana 2. Its published schema
278+ // has no resolution field, so explicit resolution overrides fail locally.
279+ if ( model . startsWith ( FAL_NANO_BANANA_2_LITE_MODEL ) ) {
280+ return {
281+ geometry : "native_aspect_ratio" ,
282+ aspectRatios : NANO_BANANA_SUPPORTED_ASPECT_RATIOS ,
283+ resolutions : [ ] ,
284+ referenceImages : "image_urls" ,
285+ maxInputImages : NANO_BANANA_EDIT_MAX_INPUT_IMAGES ,
286+ referenceLimitLabel : "fal Nano Banana 2 Lite" ,
287+ referenceLimitNoun : "reference image" ,
288+ appendEditPath : "edit" ,
289+ supportsCount : true ,
290+ supportsOutputFormat : true ,
291+ } ;
292+ }
293+ // Grok Imagine (xAI) — text-to-image at /xai/grok-imagine-image, standard
294+ // edits at /xai/grok-imagine-image/edit. Explicit quality/edit model paths
295+ // remain unchanged. Accepts up to 3 reference images via image_urls.
296+ if ( model . startsWith ( FAL_GROK_IMAGINE_MODEL ) ) {
297+ return {
298+ geometry : "native_aspect_ratio" ,
299+ aspectRatios : GROK_IMAGINE_SUPPORTED_ASPECT_RATIOS ,
300+ resolutions : GROK_IMAGINE_SUPPORTED_RESOLUTIONS ,
301+ resolutionCase : "lower" ,
302+ referenceImages : "image_urls" ,
303+ maxInputImages : GROK_IMAGINE_EDIT_MAX_INPUT_IMAGES ,
304+ referenceLimitLabel : "fal Grok Imagine" ,
305+ referenceLimitNoun : "reference image" ,
306+ appendEditPath : "edit" ,
307+ supportsCount : true ,
308+ supportsOutputFormat : true ,
309+ } ;
310+ }
232311 return {
233312 geometry : "image_size" ,
234313 referenceImages : "image_url" ,
@@ -434,7 +513,31 @@ function applyFalImageGeometry(params: {
434513 params . requestBody . aspect_ratio = nativeAspectRatio ;
435514 }
436515 if ( params . resolution && params . schema . referenceImages === "image_urls" ) {
437- params . requestBody . resolution = params . resolution ;
516+ // Schemas may opt in to resolution validation by declaring `resolutions`.
517+ // - `resolutions: undefined` (default, e.g. Nano Banana 2): forward the
518+ // uppercase value unchanged, matching legacy behaviour.
519+ // - `resolutions: ["1K", "2K"]` with `resolutionCase: "lower"` (Grok
520+ // Imagine): validate against the allowlist and lowercase before
521+ // sending.
522+ // - `resolutions: []` (Nano Banana 2 Lite): reject overrides when the
523+ // published endpoint schema has no resolution field.
524+ const allowedResolutions = params . schema . resolutions ;
525+ if ( allowedResolutions === undefined ) {
526+ params . requestBody . resolution = params . resolution ;
527+ } else if ( allowedResolutions . length === 0 ) {
528+ throw new Error (
529+ `${ params . schema . referenceLimitLabel } does not support resolution overrides` ,
530+ ) ;
531+ } else if ( ! allowedResolutions . includes ( params . resolution ) ) {
532+ throw new Error (
533+ `${ params . schema . referenceLimitLabel } supports resolution values: ${ allowedResolutions . join ( ", " ) } ` ,
534+ ) ;
535+ } else {
536+ params . requestBody . resolution =
537+ params . schema . resolutionCase === "lower"
538+ ? params . resolution . toLowerCase ( )
539+ : params . resolution ;
540+ }
438541 }
439542 return ;
440543 }
@@ -550,7 +653,18 @@ export function buildFalImageGenerationProvider(): ImageGenerationProvider {
550653 edit : {
551654 enabled : true ,
552655 maxCount : 4 ,
553- maxInputImages : GPT_IMAGE_EDIT_MAX_INPUT_IMAGES ,
656+ maxInputImages : 1 ,
657+ maxInputImagesByModel : {
658+ [ FAL_NANO_BANANA_MODEL ] : NANO_BANANA_LEGACY_EDIT_MAX_INPUT_IMAGES ,
659+ [ `${ FAL_NANO_BANANA_MODEL } /edit` ] : NANO_BANANA_LEGACY_EDIT_MAX_INPUT_IMAGES ,
660+ } ,
661+ maxInputImagesByModelPrefix : {
662+ "openai/gpt-image-" : GPT_IMAGE_EDIT_MAX_INPUT_IMAGES ,
663+ [ FAL_KREA_2_MODEL_PREFIX ] : KREA_STYLE_REFERENCE_MAX_INPUT_IMAGES ,
664+ [ `${ FAL_NANO_BANANA_MODEL } -` ] : NANO_BANANA_EDIT_MAX_INPUT_IMAGES ,
665+ [ FAL_NANO_BANANA_2_LITE_MODEL ] : NANO_BANANA_EDIT_MAX_INPUT_IMAGES ,
666+ [ FAL_GROK_IMAGINE_MODEL ] : GROK_IMAGINE_EDIT_MAX_INPUT_IMAGES ,
667+ } ,
554668 supportsSize : true ,
555669 supportsAspectRatio : true ,
556670 supportsResolution : true ,
@@ -562,7 +676,29 @@ export function buildFalImageGenerationProvider(): ImageGenerationProvider {
562676 [ FAL_KREA_2_LARGE_MODEL ] : [ ] ,
563677 } ,
564678 aspectRatios : [ ...FAL_SUPPORTED_ASPECT_RATIOS ] ,
679+ aspectRatiosByModel : {
680+ [ FAL_NANO_BANANA_MODEL ] : [ ...NANO_BANANA_LEGACY_SUPPORTED_ASPECT_RATIOS ] ,
681+ [ `${ FAL_NANO_BANANA_MODEL } /edit` ] : [ ...NANO_BANANA_LEGACY_SUPPORTED_ASPECT_RATIOS ] ,
682+ [ FAL_NANO_BANANA_2_LITE_MODEL ] : [ ...NANO_BANANA_SUPPORTED_ASPECT_RATIOS ] ,
683+ [ `${ FAL_NANO_BANANA_2_LITE_MODEL } /edit` ] : [ ...NANO_BANANA_SUPPORTED_ASPECT_RATIOS ] ,
684+ [ FAL_GROK_IMAGINE_MODEL ] : [ ...GROK_IMAGINE_SUPPORTED_ASPECT_RATIOS ] ,
685+ [ `${ FAL_GROK_IMAGINE_MODEL } /edit` ] : [ ...GROK_IMAGINE_SUPPORTED_ASPECT_RATIOS ] ,
686+ [ `${ FAL_GROK_IMAGINE_MODEL } /quality` ] : [ ...GROK_IMAGINE_SUPPORTED_ASPECT_RATIOS ] ,
687+ [ `${ FAL_GROK_IMAGINE_MODEL } /quality/edit` ] : [ ...GROK_IMAGINE_SUPPORTED_ASPECT_RATIOS ] ,
688+ } ,
565689 resolutions : [ "1K" , "2K" , "4K" ] ,
690+ resolutionsByModel : {
691+ [ FAL_KREA_2_MEDIUM_MODEL ] : [ ] ,
692+ [ FAL_KREA_2_LARGE_MODEL ] : [ ] ,
693+ [ FAL_NANO_BANANA_MODEL ] : [ ] ,
694+ [ `${ FAL_NANO_BANANA_MODEL } /edit` ] : [ ] ,
695+ [ FAL_NANO_BANANA_2_LITE_MODEL ] : [ ] ,
696+ [ `${ FAL_NANO_BANANA_2_LITE_MODEL } /edit` ] : [ ] ,
697+ [ FAL_GROK_IMAGINE_MODEL ] : [ ...GROK_IMAGINE_SUPPORTED_RESOLUTIONS ] ,
698+ [ `${ FAL_GROK_IMAGINE_MODEL } /edit` ] : [ ...GROK_IMAGINE_SUPPORTED_RESOLUTIONS ] ,
699+ [ `${ FAL_GROK_IMAGINE_MODEL } /quality` ] : [ ...GROK_IMAGINE_SUPPORTED_RESOLUTIONS ] ,
700+ [ `${ FAL_GROK_IMAGINE_MODEL } /quality/edit` ] : [ ...GROK_IMAGINE_SUPPORTED_RESOLUTIONS ] ,
701+ } ,
566702 } ,
567703 output : {
568704 formats : [ ...FAL_OUTPUT_FORMATS ] ,
0 commit comments