SciFig

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将背景替换为纯白色(非透明背景)quality50 / 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), quality50 / 75 / 100
recolor为图像应用配色,保留标签颜色可选 palette(1–8 个 #RRGGBB 颜色值;不提供时自动选择配色)、quality50 / 75 / 100
replace_text原位修改文字标签,保留字体和位置text_detection, replacements100

蒙版是以 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())