Imagen 3

This documentation is valid for the following list of our models:

  • imagen-3.0-generate-002

Model Overview

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.

Setup your API Key

If you don’t have an API key for the AI/ML API yet, feel free to use our Quickstart guide.

API Schema

post
Authorizations
Body
modelundefined · enumRequiredPossible values:
promptstring · max: 400Required

The text prompt for the image

convert_base64_to_urlbooleanOptional

If the condition is true, the url to the image will be returned; otherwise, the file will be provided in base64 format.

Default: false
num_imagesinteger · max: 4Optional

The number of images to generate

Default: 1
seedinteger · max: 4294967295Optional

The random seed for image generation

enhance_promptbooleanOptional

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

Default: true
aspect_ratiostring · enumOptional

The aspect ratio for the image

Default: 1:1Possible values:
person_generationstring · enumOptional

Allow generation of people by the model

Default: allow_adultPossible values:
safety_settingstring · enumOptional

Adds a filter level to safety filtering

Default: block_medium_and_abovePossible values:
add_watermarkbooleanOptional

Add an invisible watermark to the generated images

Default: false
Responses
201Success
post
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
}
201Success

No content

Quick Example

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.

Response
Generation: {'data': [{'mime_type': 'image/png', 'url': 'https://cdn.aimlapi.com/generations/guepard/1746720987715-f2285114-7255-49fd-bef4-269b37225465.png', 'prompt': "A close-up shot of a playful raccoon with a mischievous glint in its eyes, enjoying a scoop of strawberry ice cream on a hot summer day. The raccoon is perched on a park bench, its small paws delicately holding the cone as it takes a satisfying lick. The ice cream melts slightly in the warm weather, creating a delightful, drippy texture. Sunlight bathes the scene in a warm, golden light, enhancing the colours and creating a vibrant atmosphere. The background is slightly blurred, with lush greenery and a hint of a vibrant blue sky. The photo is taken with a Canon EOS R5 camera using a 50mm lens, capturing the detail of the raccoon's fur, the melting ice cream, and the bright colours of the surroundings."}]}

Default aspect ratio is 1:1, so we obtained the following 1024x1024 image by running this code example:

In reality, raccoons shouldn’t be given ice cream or chocolate—it’s harmful to their metabolism. But in the AI world, raccoons party like there’s no tomorrow.

Last updated

Was this helpful?