@@ -136,6 +136,11 @@ class TogetherImageGenerationService extends BaseService {
136136
137137 static DEFAULT_MODEL = 'black-forest-labs/FLUX.1-schnell' ;
138138 static DEFAULT_RATIO = { w : 1024 , h : 1024 } ;
139+ static CONDITION_IMAGE_MODELS = [
140+ 'black-forest-labs/flux.1-kontext-dev' ,
141+ 'black-forest-labs/flux.1-kontext-pro' ,
142+ 'black-forest-labs/flux.1-kontext-max' ,
143+ ] ;
139144
140145 /**
141146 * Generates an image using Together AI client
@@ -199,12 +204,15 @@ class TogetherImageGenerationService extends BaseService {
199204 prompt_strength,
200205 disable_safety_checker,
201206 response_format,
207+ input_image,
202208 } = options ;
203209
204210 const request = {
205211 prompt,
206212 model : model ?? this . constructor . DEFAULT_MODEL ,
207213 } ;
214+ const requiresConditionImage =
215+ this . constructor . _modelRequiresConditionImage ( request . model ) ;
208216
209217 const ratioWidth = ( ratio && ratio . w !== undefined ) ? Number ( ratio . w ) : undefined ;
210218 const ratioHeight = ( ratio && ratio . h !== undefined ) ? Number ( ratio . h ) : undefined ;
@@ -235,13 +243,29 @@ class TogetherImageGenerationService extends BaseService {
235243 request . disable_safety_checker = disable_safety_checker ;
236244 }
237245 if ( typeof response_format === 'string' ) request . response_format = response_format ;
246+
247+ const resolvedImageBase64 = typeof image_base64 === 'string'
248+ ? image_base64
249+ : ( typeof input_image === 'string' ? input_image : undefined ) ;
250+
238251 if ( typeof image_url === 'string' ) request . image_url = image_url ;
239- if ( typeof image_base64 === 'string' ) request . image_base64 = image_base64 ;
252+ if ( resolvedImageBase64 ) request . image_base64 = resolvedImageBase64 ;
240253 if ( typeof mask_image_url === 'string' ) request . mask_image_url = mask_image_url ;
241254 if ( typeof mask_image_base64 === 'string' ) request . mask_image_base64 = mask_image_base64 ;
242255 if ( typeof prompt_strength === 'number' && Number . isFinite ( prompt_strength ) ) {
243256 request . prompt_strength = Math . max ( 0 , Math . min ( 1 , prompt_strength ) ) ;
244257 }
258+ if ( requiresConditionImage ) {
259+ const conditionSource = resolvedImageBase64
260+ ? resolvedImageBase64
261+ : ( typeof image_url === 'string' ? image_url : undefined ) ;
262+
263+ if ( ! conditionSource ) {
264+ throw new Error ( `Model ${ request . model } requires an image_url or image_base64 input` ) ;
265+ }
266+
267+ request . condition_image = conditionSource ;
268+ }
245269
246270 return request ;
247271 }
@@ -252,6 +276,15 @@ class TogetherImageGenerationService extends BaseService {
252276 // Flux models expect multiples of 8. Snap to the nearest multiple without going below 64.
253277 return Math . max ( 64 , Math . round ( rounded / 8 ) * 8 ) ;
254278 }
279+
280+ static _modelRequiresConditionImage ( model ) {
281+ if ( typeof model !== 'string' || model . trim ( ) === '' ) {
282+ return false ;
283+ }
284+
285+ const normalized = model . toLowerCase ( ) ;
286+ return this . CONDITION_IMAGE_MODELS . some ( required => normalized === required ) ;
287+ }
255288}
256289
257290module . exports = {
0 commit comments