API 参考文档
流程图生成与编辑
以 SVG 绘制科研流程图和工作流程图,再通过后续指令修改。
JSON 请求体#
POST /flowcharts/generations。所需权限范围:figures:generate。
| 字段 | 类型 | 必填 | 默认值 | 规则 |
|---|---|---|---|---|
| prompt | string | 是 | — | 1–8,000 个字符 |
| aspect_ratio | string | 否 | auto | auto, 16:9, 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 21:9 |
| attachment_file_ids | array | 否 | — | 最多 8 个以 flowchart_attachment 用途上传的文件(例如实验方案或草稿) |
消耗 100 积分。成功任务包含一个文字可编辑的 SVG 输出,并携带 editor_url,可在网站的 FlowChart 对话中打开。通过免费的转换导出 PNG、PDF、TIFF 或 PPTX。
附件需先通过 POST /files 以 flowchart_attachment 用途上传;计入网站上传额度,有效期为 24 小时。
编辑#
POST /flowcharts/edits 接受 JSON {"job": "<flowchart job id>", "instruction": "..."},修改该任务生成的流程图,并保留宽高比。instruction 为 1–8,000 个字符,消耗 100 积分。规则与图表编辑相同:父任务仍运行时返回可重试的 409 REVISION_CONFLICT(PARENT_JOB_RUNNING);父任务失败时返回 400 INVALID_REQUEST(JOB_NOT_SUCCEEDED);只有最新版本可编辑(409 REVISION_CONFLICT、NOT_LATEST_REVISION);一次只能运行一个编辑(EDIT_IN_PROGRESS);结果显示在网站同一个 FlowChart 对话中。
cURL#
curl -X POST https://scifig.ai/api/v1/flowcharts/generations \
-H "Authorization: Bearer $SCIFIG_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Prefer: wait=25" \
-H "Content-Type: application/json" \
-d '{
"prompt": "CONSORT flow of a randomized trial: 400 assessed, 80 excluded, 320 randomized into two arms of 160, follow-up and analysis",
"aspect_ratio": "4:3"
}'JavaScript#
const response = await fetch('https://scifig.ai/api/v1/flowcharts/generations', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.SCIFIG_API_KEY}`,
'Idempotency-Key': crypto.randomUUID(),
Prefer: 'wait=25',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"prompt": "CONSORT flow of a randomized trial: 400 assessed, 80 excluded, 320 randomized into two arms of 160, follow-up and analysis",
"aspect_ratio": "4:3"
}),
});
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/flowcharts/generations",
headers=headers,
json={
"prompt": "CONSORT flow of a randomized trial: 400 assessed, 80 excluded, 320 randomized into two arms of 160, follow-up and analysis",
"aspect_ratio": "4:3"
},
timeout=60,
)
print(response.status_code, response.json())