Imagen4 图片生成
POST https://ai-api.mandao.com/v1beta/models/{model}:predict
使用 Imagen4 模型生成图片,Gemini Vertex AI 原生格式。
请求参数
路径参数
| 参数名 | 类型 | 必需 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型 ID:imagen-4.0-generate-001、imagen-4.0-fast-generate-001、imagen-4.0-ultra-generate-001 |
Body 参数 (application/json)
| 参数名 | 类型 | 必需 | 默认值 | 说明 |
|---|---|---|---|---|
| instances | array[object] | 是 | - | 生成实例列表 |
| instances[].prompt | string | 是 | - | 图片生成提示词 |
| parameters | object | 是 | - | 生成参数 |
| parameters.sampleCount | integer | 否 | 4 | 生成图片数量 |
| parameters.aspectRatio | string | 否 | 1:1 | 图片宽高比。可选:1:1、4:3、3:4、16:9、9:16 |
| parameters.imageFormat | string | 否 | image/png | 图片格式 |
| parameters.addWatermark | boolean | 否 | - | 是否添加水印 |
| parameters.negativePrompt | string | 否 | - | 负向提示词 |
| parameters.safetySetting | string | 否 | - | 安全过滤级别:block_most 等 |
请求示例
curl --location 'https://ai-api.mandao.com/v1beta/models/imagen-4.0-generate-001:predict' \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data '{
"instances": [
{
"prompt": "A futuristic laboratory with a transparent holographic display showing complex molecular structures."
}
],
"parameters": {
"sampleCount": 2,
"aspectRatio": "16:9",
"imageFormat": "image/png",
"addWatermark": true,
"negativePrompt": "blurry, distorted hands, low quality, cartoonish",
"safetySetting": "block_most"
}
}'
返回响应
返回生成的图片数据(Base64 编码或 URL)。
注意事项
- Imagen4 通过 Gemini 路径访问,使用 Vertex AI 原生格式。
- 支持 URL query
?key=参数传递 API Key。