图片生成
http
POST https://gateway.hihapi.com/doubao/api/v3/images/generations用文字描述生成图片。当前提供豆包 Seedream 系列模型,可用模型和价格见模型列表。
请求示例
bash
curl https://gateway.hihapi.com/doubao/api/v3/images/generations \
-H "Authorization: Bearer $HIHAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "doubao-seedream-5-0-pro-260628",
"prompt": "窗边的一只猫,午后阳光,胶片质感",
"size": "2K"
}'python
import os
import requests
response = requests.post(
"https://gateway.hihapi.com/doubao/api/v3/images/generations",
headers={"Authorization": f"Bearer {os.environ['HIHAI_API_KEY']}"},
json={
"model": "doubao-seedream-5-0-pro-260628",
"prompt": "窗边的一只猫,午后阳光,胶片质感",
"size": "2K",
},
timeout=120,
)
response.raise_for_status()
print(response.json())js
const response = await fetch("https://gateway.hihapi.com/doubao/api/v3/images/generations", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.HIHAI_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "doubao-seedream-5-0-pro-260628",
prompt: "窗边的一只猫,午后阳光,胶片质感",
size: "2K",
}),
});
if (!response.ok) throw new Error(await response.text());
console.log(await response.json());请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 图片模型 ID |
prompt | string | 是 | 画面描述 |
size | string | 否 | 图片尺寸,可选 1K、2K、4K、auto,默认 2K |
image | string / array | 否 | 参考图片的地址,图生图时使用。可以传一张或多张 |
watermark | boolean | 否 | 是否在图片上添加水印,默认 true |
这个接口沿用火山方舟图片生成 API 的请求和响应格式,其余参数可参考火山方舟文档。
响应
json
{
"model": "doubao-seedream-5-0-pro-260628",
"created": 1779348818,
"data": [
{
"url": "https://..."
}
]
}data 数组里每一项是一张图片,url 是图片地址。图片地址有时效,拿到后请及时下载保存到自己的存储。
计费
图片按张计费,价格随图片的像素总数分档,较大尺寸的图片单价更高。带参考图时,输入图片另外按张计费。具体价格见模型列表。
写好提示词
- 先写主体,再写环境、光线和风格,例如「一只橘猫趴在木质窗台上,午后逆光,浅景深,胶片质感」。
- 需要图中出现文字时,把文字内容用引号标出来。
- 结果不理想时,优先补充细节,而不是堆叠形容词。
常见问题
请求被拒绝,提示内容未通过审核
提示词或参考图触发了内容安全审核,对应错误 AI_CONTENT_FILTERED。调整描述后重试。
请求超时
图片生成比文本慢,请把客户端超时时间设到 60 秒以上。