Skip to content

Gemini Native Format

Gemini native interface supports both text and image generation. This interface allows you to directly call Gemini's native capabilities, including the latest image generation features.

Interface Details

Endpoint: POST /v1beta/models/{model}:generateContent

Description: Generates content based on prompts and configurations. Supports multi-modal input (text, images) and multi-modal output (text, images).

Authentication: Bearer Token

http
Authorization: Bearer YOUR_API_TOKEN

Request Parameters

Path Parameters

ParameterTypeRequiredDescriptionExample
modelstringYesModel Namegemini-2.0-flash-exp

Header Parameters

ParameterTypeRequiredDescriptionExample
AuthorizationstringYesBearer Token AuthBearer sk-xxx...
Content-TypestringYesContent Typeapplication/json

Body Parameters

ParameterTypeRequiredDescription
contentsarray[object]YesList of dialogue contents
contents[].rolestringNoRole (user, model)
contents[].partsarray[object]YesContent parts
contents[].parts[].textstringNoText prompt
generationConfigobjectNoGeneration config options
generationConfig.responseModalitiesarray[string]NoResponse modalities (TEXT, IMAGE)
generationConfig.imageConfigobjectNoImage generation configuration
generationConfig.imageConfig.aspectRatiostringNoAspect ratio (1:1, 16:9, 9:16, etc.)
generationConfig.imageConfig.imageSizestringNoOutput resolution tier, see "Image Resolution" below

Image Resolution

Which imageSize tiers are available depends on the model. Omit the field to let the model apply its 1K default.

TierValueSupported models
0.5K512gemini-3.1-flash-image family only
1K1KAll image models (default)
2K2Kgemini-3-pro-image family
4K4Kgemini-3-pro-image family

The wire value for the 0.5K tier is 512, not 0.5K. So that callers who write the tier by its documented name still work, the gateway rewrites 0.5K (case-insensitive), 512P and 512PX to 512, and all of these spellings are accepted.

Requesting the 0.5K tier on a model that does not support it makes the gateway drop the field and fall back to the model's 1K default rather than fail the request. A tier the gateway does not recognise is forwarded untouched for the model to validate.


Response Parameters

ParameterTypeDescription
candidatesarray[object]List of generation candidates
candidates[].contentobjectContent object
candidates[].content.partsarray[object]Content parts, containing text or generated image data
candidates[].finishReasonstringReason for completion
usageMetadataobjectUsage statistics
usageMetadata.promptTokenCountintegerPrompt token count
usageMetadata.candidatesTokenCountintegerGenerated token count
usageMetadata.totalTokenCountintegerTotal token count

Code Examples

Curl Example (Image Generation)

bash
curl -X POST "https://api.ezmodel.cloud/v1beta/models/gemini-2.0-flash-exp:generateContent" \
  -H "Authorization: Bearer $YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {
        "parts": [
          {
            "text": "A cyberpunk style fox running in a forest"
          }
        ]
      }
    ],
    "generationConfig": {
      "responseModalities": ["IMAGE"],
      "imageConfig": {
        "aspectRatio": "16:9",
        "imageSize": "1K"
      }
    }
  }'

Response Example

json
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "inlineData": {
              "mimeType": "image/png",
              "data": "iVBORw0KGgoAAA..."
            }
          }
        ]
      },
      "finishReason": "STOP"
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 15,
    "candidatesTokenCount": 0,
    "totalTokenCount": 15
  }
}

企业合作联系:service@ezmodel.cloud