{"record":{"id":"262de3c54cfbb78f","repo":"vercel/ai","slug":"gemini-image-models-do-not-support-generating-a-se-262de3","errorCode":null,"errorMessage":"Gemini image models do not support generating a set number of images per call. Use n=1 or omit the n parameter.","messagePattern":"Gemini image models do not support generating a set number of images per call\\. Use n=1 or omit the n parameter\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/google/src/google-image-model.ts","lineNumber":101,"sourceCode":"      seed,\n      providerOptions,\n      headers,\n      abortSignal,\n      files,\n      mask,\n    } = options;\n    const warnings: Array<SharedV4Warning> = [];\n\n    // Gemini does not support mask-based inpainting\n    if (mask != null) {\n      throw new Error(\n        'Gemini image models do not support mask-based image editing.',\n      );\n    }\n\n    // Gemini does not support generating multiple images per call via n parameter\n    if (n != null && n > 1) {\n      throw new Error(\n        'Gemini image models do not support generating a set number of images per call. Use n=1 or omit the n parameter.',\n      );\n    }\n\n    if (size != null) {\n      warnings.push({\n        type: 'unsupported',\n        feature: 'size',\n        details:\n          'This model does not support the `size` option. Use `aspectRatio` instead.',\n      });\n    }\n\n    const userContent: Array<\n      | { type: 'text'; text: string }\n      | {\n          type: 'file';\n          data:","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/google/src/google-image-model.ts#L83-L119","documentation":"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.","triggerScenarios":"Calling generateImage (or doGenerate) with a Google Gemini image model and `n` set to a number greater than 1.","commonSituations":"Code that requests multiple image variations generically across providers; migrated code from Imagen or OpenAI models that supported batch generation.","solutions":["Set `n` to 1 or remove the `n` option","Issue multiple generateImage calls in parallel (e.g. Promise.all) to obtain several images","Use a provider/model that supports batch image generation if multiple images per call are required"],"exampleFix":"// before\nawait generateImage({ model: google.imageModel('gemini-2.5-flash-image'), prompt, n: 4 });\n// after\nconst images = await Promise.all([1, 2, 3, 4].map(() => generateImage({ model: google.imageModel('gemini-2.5-flash-image'), prompt })));","handlingStrategy":"validation","validationCode":"if (n != null && n > 1) {\n  throw new Error('Gemini image models generate one image per call; use n=1 or fan out calls.');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await generateImage({ model, prompt, n });\n} catch (error) {\n  if (error instanceof Error && error.message.includes('set number of images')) {\n    // fan out: Promise.all of n single-image calls\n  }\n  throw error;\n}","preventionTips":["Default n to 1 for Google image models","Implement batch generation as parallel single-image calls in application code","Encode per-provider image capabilities (mask, n, size) in a config map"],"tags":["google","image-generation","unsupported-functionality","parameters"],"backgroundTag":"unsupported-functionality","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}