跳转到内容
本站为社区维护的非官方中文翻译,与 Cloudflare, Inc. 无关联。本站不提供账户登录,请勿在任何非官方站点输入您的 Cloudflare 账户信息。官方文档:developers.cloudflare.com
Google logo

Imagen 4

Text-to-Image • Google

查看 MarkdownAgent 设置
  • Third-party
  • Zero data retention

Google 最新的图像生成模型,可根据文本提示词生成高质量、照片级真实感的图像,并支持多种宽高比。

模型信息
条款和许可证链接 ↗
更多信息链接 ↗
零数据保留是
定价在 Cloudflare 仪表板中查看定价 ↗

用法

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"
  }
}'
简单生成
{
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "result": {
    "image": "https://pub-04a6d208d361438ea01b797e6973bd19.r2.dev/catalog/google__imagen-4/simple-generation.png"
  },
  "state": "Completed"
}

示例

宽屏风景 — 生成宽屏风景图像
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"
  }
}'
宽屏风景
{
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "result": {
    "image": "https://pub-04a6d208d361438ea01b797e6973bd19.r2.dev/catalog/google__imagen-4/widescreen-landscape.png"
  },
  "state": "Completed"
}
竖版格式 — 竖版人像风格图像
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"
  }
}'
竖版格式
{
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "result": {
    "image": "https://pub-04a6d208d361438ea01b797e6973bd19.r2.dev/catalog/google__imagen-4/portrait-format.png"
  },
  "state": "Completed"
}
包含人物 — 允许生成成年人图像
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"
  }
}'
包含人物
{
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "result": {
    "image": "https://pub-04a6d208d361438ea01b797e6973bd19.r2.dev/catalog/google__imagen-4/with-people.png"
  },
  "state": "Completed"
}
产品照片 — 方形产品摄影
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"
  }
}'
产品照片
{
  "gatewayMetadata": {
    "keySource": "Unified"
  },
  "result": {
    "image": "https://pub-04a6d208d361438ea01b797e6973bd19.r2.dev/catalog/google__imagen-4/product-photo.png"
  },
  "state": "Completed"
}

参数

prompt
stringrequired描述要生成的图像的文本提示词
aspect_ratio
stringenum: 1:1, 3:4, 4:3, 9:16, 16:9生成图像的宽高比
person_generation
stringenum: dont_allow, allow_adult, allow_all允许模型生成包含人物的图像。dont_allow:禁止生成人物,allow_adult:仅限成年人,allow_all:成年人和儿童
image
stringformat: uri生成图像的 URL

API schema(原始)

输入
输出

这篇文档对您有帮助吗?