Imagen 3
Last updated
Was this helpful?
Last updated
Was this helpful?
Google's latest text-to-image AI model, designed to generate high-quality, photorealistic images from text descriptions with improved detail, lighting, and fewer artifacts. It boasts enhanced natural language understanding and better text rendering.
If you don’t have an API key for the AI/ML API yet, feel free to use our Quickstart guide.
Let's generate an image of the specified size using a simple prompt.
import requests
def main():
response = requests.post(
"https://api.aimlapi.com/v1/images/generations",
headers={
# Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>:
"Authorization": "Bearer <YOUR_AIMLAPI_KEY>",
"Content-Type": "application/json",
},
json={
"prompt": "Racoon eating ice-cream",
"model": "imagen-3.0-generate-002",
"convert_base64_to_url": True,
}
)
response.raise_for_status()
data = response.json()
print("Generation:", data)
if __name__ == "__main__":
main()
Note that prompt enhancement is enabled by default. The model will also return the enhanced prompt in the response. If you prefer not to use this feature, set the parameter enhance_prompt
to False
.
Default aspect ratio is 1:1, so we obtained the following 1024x1024 image by running this code example:
The text prompt for the image
If the condition is true, the url to the image will be returned; otherwise, the file will be provided in base64 format.
false
The number of images to generate
1
The random seed for image generation
An optional parameter to use an LLM-based prompt rewriting feature to deliver higher quality images that better reflect the original prompt's intent. Disabling this feature may impact image quality and prompt adherence
true
The aspect ratio for the image
1:1
Possible values: Allow generation of people by the model
allow_adult
Possible values: Adds a filter level to safety filtering
block_medium_and_above
Possible values: Add an invisible watermark to the generated images
false
POST /v1/images/generations HTTP/1.1
Host: api.aimlapi.com
Authorization: Bearer <YOUR_AIMLAPI_KEY>
Content-Type: application/json
Accept: */*
Content-Length: 246
{
"model": "imagen-3.0-generate-002",
"prompt": "text",
"convert_base64_to_url": false,
"num_images": 1,
"seed": 1,
"enhance_prompt": true,
"aspect_ratio": "1:1",
"person_generation": "allow_adult",
"safety_setting": "block_medium_and_above",
"add_watermark": false
}
No content