{"record":{"id":"5ab6f61c1b78882b","repo":"vercel/ai","slug":"gemini-image-models-do-not-support-mask-based-imag-5ab6f6","errorCode":null,"errorMessage":"Gemini image models do not support mask-based image editing.","messagePattern":"Gemini image models do not support mask-based image editing\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/google/src/google-image-model.ts","lineNumber":94,"sourceCode":"    }\n\n    const {\n      prompt,\n      n,\n      size,\n      aspectRatio,\n      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      });","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/vercel/ai/blob/69428b1f8b037e4d118fb4853428d5c4e620493c/packages/google/src/google-image-model.ts#L76-L112","documentation":"Gemini image models do not support mask-based inpainting/image editing, so the provider throws immediately when a `mask` is supplied in doGenerate options. This is an explicit capability guard rather than a propagated API error.","triggerScenarios":"Calling generateImage (or doGenerate) against a Google Gemini image model with a `mask` property set in provider options or image editing options.","commonSituations":"Porting image-editing code from providers that support inpainting masks (e.g. OpenAI DALL·E editing) to Google Gemini; generic multi-provider image editing code that always passes a mask.","solutions":["Remove the `mask` option when using Gemini image models","Perform mask-based editing with a provider that supports it (e.g. OpenAI image editing)","Send the masked/composited image as part of the prompt input image instead of using a mask parameter"],"exampleFix":"// before\nawait generateImage({ model: google.imageModel('gemini-2.5-flash-image'), prompt, mask });\n// after\nawait generateImage({ model: google.imageModel('gemini-2.5-flash-image'), prompt });","handlingStrategy":"validation","validationCode":"if (options.mask != null) {\n  throw new Error('Gemini image models do not support masks; remove the mask option.');\n}","typeGuard":"function supportsMaskEditing(modelId: string): boolean {\n  return !modelId.startsWith('gemini-');\n}","tryCatchPattern":"try {\n  await generateImage({ model, prompt, ...(mask ? { mask } : {}) });\n} catch (error) {\n  if (error instanceof Error && error.message.includes('mask-based image editing')) {\n    // retry without mask or route to a mask-capable provider\n  }\n  throw error;\n}","preventionTips":["Only pass `mask` for providers known to support inpainting","Keep provider-specific options behind a capability flag in multi-provider code","Check the model capability docs before adding mask editing"],"tags":["google","image-generation","unsupported-functionality","mask"],"backgroundTag":"unsupported-functionality","analyzedSha":"69428b1f8b037e4d118fb4853428d5c4e620493c","analyzedAt":"2026-08-30T12:32:21.016Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}