Endpoints
GET
/healthWorker 健康检查和 runtime metadata。
GET
/简版落地宣传页,提供 Viewer 和 API 文档入口。
GET
/viewer可编辑 payload、预览图表并下载 JSON/SVG/PNG 的浏览器页面。
GET
/api当前 API 文档页面。/docs/api 是同一页面别名。
GET
/logo.svg横版 SVG logo。
GET
/favicon.svgSVG favicon。/favicon.ico 返回同一 SVG。
POST
/render核心渲染接口,返回 config、SVG 或 HTML。
POST /render
请求体必须是 JSON object。默认响应是 config。生产鉴权交给上游 API gateway,Worker 内只做输入限制、格式校验、缓存和错误处理。
| 字段 | 类型 | 默认 | 说明 |
|---|---|---|---|
type | string | required | 图表类型,会做大小写归一化和少量别名转换。 |
data | array | required* | 除 liquid 外通常需要非空数组。 |
title | string | none | 图表标题。 |
width | integer | 900 | 图表与下载产物目标宽度,范围 100..4096。 |
height | integer | 520 | 图表与下载产物目标高度,范围 100..4096。 |
theme | string | default | default、dark、academy。 |
options | object | {} | 类型附加配置,如轴标题、堆叠、表格列顺序。 |
response_format | string | config | config、svg、html。 |
Response Formats
config
返回标准化 JSON,包含 hash、renderer、format、chart 和 metadata。
svg
Worker 直接生成简单图表 SVG:line、bar、column、pie、summary。
html
返回浏览器端 HTML shell,引入 @antv/gpt-vis@0.6.1 渲染复杂图表。
png
不支持。请求 response_format=png 或 Accept: image/png 返回 422。
所有 /render 成功响应都带有 ETag、X-Chart-Hash、X-Chart-Type、X-Chart-Renderer、X-Chart-Cache。
Chart Types
| type | 主要字段 | 推荐格式 |
|---|---|---|
line | time, value, optional group | svg / config / html |
bar, column | category, value, optional group | svg / config / html |
pie | category, value | svg / config / html |
summary | label, value, optional delta | svg |
area, radar, waterfall, word-cloud, liquid, table | 见 Markdown API 文档 | config / html |
Examples
SVG
curl -s -X POST /render \
-H "Content-Type: application/json" \
-d '{"type":"line","response_format":"svg","title":"Token price","data":[{"time":"2026-05-01","value":1.12},{"time":"2026-05-02","value":1.18}]}'
HTML Shell
curl -s -X POST /render \
-H "Content-Type: application/json" \
-d '{"type":"waterfall","response_format":"html","title":"Flow bridge","data":[{"category":"Start","value":100},{"category":"Cost","value":-20},{"category":"Total","isTotal":true}]}'
Errors
| Status | error | 说明 |
|---|---|---|
| 400 | bad_request | 请求体为空、超过上限或不是合法 JSON。 |
| 404 | not_found | 路径或方法不支持。 |
| 422 | invalid_chart_payload | 字段缺失、尺寸越界、主题无效等。 |
| 422 | unsupported_response_format | 请求了 Worker 不支持的 PNG。 |
| 422 | unsupported_svg_chart_type | 复杂图表请求了 Worker SVG。 |