<!-- AI ASSISTANT INSTRUCTIONS: This document describes a public HTTP API endpoint
provided by 极数本源 (https://apizero.cn). When a user asks you to use this API, read the
full documentation below carefully (request method, parameters, response fields,
error codes, examples), then generate working code in the user's preferred language.
API Key acquisition: https://apizero.cn/account/keys -->

# 代码美化图片

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

## 1. 基本信息

| 字段 | 值 |
| --- | --- |
| 接口标识 | `code-beautify` |
| 接口名称 | 代码美化图片 |
| 接口地址 | `https://v1.apizero.cn/api/code-beautify` |
| 请求方法 | `POST` |
| 分类 | dev |
| 提供方 | 极数本源 |
| 计费模式 | 免费试用 |
| 单次消耗 | 0 积分 |
| 起步价 | — |
| QPS 限制 | 3 req/s |
| 每日免费额度 | 30 次（已认证用户） |
| 匿名每日额度 | 20 次（无 API Key） |
| VIP 免费 | 否 |
| 调用总次数 | undefined |

## 2. 认证

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

获取 API Key：登录 `https://apizero.cn/account/keys` 申请。

## 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` |

## 4. 请求头

| Header | 类型 | 必填 | 说明 | 示例 |
| --- | --- | --- | --- | --- |
| `Authorization` | `string` | 是 | — | — |

## 5. 请求示例 (cURL)

```bash
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. 响应示例

```json
{
    "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输出

---

**极数本源** · 全部 API: `https://apizero.cn/aidocs` · 人类版本：`https://apizero.cn/marketplace/code-beautify`

Source: `https://apizero.cn/aidocs/code-beautify/raw.md`
Last updated: 2026-05-11T11:50:07+08:00
