4Z API

Image Generation for gemini-nano-banana-2.1

Endpoint: POST https://4zapi.com/v1beta/models/gemini-nano-banana-2.1:generateContent

Model Description

gemini-nano-banana-2.1 is a Gemini series image generation/editing model that supports text-to-image and multi-image reference editing (face swapping, outfit changing, style transfer, etc.).

  • Request format: Gemini native generateContent
  • Output: inlineData (base64) in candidates[0].content.parts[]; returns image URL when response_format: "url" is passed (only non-streaming)
  • Resolution: imageConfig.imageSize only supports 1K / 2K / 4K, default is 1K, does not support 512
  • Aspect Ratio: imageConfig.aspectRatio supports 1:1, 16:9, 9:16, 4:3, 3:4, 2:3, 3:2, 4:5, 5:4, 1:4, 4:1, 1:8, 8:1, 21:9
  • Thinking: thinkingConfig.thinkingLevel only supports minimal / high, does not support thinkingBudget; can also use model name suffix -thinking / -nothinking
  • Billing: Based on resolution tiers, 1K ×1.0, 2K ×1.5, 4K ×3.375 (based on console model pricing)

Official documentation: https://ai.google.dev/gemini-api/docs/image-generation?hl=en#gemini-image-editing

Parameters

  • Content-Type (header, string, required)

Request body (application/json)

  • contents (array, required): Conversation content. For text-to-image, only one text should be placed; for image editing/multi-image reference, place one text + multiple inline_data within the same parts.
  • generationConfig (object): Generation configuration. Note: aspectRatio / imageSize must be placed within imageConfig; placing them at the top level of generationConfig will be ignored; negativePrompt and resolution fields are not supported.
  • response_format (string): Image return format (platform extension field, not an official Gemini parameter). base64: image is returned in parts[].inlineData.data (default); url: image returns a temporary link in parts[].fileData.fileUri, only supported for non-streaming requests, passing url in streaming will result in a 400 error. ["base64", "url"]

Request example

{
  "contents": [
    {
      "parts": [
        {
          "text": "将图1人物的脸和头发完整替换到图2的人物上:五官和面部细节必须完全来自图1,不保留图2的脸部特征;脸部角度根据图2的头部姿态调整;图2的服装、发饰以外的身体、背景保持不变;肤色与光影自然融合,不出现明显拼接边界;摄影级写实风格。"
        },
        {
          "text": "参考图1(提示词中的\"图1\"):"
        },
        {
          "inlineData": {
            "data": "\u003c图1的base64,不含 data:image/jpeg;base64, 前缀\u003e",
            "mimeType": "image/jpeg"
          }
        },
        {
          "text": "参考图2(提示词中的\"图2\"):"
        },
        {
          "inlineData": {
            "data": "\u003c图2的base64,不含 data:image/jpeg;base64, 前缀\u003e",
            "mimeType": "image/jpeg"
          }
        }
      ],
      "role": "user"
    }
  ],
  "generationConfig": {
    "imageConfig": {
      "aspectRatio": "3:4",
      "imageSize": "2K"
    },
    "responseModalities": [
      "TEXT",
      "IMAGE"
    ]
  },
  "response_format": "base64"
}