vercel/ai · error · Error

Gemini image models do not support generating a set number o

Error message

Gemini image models do not support generating a set number of images per call. Use n=1 or omit the n parameter.

What it means

Gemini image models generate one image per call, so passing `n > 1` throws this error. The provider enforces n=1 (or omitted n) instead of silently ignoring the value.

Source

Thrown at packages/google/src/google-image-model.ts:101

      seed,
      providerOptions,
      headers,
      abortSignal,
      files,
      mask,
    } = options;
    const warnings: Array<SharedV4Warning> = [];

    // Gemini does not support mask-based inpainting
    if (mask != null) {
      throw new Error(
        'Gemini image models do not support mask-based image editing.',
      );
    }

    // Gemini does not support generating multiple images per call via n parameter
    if (n != null && n > 1) {
      throw new Error(
        'Gemini image models do not support generating a set number of images per call. Use n=1 or omit the n parameter.',
      );
    }

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

    const userContent: Array<
      | { type: 'text'; text: string }
      | {
          type: 'file';
          data:

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Set `n` to 1 or remove the `n` option
  2. Issue multiple generateImage calls in parallel (e.g. Promise.all) to obtain several images
  3. Use a provider/model that supports batch image generation if multiple images per call are required

Example fix

// before
await generateImage({ model: google.imageModel('gemini-2.5-flash-image'), prompt, n: 4 });
// after
const images = await Promise.all([1, 2, 3, 4].map(() => generateImage({ model: google.imageModel('gemini-2.5-flash-image'), prompt })));
Defensive patterns

Strategy: validation

Validate before calling

if (n != null && n > 1) {
  throw new Error('Gemini image models generate one image per call; use n=1 or fan out calls.');
}

Try / catch

try {
  await generateImage({ model, prompt, n });
} catch (error) {
  if (error instanceof Error && error.message.includes('set number of images')) {
    // fan out: Promise.all of n single-image calls
  }
  throw error;
}

Prevention

When it happens

Trigger: Calling generateImage (or doGenerate) with a Google Gemini image model and `n` set to a number greater than 1.

Common situations: Code that requests multiple image variations generically across providers; migrated code from Imagen or OpenAI models that supported batch generation.

Related errors


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