Pular para o conteúdo
Google logo

Imagen 4

Text-to-Image • Google

Ver como Markdown
  • Third-party
  • Zero data retention

Google'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
Zero data retentionYes
Pricing View pricing in the Cloudflare dashboard

Usage

const response = await env.AI.run(
  'google/imagen-4',
  { prompt: 'A golden retriever puppy playing in autumn leaves' },
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "google/imagen-4",
  "input": {
    "prompt": "A golden retriever puppy playing in autumn leaves"
  }
}'
Simple Generation
{
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "result": {
    "image": "https://pub-04a6d208d361438ea01b797e6973bd19.r2.dev/catalog/google__imagen-4/simple-generation.png"
  },
  "state": "Completed"
}

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',
  },
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "google/imagen-4",
  "input": {
    "prompt": "A dramatic drone shot of a winding river through an autumn forest, warm golden and red tones",
    "aspect_ratio": "16:9"
  }
}'
Widescreen Landscape
{
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "result": {
    "image": "https://pub-04a6d208d361438ea01b797e6973bd19.r2.dev/catalog/google__imagen-4/widescreen-landscape.png"
  },
  "state": "Completed"
}
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',
  },
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "google/imagen-4",
  "input": {
    "prompt": "An elegant Art Deco poster featuring a jazz singer under a spotlight",
    "aspect_ratio": "9:16"
  }
}'
Portrait Format
{
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "result": {
    "image": "https://pub-04a6d208d361438ea01b797e6973bd19.r2.dev/catalog/google__imagen-4/portrait-format.png"
  },
  "state": "Completed"
}
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',
  },
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "google/imagen-4",
  "input": {
    "prompt": "A chef preparing sushi in a traditional Japanese kitchen, detailed close-up",
    "person_generation": "allow_adult"
  }
}'
With People
{
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "result": {
    "image": "https://pub-04a6d208d361438ea01b797e6973bd19.r2.dev/catalog/google__imagen-4/with-people.png"
  },
  "state": "Completed"
}
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',
  },
)
console.log(response)
curl https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "google/imagen-4",
  "input": {
    "prompt": "A sleek wireless headphone on a minimalist white marble surface with soft studio lighting",
    "aspect_ratio": "1:1"
  }
}'
Product Photo
{
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "result": {
    "image": "https://pub-04a6d208d361438ea01b797e6973bd19.r2.dev/catalog/google__imagen-4/product-photo.png"
  },
  "state": "Completed"
}

Parameters

prompt
stringrequiredText prompt describing the image to generate
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
image
stringformat: uriURL to the generated image

API Schemas (Raw)

Input
Output