LogoLogoAPI 文档
LogoLogoAPI 文档
首页
概览鉴权与幂等图片生成图片编辑图片转换图表生成任务与有限等待积分错误速率与并发限制API 更新日志
API 文档

图表生成

从数据表生成期刊风格的统计图表

POST /api/v1/charts/generations 使用 multipart/form-data。所需权限:charts:generate。 服务会读取你的数据表,自动选择或按指定的图表类型绘图,最终返回一张完成的 PNG 图片。 不暴露流式输出或中间状态,像其他任务一样轮询即可。

表单字段

字段类型必填默认值规则
datafile是—CSV、TSV、TXT、XLSX 或 XLS;最大 5 MB;首行必须是唯一的列名
promptstring否—希望展示或强调的内容,最多 8,000 字符
chart_typesstring否自动逗号分隔或重复传入,最多 4 个,取值见下方列表
journal_stylestring否defaultdefault、nature、science、cell、plos 或 acs
figure_widthstring否doublesingle(单栏)或 double(双栏)
color_palettestring否okabe_itookabe_ito、wong、tol_bright 或 tol_muted

无法解析、超过大小限制、列名重复或为空的文件返回 400 INVALID_REQUEST(超大文件的 HTTP 状态为 413)。

图表类型

bar, line, scatter, boxplot, violin, histogram, heatmap, regression, errorbar, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , .

图片转换

将图片转换为 SVG、PPTX、PNG、PDF 或 TIFF

任务与有限等待

轮询异步任务并读取经过清理的结果

目录

表单字段
图表类型
积分
输出
cURL
JavaScript
Python
timeseries
volcano
kaplan_meier
forest
dot
radar
upset
dendrogram
qq
ogive
funnel
density
roc
sankey
stem_leaf
correlation
pca
manhattan
bland_altman
waterfall
dose_response
growth_curve
standard_curve
raincloud
beeswarm
ecdf
ma_plot
enrichment
enzyme_kinetics
calendar_heatmap
choropleth
stacked_area
ridgeline
bubble
hexbin
paired_dot
precision_recall
calibration_curve
confusion_matrix

积分

每个图表任务消耗 10 积分,任务受理时预留,仅在成功后结算;失败任务会释放预留。

输出

result.files 只包含一张期刊打印分辨率的 PNG,并附带 width 与 height。 图幅尺寸由期刊风格和栏宽决定,不同请求的像素尺寸会不同。

cURL

curl https://sci-draw.com/api/v1/charts/generations \
  -H 'Authorization: Bearer sd_YOUR_KEY' \
  -H 'Idempotency-Key: study-12-figure-2' \
  -H 'Prefer: wait=30' \
  -F 'data=@results.csv;type=text/csv' \
  -F 'prompt=比较各处理组并标注显著性' \
  -F 'chart_types=boxplot' \
  -F 'journal_style=nature' \
  -F 'figure_width=single'

JavaScript

const form = new FormData();
form.set('data', file);
form.set('prompt', '比较各处理组并标注显著性');
form.set('chart_types', 'boxplot');
const response = await fetch('https://sci-draw.com/api/v1/charts/generations', {
  method: 'POST',
  headers: { Authorization: `Bearer ${apiKey}`, 'Idempotency-Key': crypto.randomUUID() },
  body: form,
});

Python

with open("results.csv", "rb") as table:
    response = requests.post(
        "https://sci-draw.com/api/v1/charts/generations",
        headers={"Authorization": f"Bearer {api_key}", "Idempotency-Key": str(uuid.uuid4())},
        files={"data": ("results.csv", table, "text/csv")},
        data={"prompt": "比较各处理组并标注显著性", "chart_types": "boxplot"},
    )

上传的数据表属于私有任务输入,不会出现在任务或日志响应中;任务到达终态后会被删除。