Skip to main content
POST
Generate an image (native Gemini, non-streaming)
Generate images with the native Gemini generateContent request and response format. For image models, this endpoint is supported only for Google/Gemini image models. Use the OpenAI image generation endpoint or a model-specific endpoint for Seedream, GPT Image, and other image models. Native calls for Gemini chat models are outside the scope of this image reference.

Features

  • Generate images using native Gemini generateContent request and response formats, not OpenAI Images formats
  • Generate from text, edit one image, combine multiple references, or continue editing across turns
  • Set model-supported aspect ratios and output tiers with generationConfig.imageConfig
  • Receive text and Base64 images in candidates[].content.parts[]; use the streaming endpoint for SSE

Authentication

POST https://api.hairoute.ai/v1/models/{model}:generateContent Replace {model} with an available Google/Gemini image model from the model list. Do not put model in the request body. Pass your HaiRoute API key in x-goog-api-key: YOUR_API_KEY, or use Authorization: Bearer YOUR_API_KEY. Do not substitute a Google API key for your HaiRoute key.

Supported image models

This endpoint is only for Google/Gemini image models.

Quick example

On success, the image is returned in candidates[].content.parts[].inlineData, with a mimeType and Base64-encoded data. Any accompanying text appears as a text part in the same parts array. The Base64 value below is a placeholder, not an actual image:
Decode inlineData.data to bytes and save them using the supplied mimeType. The response is not an OpenAI Images data[].url response. Usage, candidates, and optional fields vary by model and request.

Key parameters

This endpoint uses native generationConfig.imageConfig, not OpenAI Images parameters such as size, quality, or response_format. Supported aspect ratios and sizes depend on model configuration.

Generation modes

These examples show request bodies only. All four modes use this page’s endpoint and authentication; no separate mode parameter is needed. Replace every Base64 placeholder with actual raw Base64 image data.

Text-to-image

Send a text prompt without an input image; the Quick example above is ready to adapt. Local changes and style adjustments are prompt instructions, not separate API parameters.

Single-image editing

Put one image and an editing instruction in the same user message. This example replaces the background; you can also ask to preserve the subject, change an element, or adjust the style.

Multiple-reference composition

Put multiple reference images in one user message’s parts and describe the role of each image in the text. Input count, size limits, and results depend on the selected model and channel.

Multi-turn editing

Send the previous user request, the actual previous candidates[0].content as a model message, and your new instruction in that order within contents. This body illustrates the structure only:
For a real request, do not reconstruct or trim the prior model content: replay the complete previous candidates[0].content, including any image, text, and thoughtSignature parts if returned. Multiple references and multi-turn results depend on the selected image model.

Troubleshooting

Check the HTTP status and the error in the response body first. Never paste API keys or complete image Base64 in logs or support requests.

Next steps

Headers

x-goog-api-key
string
required

HaiRoute API key for the native request. Alternatively, use Authorization: Bearer YOUR_API_KEY instead (choose one).

Path Parameters

model
string
required

An available Google/Gemini image model in HaiRoute

Body

application/json
contents
object[]
required

Required native Gemini messages. Use a user text part for text-to-image; add inlineData for image-to-image.

Minimum array length: 1
systemInstruction
object
generationConfig
object

Native Gemini generation settings; availability depends on the image model.

Response

Native Gemini GenerateContentResponse with images in candidates[].content.parts[].inlineData.

Native Gemini GenerateContentResponse with images in candidates[].content.parts[].inlineData.

candidates
object[]
usageMetadata
object
modelVersion
string
responseId
string