Search...
Menu

Gemini Image Generation (Native Format)

Generate images using Gemini's native message structure.

Request

Item Description
Method POST
Path /v1beta/models/{model}:generateContent
Gateway URL https://ailink.nativex.com
Authentication Authorization: Bearer sk-xxxx; replace the placeholder with your API Key
Request format application/json

Replace MODEL_ID with a model from the Model Marketplace that supports this endpoint. Available models, parameters, and permissions depend on your account.

Parameters

Parameter Location Type Required Description
model Path string Yes A Gemini model that supports image output
contents Body object[] Yes Provide the image description in parts[].text; image content blocks can also be included for editing
generationConfig.responseModalities Body string[] Yes Typically ["TEXT", "IMAGE"]; check model support
generationConfig.imageConfig Body object No Image settings, such as aspectRatio and imageSize; supported values depend on the model

Example

curl -X POST 'https://ailink.nativex.com/v1beta/models/MODEL_ID:generateContent' \
  -H 'Authorization: Bearer sk-xxxx' \
  -H 'Content-Type: application/json' \
  -d '{
  "contents": [
    {
      "parts": [
        {
          "text": "Draw an orange cat sitting by a window in watercolor style."
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": [
      "TEXT",
      "IMAGE"
    ]
  }
}'

Response

The following is a simplified response for readability. IDs, URLs, text, and usage values are illustrative.

{
  "candidates": [
    {
      "content": {
        "parts": [
          {
            "inlineData": {
              "mimeType": "image/png",
              "data": "BASE64_IMAGE"
            }
          }
        ]
      }
    }
  ]
}
Field or result Description
candidates[].content.parts[] May contain both text and inlineData
inlineData.data Base64 image data; decode it before saving

Error handling

For unsuccessful responses, check the HTTP status and error body first. Verify the API Key, model name, account balance, and parameters. If rate limited, reduce concurrency and retry later.

Last modified: 2026-11-17