Skip to main content
POST
Text-to-Image: Generate an image from a text prompt
The interactive Playground on the right supports dropdown selection for parameters (aspect ratio, resolution, response type, etc.). Enter your API Key in the Authorization field (format: Bearer sk-xxx) to send test requests with one click.
Scope: This page is for text-to-image generation. Just enter a prompt — no image upload required. For editing an existing image, use the Image Editing endpoint.
🖥️ Browser Playground limitation (important)This endpoint returns a base64-encoded image (inlineData.data, typically several MB) in the response. Due to browser rendering limits, the Playground on the right may show 请求时发生错误: unable to complete request after the response arrives — the request actually succeeded; the browser just can’t render such a long base64 string.Recommended workflow (beginner-friendly):
  • Copy the Python / Node.js / cURL sample below and run it locally. The code automatically base64.b64decodes the response and writes the image to a file.
  • If you must use the in-browser Playground, set imageSize to the smallest tier (e.g. 1K) to shrink the response.
All image APIs are synchronous — there is no task ID to poll, and if your client disconnects the result is lost while the request is still billed. Set a generous timeout for this model; see Image API Essentials & Best Practices.

Code Examples

Python

cURL

Node.js

Parameter Quick Reference

See the field descriptions in the Playground on the right for detailed parameter docs, allowed values, and defaults. All enum-type fields (like aspectRatio, imageSize) support dropdown selection — no manual typing needed.
Unsupported FeaturesThe following Google official features are not supported via APIYI and require separate billing:
  • Grounding with Google Search: Real-time search info via tools: [{"google_search": {}}]
  • thinkingConfig (Thinking mode): Only supported on Nano Banana 2, not on Nano Banana Pro
For search grounding features, please contact support for separate billing options.

Authorizations

Authorization
string
header
required

API Key from APIYI Console

Body

application/json
contents
object[]
required

Content array containing the text prompt

generationConfig
object
required

Response

Image generated successfully

candidates
object[]

Generated results array

usageMetadata
object