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 on Google Vertex generate one image per request; the provider throws this plain Error in doGenerate when `n` is provided and greater than 1. It fails fast client-side because the underlying Gemini image API has no count parameter like Imagen's sampleCount.
Source
Thrown at packages/google-vertex/src/google-vertex-image-model.ts:87
size,
aspectRatio,
seed,
providerOptions,
headers,
abortSignal,
files,
mask,
} = options;
const warnings: Array<SharedV4Warning> = [];
if (mask != null) {
throw new Error(
'Gemini image models do not support mask-based image editing.',
);
}
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
- Set n to 1 or omit the n parameter entirely.
- Call generateImage multiple times (or Promise.all) to obtain several images.
- Use an Imagen model on Vertex if single-call multi-image generation (sampleCount) is needed.
Example fix
// before
await generateImage({ model: vertex.image('gemini-2.0-flash-exp-image'), prompt, n: 4 });
// after
const images = await Promise.all([1, 2, 3, 4].map(() => generateImage({ model: vertex.image('gemini-2.0-flash-exp-image'), prompt }))); Defensive patterns
Strategy: validation
Validate before calling
if (typeof n === 'number' && n > 1 && isGeminiImageModel(modelId)) {
throw new Error('Gemini image models generate 1 image per call; loop calls instead.');
} Try / catch
try {
await generateImage({ model, prompt, n });
} catch (e) {
if (e instanceof Error && e.message.includes('set number of images')) {
// retry with n = 1 or fan out parallel calls
} else throw e;
} Prevention
- Clamp n to 1 (or omit it) whenever the model id starts with 'gemini'.
- Centralize image generation behind a helper that adapts n per provider capability.
When it happens
Trigger: generateImage({ model: vertex.image('<gemini image model>'), prompt, n: 2 }) (or any n > 1) — the check `if (n != null && n > 1)` throws before the request is sent.
Common situations: Migrating from Imagen or OpenAI DALL·E code that requested multiple images per call; loops that fan out a shared options object containing n: 4; expecting batch generation semantics that Gemini image models don't offer on Vertex.
Related errors
- Gemini image models do not support mask-based image editing.
- AI_NoSuchModelError
- Unsupported task type: ${taskType}
- Amazon Bedrock request was moderated: ${reasons.join(', ')}
- Amazon Bedrock returned no images. Status: ${response.status
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/efcbacfc0078235c.
Report an issue: GitHub.