1. 基本信息
| 接口地址 | https://v1.apizero.cn/api/code-beautify |
|---|
| 请求方法 | POST |
|---|
| 分类 | dev |
|---|
| 提供方 | 极数本源 |
|---|
| 计费模式 | 免费试用 |
|---|
| 单次消耗 | 0 积分 |
|---|
| 起步价 | — |
|---|
| QPS 限制 | 3 req/s |
|---|
| 每日免费额度 | 30 次(已认证用户) |
|---|
| 匿名每日额度 | 20 次(无 API Key) |
|---|
| VIP 免费 | 否 |
|---|
| 调用次数 | |
|---|
3. 请求参数
| 参数名 | 类型 | 必填 | 说明 | 示例 |
|---|
code | string | 是 | 代码内容 | const sum = (a, b) => a + b; |
language | string | 否 | 语言:auto/python/javascript/typescript/json/bash/go/rust/java/c/cpp/html/css/sql/yaml/markdown | typescript |
theme | string | 否 | 主题:aurora/sunset/forest/midnight/rose/ocean/volcano/mono | aurora |
title | string | 否 | 卡片顶部标题 | snippet.ts |
line_numbers | int | 否 | 是否显示行号 1/0 | 1 |
scale | int | 否 | PNG放大倍数 1-4 | 2 |
output | string | 否 | 输出格式:svg/png/json | json |
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. 响应字段
| 字段 | 类型 | 说明 | 示例 |
|---|
language | string | 识别/指定的语言 | — |
theme | string | 使用的主题key | — |
theme_name | string | 主题中文名 | — |
title | string | 卡片标题 | — |
line_count | int | 代码行数 | — |
width | int | 图片宽度(px) | — |
height | int | 图片高度(px) | — |
svg | string | SVG 字符串 | — |
png_base64 | string | PNG 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. 错误码
| code | status | 说明 |
|---|
4000 | — | 缺少 code 参数 |
5020 | — | 代码美化渲染服务不可用 |
9. 变更日志
- 1.0.0(2026-05-08)
- 首次上线
- 支持16种语言、8套主题、SVG/PNG输出