ModelSell Docs
ImagesGemini

Gemini Native Image Generation

Use the official Gemini generateContent REST shape for native image generation and image editing models.

Gemini native image generation uses Google's official generateContent REST request shape: the model is carried in the path, text and images are sent through contents[].parts[], and image output is requested with generationConfig.responseModalities.

If your client already uses the Gemini SDK or Google REST format, you can point it at the ModelSell Gemini-compatible endpoint without converting the request body to the OpenAI Images format.

Endpoints

OperationEndpoint
Gemini native content generationPOST /v1beta/models/{model}:generateContent
Gemini native content generationPOST /v1/models/{model}:generateContent

{model} is the Gemini image model ID, such as gemini-3.1-flash-image-preview or another Gemini image model available to your account.

Request Shape

FieldTypeRequiredDescription
contentsarrayYesRequest content. A single-turn request usually has one role: "user" item.
contents[].rolestringNouser or model. Use user for a single-turn request.
contents[].partsarrayYesMultimodal parts. Each part should carry one content type.
parts[].textstringNoText prompt.
parts[].inlineDataobjectNoBase64 inline media using the official camelCase fields.
inlineData.mimeTypestringYesInput image MIME type, such as image/png, image/jpeg, or image/webp.
inlineData.datastringYesBase64 image data without a data:image/...;base64, prefix.
generationConfig.responseModalitiesstring arrayYesImage generation must include IMAGE. Use ["TEXT", "IMAGE"] if you also want text.
generationConfig.imageConfig.aspectRatiostringNoOutput aspect ratio, such as 1:1, 4:3, 16:9, 9:16, or 21:9.
generationConfig.imageConfig.imageSizestringNoOutput image tier, such as 512, 1K, 2K, or 4K, depending on model support.
systemInstructionobjectNoGemini official system instruction shape.
safetySettingsarrayNoGemini official safety settings.
toolsarrayNoGemini official tools.

Text To Image

curl -X POST "https://api.modelsell.com/v1beta/models/gemini-3.1-flash-image-preview:generateContent" \
  -H "Authorization: Bearer $MODELSELL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "role": "user",
        "parts": [
          {
            "text": "Create a polished product photo with clean composition, soft natural light, and crisp detail."
          }
        ]
      }
    ],
    "generationConfig": {
      "responseModalities": ["IMAGE"],
      "imageConfig": {
        "aspectRatio": "4:3",
        "imageSize": "2K"
      }
    }
  }'

Reference Image Editing

When sending an image through inlineData, data must be the complete Base64 string. Do not include a Data URL prefix and do not send a truncated log capture.

{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "text": "Remove all people from the scene while preserving the room structure. Make the final image clean, airy, and cinematic."
        },
        {
          "inlineData": {
            "mimeType": "image/png",
            "data": "BASE64_IMAGE_DATA"
          }
        }
      ]
    }
  ],
  "generationConfig": {
    "responseModalities": ["IMAGE"],
    "imageConfig": {
      "aspectRatio": "16:9",
      "imageSize": "2K"
    }
  }
}

Response

The response keeps the native Gemini structure. Generated image data is usually returned at:

candidates[].content.parts[].inlineData.data

The MIME type is returned at:

candidates[].content.parts[].inlineData.mimeType

Common Errors

ProblemDescription
Missing responseModalitiesImage generation must request IMAGE; an empty list is equivalent to text-only output.
Truncated Base64inlineData.data must be complete. Truncated payloads commonly produce 400 invalid argument.
Data URL prefix includedinlineData.data expects raw Base64, not data:image/png;base64,....
Mixed new-interface fieldsThis endpoint uses contents, inlineData, and generationConfig. Do not send interactions fields such as input, type: "image", or response_format in a generateContent body.
imageConfig sent to a non-image modelimageConfig is only valid for models that support image generation configuration.

Difference From Generic Images

/v1/images/generations is the OpenAI Images-compatible entrypoint for unified image model calls. Gemini native image generation preserves Google's official generateContent request and response shape, which is best for clients already built around the Gemini protocol.

On this page