产品图生成 API
通过 API 从文本描述生成产品图。
概述
产品图生成 API 使用先进的 AI 技术,根据文本描述快速生成专业的产品展示图片。无需摄影设备,只需提供产品描述和场景要求,即可获得高质量的商业图片。支持一次生成 1-4 张变体,提供多种宽高比选择。
接口地址
POST https://api.aluo.ai/api/photo-generate/generate请求参数
使用 application/json 格式提交:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
prompt | string | 是 | 产品描述文本 |
size | string | 否 | 宽高比(默认 1:1) |
nVariants | number | 否 | 生成数量:1, 2, 4(默认 1) |
outputFormat | string | 否 | png | jpeg | webp (默认 png) |
resolution | string | 否 | 1K | 2K | 4K (可选) |
支持的宽高比: 1:1, 3:2, 2:3, 16:9, 9:16, 4:3, 3:4, 4:5, 5:4, 21:9
响应格式
成功响应
注意:此 API 返回 taskId 后,图片生成已完成。您可以使用 taskId 查询状态接口获取结果 URL。
{
"code": 0,
"success": true,
"data": {
"provider": "ai-provider",
"model": "default",
"taskId": "task_123456789",
"prompt": "A red coffee mug on wooden table",
"size": "1:1",
"nVariants": 1
}
}查询结果接口
GET https://api.aluo.ai/api/photo-generate/status?taskId=task_123456789{
"code": 0,
"success": true,
"data": {
"status": "SUCCESS",
"images": [
{ "url": "https://cdn.aluo.ai/result1.png" }
]
}
}请求示例
cURL
# 步骤 1: 创建生成任务
curl -X POST https://api.aluo.ai/api/photo-generate/generate \
-H "Authorization: Bearer sk-your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"prompt": "A red coffee mug on a wooden table, natural lighting",
"size": "1:1",
"nVariants": 1,
"outputFormat": "png"
}'
# 步骤 2: 查询任务结果(使用返回的 taskId)
curl -X GET "https://api.aluo.ai/api/photo-generate/status?taskId=task_123456789" \
-H "Authorization: Bearer sk-your-api-key-here"Node.js
const fetch = require('node-fetch');
// 步骤 1: 创建生成任务
const createResponse = await fetch(
'https://api.aluo.ai/api/photo-generate/generate',
{
method: 'POST',
headers: {
'Authorization': 'Bearer sk-your-api-key-here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
prompt: 'A red coffee mug on a wooden table, natural lighting',
size: '1:1',
nVariants: 1,
outputFormat: 'png'
})
}
);
const createResult = await createResponse.json();
const taskId = createResult.data.taskId;
// 步骤 2: 查询任务结果
const statusResponse = await fetch(
`https://api.aluo.ai/api/photo-generate/status?taskId=${taskId}`,
{
headers: {
'Authorization': 'Bearer sk-your-api-key-here'
}
}
);
const statusResult = await statusResponse.json();
if (statusResult.data.status === 'SUCCESS') {
console.log('Images:', statusResult.data.images);
} else if (statusResult.data.status === 'FAILED') {
console.error('Generation failed');
}Python
import requests
headers = {
'Authorization': 'Bearer sk-your-api-key-here',
'Content-Type': 'application/json'
}
# 步骤 1: 创建生成任务
create_response = requests.post(
'https://api.aluo.ai/api/photo-generate/generate',
headers=headers,
json={
'prompt': 'A red coffee mug on a wooden table, natural lighting',
'size': '1:1',
'nVariants': 1,
'outputFormat': 'png'
}
)
task_id = create_response.json()['data']['taskId']
# 步骤 2: 查询任务结果
status_response = requests.get(
f'https://api.aluo.ai/api/photo-generate/status?taskId={task_id}',
headers={'Authorization': 'Bearer sk-your-api-key-here'}
)
result = status_response.json()
if result['data']['status'] == 'SUCCESS':
print('Images:', result['data']['images'])
elif result['data']['status'] == 'FAILED':
print('Generation failed')积分消耗与处理时间
| 生成数量 | 免费用户 | PRO 用户 | 处理时间 |
|---|---|---|---|
| 1 张 | 40 积分 | 35 积分 | 通常 10-30 秒 |
| 2 张 | 80 积分 | 70 积分 | |
| 4 张 | 160 积分 | 140 积分 |
积分扣除说明: 积分由客户端在获取生成结果后扣除。如果生成失败(status: FAILED),不会扣除积分。
提示词技巧
- 详细描述产品特征(颜色、材质、形状等)
- 指定场景和环境(室内/室外、光线条件等)
- 添加氛围描述(简约、奢华、温馨等)
- 使用具体的角度和构图说明
- 保持描述清晰简洁,避免过于复杂
常见错误
| 错误信息 | 原因 | 解决方案 |
|---|---|---|
Prompt is required | 未提供 prompt | 必须提供产品描述文本 |
nVariants must be 1, 2, or 4 | 变体数量不合法 | 仅支持 1, 2, 4 三个值 |
Insufficient credits | 积分不足 | 充值积分或减少生成数量 |