> This page is for version v1 (default).
> For other versions, use one of these documentation indexes:
> - v1 (default): https://docs.butterix.com/llms.txt
> - v0: https://docs.butterix.com/v0/llms.txt

> For the MDX source of any page, append .mdx to the page URL.
> For a complete documentation index, see https://docs.butterix.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.butterix.com/_mcp/server.
> If something on this page is wrong or missing, POST JSON {"page": "<page URL>", "message": "<what is wrong>"} to https://docs.butterix.com/_biti/feedback/agent.

# 预览草稿

`POST /sites/{site}/editor/preview`

为草稿分支创建预览部署，得到 `<site>--<短 id>` 形式的独立地址。

Base URL: https://api.butterix.com/v1

Authentication: bearer token in Authorization header or API key in cookie `biti_session`

## Path parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `site` | string | yes | 站点 slug 或 id |

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `branch` | string | no |  |

## Example request

```bash
curl -X POST https://api.butterix.com/v1/sites/acme-payments/editor/preview \
     -H "Authorization: Bearer <token>" \
     -H "Content-Type: application/json" \
     -d '{}'
```

## Responses

### 202

已排队的预览部署

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `id` | string | no |  |
| `siteId` | string | no |  |
| `kind` | enum | no | Allowed: `production`, `preview`. |
| `status` | enum | no | Allowed: `queued`, `building`, `ready`, `failed`, `canceled`. |
| `source` | string | no | `cli`（上传）、`hosted`（托管仓库）或 `git` |
| `branch` | string | no |  |
| `commitSha` | string | no |  |
| `message` | string | no |  |
| `createdBy` | object | no | 触发者；用 API Key 触发时是创建密钥的人 |
| `createdBy.id` | string | no |  |
| `createdBy.name` | string | no |  |
| `apiKey` | object | no | 用 API Key（CLI / CI）触发时，密钥的名称与首尾 |
| `apiKey.name` | string | no |  |
| `apiKey.prefix` | string | no | 密钥前 10 个字符 |
| `apiKey.suffix` | string | no | 密钥末尾 10 个字符 |
| `error` | string | no | 失败原因 |
| `pageCount` | integer | no |  |
| `sizeBytes` | integer | no |  |
| `durationMs` | integer | no |  |
| `url` | URL | no | 成功后才有。生产部署是站点地址，预览部署是 `<site>--<id 后 8 位>` 子域名 |
| `isCurrent` | boolean | no | 是否为当前生产部署 |
| `createdAt` | integer | no |  |
| `finishedAt` | integer | no |  |

### Example response (202)

```json
{
  "id": "dpl_01jd8x2k7q",
  "siteId": "site_2m4k8p",
  "kind": "production",
  "status": "queued",
  "source": "git",
  "branch": "main",
  "commitSha": "9fceb02d0ae598e95dc970b74767f19372d61af8",
  "message": "docs: 更新快速开始",
  "createdBy": {
    "id": "string",
    "name": "string"
  },
  "apiKey": {
    "name": "GitHub Actions",
    "prefix": "biti_a1B2c",
    "suffix": "Kd82mQx0Zt"
  },
  "error": "string",
  "pageCount": 94,
  "sizeBytes": 5832110,
  "durationMs": 6120,
  "url": "https://acme-payments--8x2k7q-sites.butterix.com",
  "isCurrent": true,
  "createdAt": 1,
  "finishedAt": 1
}
```
