> For the complete documentation index, see [llms.txt](https://docs.unitlab.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.unitlab.ai/api-sdk-cli/zh/apis/releases-api.md).

# 发布 API

Unitlab 发布 API（Releases API）：通过 HTTP 创建 COCO、YOLO、UUEF 等格式的发布，跟踪准备进度，并下载标注划分和源文件。

所有路由都需要 **Manage releases** 权限。

| 方法与路由                                   | 作用               |
| --------------------------------------- | ---------------- |
| `POST /api/sdk/projects/{id}/releases/` | 开始创建发布           |
| `GET /api/sdk/releases/`                | 列出已就绪的发布（普通数组）   |
| `GET /api/sdk/releases/{id}/`           | 读取单个发布，准备过程中也可读取 |
| `GET /api/sdk/releases/{id}/status/`    | 准备进度             |
| `POST /api/sdk/releases/{id}/`          | 获取下载链接           |

## 创建 <a href="#create" id="create"></a>

```bash
curl -s -X POST "https://api.unitlab.ai/api/sdk/projects/$PROJECT_ID/releases/" \
  -H "Authorization: Api-Key $UNITLAB_API_KEY" -H "Content-Type: application/json" \
  -d '{"export_type": "COCO", "split_ratios": {"train": 80, "test": 20}, "completed_only": true}'
```

| 字段                        | 用途                                                                      |
| ------------------------- | ----------------------------------------------------------------------- |
| `export_type`             | `COCO`、`YOLOv8`、`YOLOv5`、`Audio JSON`、`RTTM`、`JSONL`、`GeoJSON` 或 `UUEF` |
| `split_ratios`            | `train`、`validation` 和 `test` 的百分比。默认 `{"train": 100}`。                 |
| `completed_only`          | 只包含处于 Complete 阶段的条目                                                    |
| `upload_sessions`         | 只包含这些 Batch Queue ID                                                    |
| `generic_types`           | 只包含这些类型，例如 `["img", "video"]`                                           |
| `bundle_formats`          | 混合项目中每种类型的导出格式：`{"img": "COCO", "audio": "Audio JSON"}`                 |
| `include_download_tokens` | 为每个条目添加持久下载链接                                                           |
| `license`                 | 数据集许可证 ID，没有有效订阅时必填                                                     |

响应是一个 `status` 为 `pending` 的发布。同一项目已有发布在准备中时，再创建发布会返回 409，错误码为 `release_in_progress`。

## 跟踪准备进度 <a href="#follow-preparation" id="follow-preparation"></a>

```bash
curl -s "https://api.unitlab.ai/api/sdk/releases/$RELEASE_ID/status/" -H "Authorization: Api-Key $UNITLAB_API_KEY"
```

```json
{"status": "completed", "total": 100, "completed": 100, "processing": 0, "failed": 0, "release_status": "ready", "status_error": ""}
```

`release_status` 依次从 `pending` 变为 `exporting`，最终为 `ready` 或 `failed`。`completed` 是以百分比表示的进度。

## 下载 <a href="#download" id="download"></a>

```bash
URL=$(curl -s -X POST "https://api.unitlab.ai/api/sdk/releases/$RELEASE_ID/" \
  -H "Authorization: Api-Key $UNITLAB_API_KEY" -H "Content-Type: application/json" \
  -d '{"download_type": "annotation", "split_type": "train"}' | jq -r .file)
curl -s -o train.json "$URL"
```

| 请求体                                                      | 响应                                                                 |
| -------------------------------------------------------- | ------------------------------------------------------------------ |
| `{"download_type": "annotation", "split_type": "train"}` | 单个划分的 `{"file": "<signed link>"}`。省略 `split_type` 则获取合并后的完整发布。     |
| `{"download_type": "files"}`                             | `{"file_name", "source"}` 媒体链接列表；文本条目则为 `{"file_name", "content"}` |

请求带签名的链接时不要带 `Authorization` 请求头。发布就绪前下载会返回 409，错误码为 `release_not_ready`；划分为空时返回 400。

## 发布字段 <a href="#release-fields" id="release-fields"></a>

`pk`、`name`、`version`、`generic_type`、`number_of_data`、`is_public`、`status`、`progress`、`status_error`、`completed_only`。

## 相关内容 <a href="#related" id="related"></a>

[SDK：创建与下载发布](https://docs.unitlab.ai/api-sdk-cli/zh/sdks/create-and-download-releases.md) · [导出格式](https://docs.unitlab.ai/documentation/zh/releases/export-formats-and-source-inclusion)
