vercel/ai · error · Error

Together AI does not support mask-based image editing. Use F

Error message

Together AI does not support mask-based image editing. Use FLUX Kontext models (e.g., black-forest-labs/FLUX.1-kontext-pro) with a reference image and descriptive prompt instead.

What it means

The Together AI image model does not implement mask-based (inpainting) editing. If a mask is provided to doGenerate, it throws immediately with guidance to use FLUX Kontext models instead, which perform instruction-based editing from a reference image plus a descriptive prompt.

Source

Thrown at packages/togetherai/src/togetherai-image-model.ts:71

  ) {}

  async doGenerate({
    prompt,
    n,
    size,
    seed,
    providerOptions,
    headers,
    abortSignal,
    files,
    mask,
  }: Parameters<ImageModelV4['doGenerate']>[0]): Promise<
    Awaited<ReturnType<ImageModelV4['doGenerate']>>
  > {
    const warnings: Array<SharedV4Warning> = [];

    if (mask != null) {
      throw new Error(
        'Together AI does not support mask-based image editing. ' +
          'Use FLUX Kontext models (e.g., black-forest-labs/FLUX.1-kontext-pro) ' +
          'with a reference image and descriptive prompt instead.',
      );
    }

    if (size != null) {
      warnings.push({
        type: 'unsupported',
        feature: 'aspectRatio',
        details:
          'This model does not support the `aspectRatio` option. Use `size` instead.',
      });
    }

    const currentDate = this.config._internal?.currentDate?.() ?? new Date();

    const togetheraiOptions = await parseProviderOptions({

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Remove the mask parameter from the generateImage call.
  2. Switch to a FLUX Kontext model (e.g. black-forest-labs/FLUX.1-kontext-pro) and supply the reference image plus a prompt describing the edit.
  3. Use a different provider that supports mask-based inpainting if masks are mandatory.
  4. Validate/handle the model choice before calling to warn users masks are unsupported.

Example fix

// before
await generateImage({ model: togetherai.image('...'), prompt, mask });
// after
await generateImage({
  model: togetherai.image('black-forest-labs/FLUX.1-kontext-pro'),
  prompt: 'replace the sky with a sunset',
  providerOptions: { togetherai: { image: referenceImage } },
});
Defensive patterns

Strategy: validation

Validate before calling

if (params.mask && model.provider === 'togetherai') {
  throw new Error('togetherai: remove mask; use FLUX Kontext with a reference image instead.');
}

Type guard

null

Try / catch

try {
  await generateImage(params);
} catch (error) {
  if (error.message.includes('mask-based image editing')) {
    // fall back to a Kontext model or another provider
  } else throw error;
}

Prevention

When it happens

Trigger: Calling generateImage with a Together AI image model and passing a `mask` parameter (image editing/inpainting request).

Common situations: Porting code from OpenAI DALL·E-style inpainting (image + mask) to Together AI; migrating an app between providers assuming mask support parity.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/3c829f2cc44ffe37. Report an issue: GitHub.