- 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