AI 模型接口图像imagen接口imagen 图像生成
imagen-4.0-generate-001 图像生成接口
Imagen 4 Standard 图像生成接口
用于高质量写实图像、插画、产品视觉和通用创意资产生成。
Authorization
BearerAuth
AuthorizationBearer <token>
模型 relay 接口鉴权。请求头:Authorization: Bearer 。
In: header
Path Parameters
model*string
Gemini 模型名。
Default
"imagen-4.0-generate-001"Request Body
application/json
[key: string]?any
Response Body
application/json
curl -X POST "https://api.tokaify.com/v1beta/models/imagen-4.0-generate-001:predict" \ -H "Content-Type: application/json" \ -d '{}'{}请求参数
| 字段 | 类型 | 必选 | 默认值 | 描述 |
|---|---|---|---|---|
instances | array | 是 | 无 | 预测输入数组,Imagen 通常只需要一个实例。 |
instances[].prompt | string | 是 | 无 | 英文提示词,官方建议最大 480 tokens。 |
parameters.sampleCount | integer | 否 | 4 | 生成图片数量,范围 1 到 4。 |
parameters.aspectRatio | string | 否 | 1:1 | 支持 1:1、3:4、4:3、9:16、16:9。 |
parameters.imageSize | string | 否 | 1K | 输出尺寸档位,支持 1K、2K。 |
parameters.personGeneration | string | 否 | allow_adult | 人物生成策略,支持 dont_allow、allow_adult、allow_all;部分地区不允许 allow_all。 |
示例代码
curl "https://api.tokaify.com/v1beta/models/imagen-4.0-generate-001:predict" \
-H "Authorization: Bearer $TOKAIFY_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"instances": [{ "prompt": "A premium SaaS API gateway product poster, dark background, crisp typography" }],
"parameters": {
"sampleCount": 1,
"aspectRatio": "16:9",
"imageSize": "2K",
"personGeneration": "dont_allow"
}
}'import requests
response = requests.post(
"https://api.tokaify.com/v1beta/models/imagen-4.0-generate-001:predict",
headers={"Authorization": "Bearer YOUR_TOKAIFY_API_KEY"},
json={
"instances": [{"prompt": "A premium SaaS API gateway product poster, dark background, crisp typography"}],
"parameters": {"sampleCount": 1, "aspectRatio": "16:9", "imageSize": "2K", "personGeneration": "dont_allow"},
},
)
print(response.json())const response = await fetch("https://api.tokaify.com/v1beta/models/imagen-4.0-generate-001:predict", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.TOKAIFY_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
instances: [{ prompt: "A premium SaaS API gateway product poster, dark background, crisp typography" }],
parameters: { sampleCount: 1, aspectRatio: "16:9", imageSize: "2K", personGeneration: "dont_allow" },
}),
});
console.log(await response.json());响应示例
{
"predictions": [
{
"bytesBase64Encoded": "iVBORw0KGgoAAAANSUhEUg...",
"mimeType": "image/png"
}
]
}业务提示
计费倍率按后台模型倍率与渠道倍率配置执行。Imagen 4 输出包含 SynthID 水印;如要批量生成,请控制 sampleCount,避免单次请求过大导致超时。
这篇文档对您有帮助吗?
最后更新于