> 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}/deployments`

需要 `editor` 角色。两种用法：

1. **上传源码**（`biti deploy` 使用）：请求体是项目目录的 gzip tar 包（`Content-Type: application/gzip`，最大 200 MB）。
   请求头 `x-biti-preview: 1` 创建预览部署，`x-biti-message` 是 URL 编码的部署说明。
2. **从仓库重新构建**：JSON `{ preview?, branch? }`，从托管仓库或已连接的 Git 仓库构建。通过 CLI 上传过的站点不支持这种方式。

返回 202 与部署 id，用[获取部署](https://docs.butterix.com/api-reference/deployments/get-deployment.md)轮询状态。

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 |

## Header parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `x-biti-preview` | enum | no | 上传源码时：`1` 表示预览部署 Allowed: `0`, `1`. |
| `x-biti-message` | string | no | 上传源码时：URL 编码的部署说明 |

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `preview` | boolean | no | 创建预览部署而不是生产部署 |
| `branch` | string | no | 构建的分支，默认是站点的生产分支 |

## Example request

```bash
tar --exclude=node_modules --exclude=.git --exclude=dist -czf site.tgz .
curl -X POST https://api.butterix.com/v1/sites/acme-payments/deployments \
  -H "Authorization: Bearer $BITI_TOKEN" \
  -H "Content-Type: application/gzip" \
  -H "x-biti-preview: 1" \
  --data-binary @site.tgz
```

## Responses

### 202

已排队

Content type: `application/json`

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

### 400

请求参数无效

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `error` | string | yes | 人类可读的错误信息 |
| `code` | string | no | 机器可读的错误码（部分接口提供） |

### 413

上传超过 200 MB

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `error` | string | yes | 人类可读的错误信息 |
| `code` | string | no | 机器可读的错误码（部分接口提供） |

### Example response (202)

```json
{
  "id": "dpl_01jd8x2k7q"
}
```
