> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ariacompute.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 将训练好的模型导出为 GGUF、MLX、MNN 或 QNN

> 请求将训练好的模型异步导出为 GGUF、MLX、MNN 或 QNN 格式。返回可用于轮询状态的导出任务 ID。

使用此接口将训练好的模型转换为可部署的格式。支持的格式包括 GGUF（量化）、MLX（Apple Silicon）、MNN（阿里巴巴移动端）与 QNN（高通）。导出异步运行；轮询 `GET /v1/exports/:id` 以跟踪完成状态。

## 方法与路径

```http theme={null}
POST /v1/models/:id/export
```

## 认证

在 `Authorization` 头中以 Bearer 令牌的形式携带你的 PIN API 令牌或 JWT。

```http theme={null}
Authorization: Bearer <token>
```

## 路径参数

<ParamField path="id" type="string" required>
  模型标识符（例如 `md_abc123def456`）。
</ParamField>

## 请求体

<ParamField body="format" type="string" required>
  目标导出格式。必须为以下之一：`gguf`、`mlx`、`mnn`、`qnn`。
</ParamField>

### 请求体示例

```json theme={null}
{
  "format": "gguf"
}
```

## 请求示例

<CodeGroup>
  ```bash curl theme={null}
  curl -s -X POST "https://api.ariacompute.com/v1/models/md_abc123def456/export" \
    -H "Authorization: Bearer $PIN_API_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{"format": "gguf"}'
  ```
</CodeGroup>

## 响应

返回标准的 PIN 成功信封，包含导出任务。

<ResponseField name="code" type="integer" required>
  成功为 `0`，出错为非零值。
</ResponseField>

<ResponseField name="data" type="object" required>
  <Expandable title="导出对象">
    <ResponseField name="export_id" type="string">
      唯一的导出任务标识符（例如 `ex_...`）。
    </ResponseField>

    <ResponseField name="model_id" type="string">
      源模型标识符。
    </ResponseField>

    <ResponseField name="format" type="string">
      所请求的格式：`gguf`、`mlx`、`mnn` 或 `qnn`。
    </ResponseField>

    <ResponseField name="status" type="string">
      任务状态：`queued`、`running`、`succeeded` 或 `failed`。
    </ResponseField>

    <ResponseField name="artifact_path" type="string">
      输出路径或文件（成功后填充）。
    </ResponseField>

    <ResponseField name="error" type="string">
      导出失败时的错误消息。
    </ResponseField>

    <ResponseField name="created_at" type="string">
      ISO 8601 创建时间戳。
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="message" type="string">
  可读消息（成功时为空）。
</ResponseField>

### 响应示例

```json theme={null}
{
  "code": 0,
  "data": {
    "export_id": "ex_7a8b9c0d1e2f",
    "model_id": "md_abc123def456",
    "format": "gguf",
    "status": "queued",
    "created_at": "2025-01-15T14:32:08Z"
  },
  "message": ""
}
```

## 导出流程

1. 若模型没有合并后的产物，系统会先将 LoRA 适配器自动合并进基座权重。
2. 转换工具在后台 goroutine 中运行：
   * **GGUF**：先转换为 FP16，再使用 llama.cpp 量化为 `Q4_K_M`。
   * **MLX**：运行 `mlx_lm.convert` 或由 `ARIAPIN_CONVERT_MLX` 配置的工具。
   * **MNN**：运行 `mnnconvert` 或由 `ARIAPIN_CONVERT_MNN` 配置的工具。
   * **QNN**：运行 `qairt-converter` 或由 `ARIAPIN_CONVERT_QNN` 配置的工具。
3. 成功后，产物路径被登记，模型状态恢复为 `ready`。

## 错误

| Code | HTTP | 含义                         |
| ---- | ---- | -------------------------- |
| 401  | 401  | 缺失或无效的 Bearer 令牌。          |
| 404  | 404  | 模型不存在或不属于你。                |
| 422  | 422  | 不支持的格式或缺少转换工具。             |
| 500  | 500  | 导出执行器失败（详情见 `data.error`）。 |
