Google Gemini API
  1. Generate images
Google Gemini API
  • Get API key
  • Release notes
  • Libraries
  • Run Gemini on Google Cloud
  • Model Capabilities
    • Overview
    • Long context
    • Structured output
    • Document understanding
    • Image understanding
    • Video understanding
    • Audio understanding
    • Text generation
      • Text input
      • Image input
      • Streaming output
      • Multi-turn conversations
      • Multi-turn conversations (Streaming)
      • Configuration parameters
    • Generate images
      • Generate images using Gemini
        POST
      • Image editing with Gemini
        POST
      • Generate images using Imagen 3
        POST
    • Gemini thinking
      • Use thinking models
      • Set budget on thinking models
    • Function calling
      • Function Calling with the Gemini API
  • models
    • All Model
    • Pricing
    • Rate limits
    • Billing info
  • Safety
    • Safety settings
    • Safety guidance
  1. Generate images

Image editing with Gemini

POST
https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp-image-generation:generateContent
To perform image editing, add an image as input. The following example demonstrats uploading base64 encoded images. For multiple images and larger payloads, check the image input section.

Limitations#

For best performance, use the following languages: EN, es-MX, ja-JP, zh-CN, hi-IN.
Image generation does not support audio or video inputs.
Image generation may not always trigger:
The model may output text only. Try asking for image outputs explicitly (e.g. "generate an image", "provide images as you go along", "update the image").
The model may stop generating partway through. Try again or try a different prompt.
When generating text for an image, Gemini works best if you first generate the text and then ask for an image with the text.
Request Request Example
Shell
JavaScript
Java
Swift
curl --location -g --request POST 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp-image-generation:generateContent?key=' \
--header 'Content-Type: application/json' \
--data-raw '{
      "contents": [{
        "parts":[
            {"text": "'\''Hi, This is a picture of me. Can you add a llama next to me"},
            {
              "inline_data": {
                "mime_type":"image/jpeg",
                "data": "$IMG_BASE64"
              }
            }
        ]
      }],
      "generationConfig": {"responseModalities": ["TEXT", "IMAGE"]}
    }'
Response Response Example
{}

Request

Query Params
key
string 
required
Example:
{{GEMINI_API_KEY}}
Header Params
Content-Type
string 
required
Example:
application/json
Body Params application/json
contents
array [object {1}] 
required
parts
array [object {2}] 
optional
generationConfig
object 
required
responseModalities
array[string]
required
Examples

Responses

🟢200成功
application/json
Body
object {0}
Previous
Generate images using Gemini
Next
Generate images using Imagen 3
Built with