图像接口 (Image)
约 861 字大约 3 分钟
2025-02-10
图像接口支持 AI 图像生成,包括 DALL·E 和 Midjourney 等模型。
DALL·E 图像生成
接口地址
POST https://api.ai.webweb.cn/v1/images/generations请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型名称:dall-e-2 或 dall-e-3 |
| prompt | string | 是 | 图像描述提示词 |
| n | integer | 否 | 生成图像数量,默认 1 |
| size | string | 否 | 图像尺寸 |
| quality | string | 否 | 图像质量:standard 或 hd(仅 DALL·E 3) |
| style | string | 否 | 图像风格:vivid 或 natural(仅 DALL·E 3) |
| response_format | string | 否 | 返回格式:url 或 b64_json |
支持的尺寸
DALL·E 2:
- 256x256
- 512x512
- 1024x1024
DALL·E 3:
- 1024x1024
- 1024x1792
- 1792x1024
请求示例
cURL
curl https://api.ai.webweb.cn/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "dall-e-3",
"prompt": "一只可爱的橘猫坐在窗台上看日落,油画风格",
"n": 1,
"size": "1024x1024",
"quality": "hd"
}'Python
from openai import OpenAI
client = OpenAI(
api_key="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
base_url="https://api.ai.webweb.cn/v1"
)
response = client.images.generate(
model="dall-e-3",
prompt="一只可爱的橘猫坐在窗台上看日落,油画风格",
n=1,
size="1024x1024",
quality="hd"
)
print(response.data[0].url)JavaScript
import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: 'sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
baseURL: 'https://api.ai.webweb.cn/v1'
});
const response = await openai.images.generate({
model: 'dall-e-3',
prompt: '一只可爱的橘猫坐在窗台上看日落,油画风格',
n: 1,
size: '1024x1024',
quality: 'hd'
});
console.log(response.data[0].url);响应示例
{
"created": 1234567890,
"data": [
{
"url": "https://...",
"revised_prompt": "优化后的提示词..."
}
]
}图像编辑
接口地址
POST https://api.ai.webweb.cn/v1/images/edits请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| image | file | 是 | 原始图像(PNG,小于4MB) |
| mask | file | 否 | 遮罩图像,标识需要编辑的区域 |
| prompt | string | 是 | 编辑描述 |
| n | integer | 否 | 生成数量 |
| size | string | 否 | 输出尺寸 |
请求示例
from openai import OpenAI
client = OpenAI(
api_key="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
base_url="https://api.ai.webweb.cn/v1"
)
response = client.images.edit(
model="dall-e-2",
image=open("original.png", "rb"),
mask=open("mask.png", "rb"),
prompt="在图片中添加一只蝴蝶",
n=1,
size="1024x1024"
)
print(response.data[0].url)图像变体
接口地址
POST https://api.ai.webweb.cn/v1/images/variations请求示例
from openai import OpenAI
client = OpenAI(
api_key="sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
base_url="https://api.ai.webweb.cn/v1"
)
response = client.images.create_variation(
image=open("original.png", "rb"),
n=2,
size="1024x1024"
)
for i, img in enumerate(response.data):
print(f"变体 {i+1}: {img.url}")Midjourney 代理
提交任务
POST https://api.ai.webweb.cn/mj/submit/imagine请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| prompt | string | 是 | 图像描述提示词 |
| base64 | string | 否 | 垫图的 base64 编码 |
| notifyHook | string | 否 | 回调通知地址 |
| state | string | 否 | 自定义状态值 |
请求示例
curl https://api.ai.webweb.cn/mj/submit/imagine \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"prompt": "a cute cat, anime style --ar 16:9 --v 6"
}'响应示例
{
"code": 1,
"description": "提交成功",
"result": "1234567890"
}查询任务
GET https://api.ai.webweb.cn/mj/task/{task_id}/fetch响应示例
{
"id": "1234567890",
"action": "IMAGINE",
"prompt": "a cute cat, anime style --ar 16:9 --v 6",
"status": "SUCCESS",
"imageUrl": "https://...",
"progress": "100%"
}Midjourney 参数说明
| 参数 | 说明 | 示例 |
|---|---|---|
| --ar | 宽高比 | --ar 16:9 |
| --v | 版本 | --v 6 |
| --q | 质量 | --q 2 |
| --s | 风格化程度 | --s 750 |
| --c | 混乱度 | --c 50 |
| --no | 排除元素 | --no text |
提示词最佳实践
1. 详细描述
❌ 一只猫
✅ 一只橘色的英短猫,坐在阳光明媚的窗台上,背景是模糊的城市天际线,暖色调,电影级光影2. 指定风格
油画风格、水彩风格、赛博朋克、像素艺术、写实摄影、日系动漫、3D渲染3. 指定视角
鸟瞰图、特写镜头、全身照、侧面照、正面照、45度角4. 指定光线
黄金时刻、蓝调时刻、霓虹灯光、柔和自然光、戏剧性光影价格说明
| 模型 | 尺寸 | 单价 |
|---|---|---|
| DALL·E 3 | 1024x1024 | ¥0.28 |
| DALL·E 3 | 1024x1792 | ¥0.42 |
| DALL·E 2 | 1024x1024 | ¥0.14 |
| Midjourney | 任意 | ¥0.35 |
