Skip to content
Google logo

Imagen 4

Text-to-ImageGoogleProxied

Google's latest image generation model producing high-quality, photorealistic images from text prompts with support for multiple aspect ratios.

Model Info
Terms and Licenselink
More informationlink
PricingView pricing in the Cloudflare dashboard

Usage

TypeScript
const response = await env.AI.run(
'google/imagen-4',
{ prompt: 'A golden retriever puppy playing in autumn leaves' },
)
console.log(response)
Simple Generation

Examples

Widescreen Landscape — Generate a widescreen landscape image
TypeScript
const response = await env.AI.run(
'google/imagen-4',
{
aspect_ratio: '16:9',
prompt:
'A dramatic drone shot of a winding river through an autumn forest, warm golden and red tones',
},
)
console.log(response)
Widescreen Landscape
Portrait Format — Vertical portrait-style image
TypeScript
const response = await env.AI.run(
'google/imagen-4',
{
aspect_ratio: '9:16',
prompt: 'An elegant Art Deco poster featuring a jazz singer under a spotlight',
},
)
console.log(response)
Portrait Format
With People — Allow generation of adult people
TypeScript
const response = await env.AI.run(
'google/imagen-4',
{
person_generation: 'allow_adult',
prompt: 'A chef preparing sushi in a traditional Japanese kitchen, detailed close-up',
},
)
console.log(response)
With People
Product Photo — Square product photography
TypeScript
const response = await env.AI.run(
'google/imagen-4',
{
aspect_ratio: '1:1',
prompt:
'A sleek wireless headphone on a minimalist white marble surface with soft studio lighting',
},
)
console.log(response)
Product Photo

Parameters

aspect_ratio
stringenum: 1:1, 3:4, 4:3, 9:16, 16:9Aspect ratio of the generated image
person_generation
stringenum: 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 children
prompt
stringrequiredText prompt describing the image to generate

API Schemas (Raw)

Input
Output