Skip to content

Nano Banana โ€‹

Updated

Nano Banana is an image generation model that supports text-to-image and reference-image editing. It is called synchronously via the TokenHub path, and the result is returned directly in the response body.

Basic Information โ€‹

ItemValue
modelcustom-model-gn-v3.1
Supported versioncustom-model-gn-v3.1 / custom-model-gn-v3.1-lite / custom-model-gn-v3.0 / custom-model-gn-v2.5
Default valuemodel=custom-model-gn-v3.1 / responseFormat=url
Supported operationsText โ†’ image generation, image editing
Output size1K / 2K / 4K
Supported aspect ratio16:9 / 1:1 / 4:3 / 3:4 / 9:16
Return formaturl / b64_json
Guardrail release supportNot supported

Endpoint โ€‹

ItemValue
HTTP methodPOST
Request domainhttps://tokenhub.tencentcloudmaas.com
Image generation and editing/v1/wand/gn-image/generation
AuthenticationAuthorization: Bearer <API_KEY>
Result returnSynchronous. The generation result is included in the response body

Region-specific Access Addresses

The address above is based on Guangzhou. For region-specific addresses and backup addresses such as Singapore and Silicon Valley, refer to the API usage guide.

Prerequisites โ€‹

  • The TokenHub service must be activated and a API Key must have been issued. For the procedure, refer to the TokenHub Quick Start.

Input Parameters โ€‹

ParameterRequiredTypeDescription
modelRequiredStringcustom-model-gn-v3.1 / custom-model-gn-v3.1-lite / custom-model-gn-v3.0 / custom-model-gn-v2.5
contentsRequiredArrayContent array consisting of role and parts
contents.roleOptionalStringMessage role. user
contents.partsRequiredArrayItem array consisting of text or inlineData
contents.parts.textRequiredStringGeneration prompt
contents.parts.inlineDataOptionalObjectInput image. Used only for image editing
contents.parts.inlineData.mimeTypeOptionalStringInput image type. image/png / image/jpeg
contents.parts.inlineData.dataOptionalStringInput image. An accessible URL or a Base64 string
generationConfigOptionalObjectGeneration settings
generationConfig.responseModalitiesOptionalArrayReturn modality. ["IMAGE"]
generationConfig.responseFormatOptionalObjectImage output settings
generationConfig.responseFormat.image.aspectRatioOptionalString16:9 / 1:1 / 4:3 / 3:4 / 9:16
generationConfig.responseFormat.image.imageSizeOptionalString1K / 2K / 4K
responseFormatOptionalStringReturn image format. url / b64_json. Default value url
logoAddOptionalIntegerWhether to add a watermark. 1 adds it, 0 does not. Default value 0

Output Parameters โ€‹

ParameterTypeDescription
candidatesArrayGeneration result array
candidates.content.parts.inlineData.dataStringGenerated image. URL or Base64 depending on responseFormat
candidates.content.parts.inlineData.mimeTypeStringGenerated image type
candidates.finishReasonStringReason for termination. STOP on normal completion
candidates.indexIntegerResult sequence number
modelVersionStringModel version actually used for generation
responseIdStringResponse ID
tokenhub_usage.total_tokensIntegerNumber of tokens used
request_idStringID used to verify the request

Request Example โ€‹

bash
curl --location 'https://tokenhub.tencentcloudmaas.com/v1/wand/gn-image/generation' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  -d '{
  "model": "custom-model-gn-v3.1",
  "contents": [
    {
      "parts": [
        {
          "text": "Dancing"
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "IMAGE"
    ],
    "responseFormat": {
      "image": {
        "aspectRatio": "9:16",
        "imageSize": "2K"
      }
    }
  }
}'

Response Example โ€‹

json
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "inlineData": {
              "data": "https://xxxxxx.jpg",
              "mimeType": "image/jpeg"
            },
            "thoughtSignature": ""
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0
    }
  ],
  "modelVersion": "gemini-3.1-flash-image",
  "responseId": "uXd8arrMAeu-_uMP7v-g4Ag",
  "tokenhub_usage": {
    "total_tokens": 394260
  },
  "request_id": "5f0b3bf8-3ea8-46b5-b8af-529dabbc25af"
}

Image Editing โ€‹

Adding inlineData to contents.parts makes it an edit that references the input image. The request body structure and the response structure are the same as for generation.

Input Parameters โ€‹

ParameterRequiredTypeDescription
contents.parts.inlineDataRequiredObjectInput image
contents.parts.inlineData.mimeTypeRequiredStringInput image type. image/png / image/jpeg
contents.parts.inlineData.dataRequiredStringInput image. An accessible URL or a Base64 string

Generation and Editing Use the Same Endpoint

Text generation and image editing use the same endpoint. In an edit request, pass the reference image through inlineData.

Request Example โ€‹

bash
curl --location 'https://tokenhub.tencentcloudmaas.com/v1/wand/gn-image/generation' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --header 'Content-Type: application/json' \
  -d '{
  "model": "custom-model-gn-v3.1",
  "contents": [
    {
      "parts": [
        {
          "text": "Dancing"
        },
        {
          "inlineData": {
            "mimeType": "image/png",
            "data": "https://xxxxxxxxx.png"
          }
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "IMAGE"
    ],
    "responseFormat": {
      "image": {
        "aspectRatio": "9:16",
        "imageSize": "2K"
      }
    }
  }
}'

Response Example โ€‹

json
{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "inlineData": {
              "data": "https://xxxxxx.jpg",
              "mimeType": "image/jpeg"
            },
            "thoughtSignature": ""
          }
        ],
        "role": "model"
      },
      "finishReason": "STOP",
      "index": 0
    }
  ],
  "modelVersion": "gemini-3.1-flash-image",
  "responseId": "kT2pQmR7bvN-_yWL4w-h9De",
  "tokenhub_usage": {
    "total_tokens": 412870
  },
  "request_id": "a7c31e90-6d52-4f18-9b03-72e5cd14f8ba"
}

Built with VitePress ยท Deployed on Tencent EdgeOne Pages