Authentication
authorization string required
All APIs require authentication via Bearer Token.
Get API Key:
Visit API Key Management Page to get your API Key
Usage:
Add to request header:
Authorization: Bearer YOUR_API_KEY
Parameters
model string required
Model ID to use for the request.
Value: nano_banana_2
prompt string required
Image generation prompt, length must be between 1-2500 characters
Prompt guidelines:
- Realistic scenes: Use photography terminology. Mention shooting angles, lens types, lighting, and details to guide the model to generate realistic effects
- Stylized illustrations and stickers: To create stickers, icons, or assets, clearly state the style and request a transparent background
- Accurate text in images: Gemini excels at rendering text. Clearly specify the text, font style (descriptive), and overall design
- Product mockups and commercial photography: Ideal for creating clear professional product photos for e-commerce, advertising, or branding
- Minimalist style and negative space design: Great for creating backgrounds for websites, presentations, or marketing materials to overlay text
image_urls array
Maximum 3 images can be accepted as input
aspect_ratio string
Image aspect ratio
Options: 1:8, 1:4, 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 8:1, 4:1, 9:16, 16:9, 21:9
resolution string
Image resolution
Options: 0.5K, 1K, 2K, 4K
Default: 1K
response_modalities string
By default, the model returns both text and image responses (i.e., response_modalities=[‘Text’, ‘Image’]). You can configure the response to return only images without text using response_modalities=[‘Image’]
Polling
Since result generation takes time, you need to poll the task status after creating the task.
The initial response only returns information such as the task ID and initial status. The final result must be obtained by polling the task status endpoint using the task ID.
See the examples on the right for polling requests and responses.
Response Format
error object
Error information. Only present when status is failed.
code
integerError code.
error_message
stringDetailed error message.
output array
Generation results. Only present when status is completed.
content
arrayList of generated content
type
stringResource type
Options:
image,texturl
stringContent URL
usage object
Usage statistics. Only present when status is completed
prompt_tokens
integerPrompt tokens
completion_tokens
integerCompletion tokens
total_tokens
integerTotal tokens
metadata object
Metadata information
Error Codes
| Error Code | Description |
|---|---|
| 005001095 | Internal generation error |
| 005001096 | Result parsing error |
| 005001097 | HTTP error response |
| 005001098 | Synchronous generation error |