Imagen 4
Text-to-Image • Google • ProxiedGoogle's latest image generation model producing high-quality, photorealistic images from text prompts with support for multiple aspect ratios.
| Model Info | |
|---|---|
| Terms and License | link ↗ |
| More information | link ↗ |
Usage
const response = await env.AI.run( 'google/imagen-4', { prompt: 'A golden retriever puppy playing in autumn leaves', }, { gateway: { id: 'default' }, })console.log(response)
Examples
Widescreen Landscape — Generate a widescreen landscape image
const response = await env.AI.run( 'google/imagen-4', { prompt: 'A dramatic drone shot of a winding river through an autumn forest, warm golden and red tones', aspect_ratio: '16:9', }, { gateway: { id: 'default' }, })console.log(response)
Portrait Format — Vertical portrait-style image
const response = await env.AI.run( 'google/imagen-4', { prompt: 'An elegant Art Deco poster featuring a jazz singer under a spotlight', aspect_ratio: '9:16', }, { gateway: { id: 'default' }, })console.log(response)
With People — Allow generation of adult people
const response = await env.AI.run( 'google/imagen-4', { prompt: 'A chef preparing sushi in a traditional Japanese kitchen, detailed close-up', person_generation: 'allow_adult', }, { gateway: { id: 'default' }, })console.log(response)
Product Photo — Square product photography
const response = await env.AI.run( 'google/imagen-4', { prompt: 'A sleek wireless headphone on a minimalist white marble surface with soft studio lighting', aspect_ratio: '1:1', }, { gateway: { id: 'default' }, })console.log(response)
Parameters
stringrequiredText prompt describing the image to generatestringenum: 1:1, 3:4, 4:3, 9:16, 16:9Aspect ratio of the generated imagestringenum: dont_allow, allow_adult, allow_allAllow the model to generate images of people. dont_allow: block people, allow_adult: adults only, allow_all: adults and childrenstringformat: uriURL to the generated imageAPI Schemas
{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "prompt": { "description": "Text prompt describing the image to generate", "type": "string" }, "aspect_ratio": { "description": "Aspect ratio of the generated image", "type": "string", "enum": [ "1:1", "3:4", "4:3", "9:16", "16:9" ] }, "person_generation": { "description": "Allow the model to generate images of people. dont_allow: block people, allow_adult: adults only, allow_all: adults and children", "type": "string", "enum": [ "dont_allow", "allow_adult", "allow_all" ] } }, "required": [ "prompt" ], "additionalProperties": false}{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "image": { "description": "URL to the generated image", "type": "string", "format": "uri" } }, "required": [ "image" ], "additionalProperties": false}