正在启动平台

代码美化图片code-beautify

将代码片段渲染为精美的SVG/PNG卡片图片。支持16种编程语言语法高亮、8套设计主题,适合社交分享和技术文档配图。

1. 基本信息

接口地址https://v1.apizero.cn/api/code-beautify
请求方法POST
分类dev
提供方极数本源
计费模式免费试用
单次消耗0 积分
起步价
QPS 限制3 req/s
每日免费额度30 次(已认证用户)
匿名每日额度20 次(无 API Key)
VIP 免费
调用次数

2. 认证

需要 API Key。登录用户每日 30 次免费;匿名每日 20 次。

获取 API Key:登录 https://apizero.cn/account/keys

3. 请求参数

参数名类型必填说明示例
codestring代码内容const sum = (a, b) => a + b;
languagestring语言:auto/python/javascript/typescript/json/bash/go/rust/java/c/cpp/html/css/sql/yaml/markdowntypescript
themestring主题:aurora/sunset/forest/midnight/rose/ocean/volcano/monoaurora
titlestring卡片顶部标题snippet.ts
line_numbersint是否显示行号 1/01
scaleintPNG放大倍数 1-42
outputstring输出格式:svg/png/jsonjson

4. 请求头

Header类型必填说明示例
Authorizationstring

5. 请求示例 (cURL)

curl -X POST "https://v1.apizero.cn/api/code-beautify" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "code": "const sum = (a, b) => a + b;",
  "language": "typescript",
  "theme": "aurora",
  "title": "snippet.ts",
  "line_numbers": "1",
  "scale": "2",
  "output": "json"
}'

6. 响应字段

字段类型说明示例
languagestring识别/指定的语言
themestring使用的主题key
theme_namestring主题中文名
titlestring卡片标题
line_countint代码行数
widthint图片宽度(px)
heightint图片高度(px)
svgstringSVG 字符串
png_base64stringPNG base64(output=json时返回)

7. 响应示例

{
    "code": 0,
    "msg": "成功",
    "data": {
        "language": "typescript",
        "theme": "aurora",
        "theme_name": "极光",
        "title": "snippet.ts",
        "line_count": 3,
        "width": 680,
        "height": 180,
        "svg": "<svg>...<\/svg>",
        "png_base64": "iVBORw0..."
    },
    "request_id": "req_abc123"
}

8. 错误码

codestatus说明
4000缺少 code 参数
5020代码美化渲染服务不可用

9. 变更日志

  • 1.0.0(2026-05-08)
    • 首次上线
    • 支持16种语言、8套主题、SVG/PNG输出