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

需要 `editor` 角色。`document` 是一份 Markdown，`website` 从 `url` 开始抓取一个公开网站（遵守 robots.txt）。每个站点最多 20 个来源。

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 |
|---|---|---|---|
| `kind` | enum | yes | Allowed: `document`, `website`. |
| `title` | string | no | 标题；`document` 必填，`website` 默认为主机名 |
| `url` | string | yes | 文档的引用地址，或抓取的起始地址 |
| `document` | string | no | Markdown 正文，仅 `document` |
| `paths` | list of strings | no | 只抓取这些路径开头的页面，默认是起始地址所在的目录，仅 `website` |
| `exclude` | list of strings | no | 不抓取这些路径开头的页面，仅 `website` |
| `maxPages` | integer | no | 页数上限，仅 `website` |
| `refresh` | enum | no | 重新抓取的周期，仅 `website` Allowed: `never`, `daily`, `weekly`, `monthly`. |

## Example request

```bash
curl -X POST https://api.butterix.com/v1/sites/acme-payments/sources \
     -H "Authorization: Bearer <token>" \
     -H "Content-Type: application/json" \
     -d '{
         "kind": "website",
         "url": "https://help.acme.com/",
         "maxPages": 200,
         "refresh": "weekly"
       }'
```

## Responses

### 201

新的内容来源；网站在后台抓取

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `id` | string | no |  |
| `kind` | enum | no | Allowed: `document`, `website`. |
| `title` | string | no |  |
| `url` | string | no |  |
| `config` | object | no | 抓取设置，仅 `website` |
| `config.paths` | list of strings | no |  |
| `config.exclude` | list of strings | no |  |
| `config.maxPages` | integer | no |  |
| `config.refresh` | enum | no | Allowed: `never`, `daily`, `weekly`, `monthly`. |
| `status` | enum | no | Allowed: `ready`, `queued`, `running`, `failed`. |
| `error` | string | no | 上次抓取失败的原因 |
| `pageCount` | integer | no |  |
| `createdAt` | integer | no |  |
| `refreshedAt` | integer | no | 内容最近更新的时间 May be null. |
| `nextAt` | integer | no | 下一次抓取的时间 May be null. |
| `pages` | list of objects | no | 页面，最多 500 个；列表中不返回 |
| `pages[].url` | string | no |  |
| `pages[].title` | string | no |  |
| `pages[].size` | integer | no | 正文的字符数 |
| `document` | string | no | Markdown 正文，仅 `document`；列表中不返回 |

### 400

请求参数无效

Content type: `application/json`

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

### Example response (201)

```json
{
  "id": "src_01jd8x2k7q",
  "kind": "document",
  "title": "help.acme.com",
  "url": "https://help.acme.com/",
  "config": {
    "paths": [
      "string"
    ],
    "exclude": [
      "string"
    ],
    "maxPages": 1,
    "refresh": "never"
  },
  "status": "ready",
  "error": "string",
  "pageCount": 86,
  "createdAt": 1,
  "refreshedAt": 1,
  "nextAt": 1,
  "pages": [
    {
      "url": "string",
      "title": "string",
      "size": 1
    }
  ],
  "document": "string"
}
```
