Use prompt rewriter Stay organized with collections Save and categorize content based on your preferences.
Try image generation (Vertex AI Studio)
Imagen on Vertex AI offers an LLM-based prompt rewriting tool, also known as aprompt rewriter. The prompt rewriter helps you obtain higher quality outputimages by adding more detail to your prompt.
If you disable the prompt rewriter, the quality of the images and how well theoutput resembles the prompt that you supplied may be impacted. This feature isenabled by default for the following model versions:
imagen-4.0-generate-001imagen-4.0-fast-generate-001imagen-4.0-ultra-generate-001imagen-3.0-generate-002
The rewritten prompt is delivered by API response only if the original promptis fewer than 30 words long.
Important:imagen-4.0-fast-generate-001 may generate undesireableresults if the prompt is complex and you use enhanced prompts. To fix this,avoid usingHelp me write in Google Cloud console, or setenhancePrompt tofalse.Use the prompt rewriter
To use the prompt rewriter, do the following:
Console
In the Google Cloud console, go to theVertex AI> MediaStudio page.
ClickImagen. The Imagen Media Studio image generation page isdisplayed.
In theSettings panel, adjust the following options:
Model: Choose a model from the available options.
For more information about available models, seeImagenmodels
Number of results: Adjust the slider or enter a value between1 and4.
In theNegative prompt box, enter a prompt that describes whatyou don't want generated in the image.
In theWrite your prompt box, clickHelp me write.
TheEnhance my prompt window is displayed.
In theCurrent prompt box, write your prompt, and then clickEnhance.
The rewritten prompt is displayed in theEnhanced prompt box. Youcan edit the enhanced prompt or use it as displayed.
ClickInsert to use the displayed prompt.
The prompt is inserted into theWrite your prompt box.
ClickGenerate.
REST
Before using any of the request data, make the following replacements:
- PROJECT_ID: Your Google Cloudproject ID.
- MODEL_VERSION: The image generation model version to use.
For more information about model versions and features, seemodel versions.
- LOCATION: Your project's region. For example,
us-central1,europe-west2, orasia-northeast3. For a list of available regions, seeGenerative AI on Vertex AI locations. - TEXT_PROMPT: The text prompt that guides what images the model generates. Before images are generated, this base prompt is enhanced with more detail and descripitive language using the LLM-based prompt rewriting tool.
- IMAGE_COUNT: An integer, describing the number of images to generate. The accepted values are
1-4. The default value is4. - PROMPT_SETTING: A boolean value,
trueenables enhanced prompts andfalsedisables enhanced prompts. The default value istrue.
HTTP method and URL:
POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict
Request JSON body:
{ "instances": [ { "prompt": "TEXT_PROMPT" } ], "parameters": { "sampleCount":IMAGE_COUNT, "enhancePrompt":PROMPT_SETTING }}To send your request, choose one of these options:
curl
Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login , or by usingCloud Shell, which automatically logs you into thegcloud CLI . You can check the currently active account by runninggcloud auth list. Save the request body in a file namedrequest.json, and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict"
PowerShell
Note: The following command assumes that you have logged in to thegcloud CLI with your user account by runninggcloud init orgcloud auth login . You can check the currently active account by runninggcloud auth list. Save the request body in a file namedrequest.json, and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict" | Select-Object -Expand Content
prompt field that shows the enhanced prompt and its associatedgenerated image:{"predictions":[{"mimeType":"MIME_TYPE","prompt":"ENHANCED_PROMPT_1","bytesBase64Encoded":"BASE64_IMG_BYTES_1"},{"mimeType":"MIME_TYPE","prompt":"ENHANCED_PROMPT_2","bytesBase64Encoded":"BASE64_IMG_BYTES_2"}]}
For example, the following sample response is for a request with"sampleCount": 2 and"prompt": "A raccoon wearing formal clothes, wearing a top hat. Oil painting in the style of Vincent VanGogh.". The response returns two prediction objects, each with theirenhanced prompt and the generated image bytes base64-encoded.
{ "predictions": [ { "mimeType": "image/png", "prompt": "An oil painting in the style of Vincent van Gogh, depicting a raccoon adorned in a finely tailored tuxedo, complete with a crisp white shirt and a bow tie. The raccoon also sports a classic top hat, perched jauntily on its head. The painting uses thick, swirling brushstrokes characteristic of van Gogh, with vibrant hues of blue, yellow, and green in the background, contrasting with the dark tones of the raccoon's attire. The light source is subtly placed, casting a dramatic shadow of the raccoon's attire onto the surface it sits upon, further enhancing the depth and dimensionality of the composition. The overall impression is one of a whimsical and sophisticated character, a raccoon elevated to a higher class through its formal attire, rendered in van Gogh's iconic style.", "bytesBase64Encoded": "BASE64_IMG_BYTES" }, { "mimeType": "image/png", "prompt": "An oil painting in the style of Vincent van Gogh featuring a raccoon in a dapper suit, complete with a black jacket, crisp white shirt, and a black bow tie. The raccoon is wearing a black top hat, adding a touch of elegance to its ensemble. The painting is rendered with characteristic van Gogh brushwork, utilizing thick, impasto strokes of color. The background is a swirl of blues, greens, and yellows, creating a vibrant yet slightly chaotic atmosphere that contrasts with the raccoon's formal attire. The lighting is dramatic, casting sharp shadows and highlighting the textures of the fabric and the raccoon's fur, enhancing the sense of realism within the fantastical scene. The composition focuses on the raccoon's proud posture, highlighting the whimsical contrast of a wild animal dressed in formal attire, captured in the unique artistic language of van Gogh.", "bytesBase64Encoded": "BASE64_IMG_BYTES" } ]}What's next
- Set text prompt language
- Configure aspect ratio
- Omit content using a negative prompt
- Generate deterministic images
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.