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

Generate images using Gemini

POST
https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp-image-generation:generateContent
Gemini 2.0 Flash Experimental supports the ability to output text and inline images. This lets you use Gemini to conversationally edit images or generate outputs with interwoven text (for example, generating a blog post with text and images in a single turn). All generated images include a SynthID watermark, and images in Google AI Studio include a visible watermark as well.
Note: Make sure to include responseModalities: ["TEXT", "IMAGE"] in your generation configuration for text and image output with gemini-2.0-flash-exp-image-generation. Image only is not allowed.
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, can you create a 3d rendered image of a pig with wings and a top hat flying over a happy futuristic scifi city with lots of greenery?"}
      ]
    }],
    "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 {1}] 
optional
generationConfig
object 
required
responseModalities
array[string]
required
Examples

Responses

🟢200成功
application/json
Body
object {0}
Previous
Configuration parameters
Next
Image editing with Gemini
Built with