基于 Stable Diffusion 的电商图像生成服务
v2.0 - 已启用 API Key 鉴权https://api.ai-baidu.com/api/
所有接口(除根路径)都必须带上 X-API-Key 请求头。
bd- 开头bd-a8d07ce05c54cd6e135ca90629a76e72在 HTTP 请求头中添加:
Headers: Content-Type: application/json X-API-Key: bd-a8d07ce05c54cd6e135ca90629a76e72
联系管理员生成。每个 Key 可以随时启用/禁用,便于管理。
bd-demo1234567890abcdef1234567890ab
| HTTP状态码 | 错误类型 | 说明 | 解决方案 |
|---|---|---|---|
| 401 | missing_api_key | 没有带 X-API-Key | 在请求头加上 X-API-Key |
| 401 | invalid_key_format | Key 不是 bd- 开头 | 检查 Key 格式 |
| 403 | invalid_api_key | Key 不存在或被禁用 | 联系管理员重新生成 |
| 200 | - | 调用成功 | - |
import requests API_KEY = "bd-a8d07ce05c54cd6e135ca90629a76e72" # 替换成你的Key response = requests.post( "https://api.ai-baidu.com/api/text2img", headers={"X-API-Key": API_KEY}, json={ "prompt": "premium gift box, wooden table, warm lighting", "style": "product_photo" } ) data = response.json() import base64 with "output.png", "wb") as f: f.write(base64.b64decode(data["image"]))
const API_KEY = "bd-a8d07ce05c54cd6e135ca90629a76e72"; const response = await fetch("https://api.ai-baidu.com/api/text2img", { method: "POST", headers: { "Content-Type": "application/json", "X-API-Key": API_KEY }, body: JSON.stringify({ prompt: "luxury gift box", style: "product_photo" }) }); const data = await response.json();
curl -X POST https://api.ai-baidu.com/api/text2img \ -H "Content-Type: application/json" \ -H "X-API-Key: bd-a8d07ce05c54cd6e135ca90629a76e72" \ -d '{"prompt":"gift box","style":"product_photo"}'
文生图:根据文字描述生成图片
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
prompt | string | 必填 | 图片描述,30-200字效果最佳 |
style | string | 可选 | product_photo | lifestyle | festive |
width | integer | 可选 | 宽度 512-2048,默认1024 |
height | integer | 可选 | 高度 512-2048,默认1024 |
图改图:基于原图生成新版本
| 字段 | 位置 | 必填 | 说明 |
|---|---|---|---|
image | form-data | 必填 | 原图文件 |
prompt | query | 必填 | 目标效果描述 |
strength | query | 可选 | 修改强度 0-1,默认0.7 |
style | query | 可选 | 风格 |
局部重绘:用蒙版标记区域重绘
| 字段 | 位置 | 必填 | 说明 |
|---|---|---|---|
image | form-data | 必填 | 原图 |
mask | form-data | 必填 | 蒙版(白色=重绘区域) |
prompt | query | 必填 | 重绘内容描述 |
style | query | 可选 | 风格 |
查看历史生成记录
系统统计
支持3种风格预设:产品摄影、生活方式、节日氛围
上传原图+描述,生成优化版本
用蒙版标记区域,精准修改
每次生成的样本自动保存
每个Key可独立启用/禁用
记录每个Key的调用次数
| style | 中文名 | 适用场景 |
|---|---|---|
product_photo | 产品摄影 | 电商主图、商品详情、白底图 |
lifestyle | 生活方式 | 使用场景图、生活化氛围 |
festive | 节日氛围 | 节庆、促销、礼盒场景 |
[主体描述] + [材质质感] + [光线氛围] + [构图角度] + [质量标签]
"premium gift box with red ribbon, matte finish, wooden table,
studio lighting with soft shadows, eye-level angle, shot on Canon EOS R5,
8k, high detail, professional product photography"
"fresh bamboo leaves arranged on kitchen counter, morning sunlight
streaming through window, bokeh background, cozy atmosphere, shot from
above, lifestyle photography, natural colors"
| 项 | 当前限制 |
|---|---|
| 请求频率 | 无限制(测试模式) |
| 图片尺寸 | 512 - 2048 像素 |
| 文件上传 | 最大 10MB |
| Prompt 长度 | 建议 30-500 字 |