API 参考文档
图像编辑
按指令或区域编辑图像、替换背景、调整宽高比、重新配色或替换文字。
操作#
POST /images/edits 接受 JSON 请求体。所需权限范围:figures:generate。image 是 file_id(上传文件或此前的输出);operation 选择编辑操作,默认为 instruct。网站结果工具栏也提供相同工具。
| operation | 功能 | 字段 | 积分 |
|---|---|---|---|
| instruct | 按指令编辑整张图像;提供蒙版时,仅重绘蒙版区域 | instruction(1–2,000 个字符),可选 mask、quality | 按质量为 50 / 75 / 100;提供蒙版时为 100 |
| white_background | 将背景替换为纯白色(非透明背景) | quality | 50 / 75 / 100 |
| aspect_ratio | 将整张图调整为新的宽高比,并延展背景 | aspect_ratio (1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9), quality | 50 / 75 / 100 |
| recolor | 为图像应用配色,保留标签颜色 | 可选 palette(1–8 个 #RRGGBB 颜色值;不提供时自动选择配色)、quality | 50 / 75 / 100 |
| replace_text | 原位修改文字标签,保留字体和位置 | text_detection, replacements | 100 |
蒙版是以 mask 用途上传的 PNG,尺寸需与图像相同,白色标记允许修改的区域。区域编辑始终使用 premium 模型,不受 quality 影响。replace_text 不接受 quality:始终使用文字编辑模型,按 premium 等级计费。
替换文字#
- 对同一张图调用
POST /images/text-detections。该操作免费,返回id以及带有index的texts。 - 发送
operation: "replace_text"、text_detection: <id>和replacements: [{"index": 0, "text": "Figure 1"}]。未列出的文字保持原样。 - 识别结果中不存在的索引会返回
400 INVALID_REQUEST和details.reason = TEXT_INDEX_OUT_OF_RANGE,不扣积分。
积分#
cURL#
curl -X POST https://scifig.ai/api/v1/images/edits \
-H "Authorization: Bearer $SCIFIG_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Prefer: wait=25" \
-H "Content-Type: application/json" \
-d '{
"image": "<file_id>",
"operation": "aspect_ratio",
"aspect_ratio": "16:9"
}'JavaScript#
const response = await fetch('https://scifig.ai/api/v1/images/edits', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SCIFIG_API_KEY}`,
'Idempotency-Key': crypto.randomUUID(),
Prefer: 'wait=25',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"image": "<file_id>",
"operation": "aspect_ratio",
"aspect_ratio": "16:9"
}),
});
const result = await response.json();
console.log(response.status, result);Python#
import os
import uuid
import requests
headers = {
"Authorization": f"Bearer {os.environ['SCIFIG_API_KEY']}",
"Idempotency-Key": str(uuid.uuid4()),
"Prefer": "wait=25",
}
response = requests.post(
"https://scifig.ai/api/v1/images/edits",
headers=headers,
json={
"image": "<file_id>",
"operation": "aspect_ratio",
"aspect_ratio": "16:9"
},
timeout=60,
)
print(response.status_code, response.json())