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

# Create scheduled task

`POST /sites/{site}/automations`

Requires the `editor` role. A site can have up to 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 | Site slug or id |

## Request body

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `name` | string | yes |  |
| `prompt` | string | yes | What to do |
| `schedule` | object | yes |  |
| `schedule.every` | enum | yes | Allowed: `day`, `week`. |
| `schedule.weekday` | integer | no | 1 (Monday) to 7 (Sunday), required when `every` is `week` |
| `schedule.hour` | integer | yes |  |
| `schedule.minute` | integer | no |  |
| `schedule.timezone` | string | no | IANA time zone |
| `canEdit` | boolean | no | Allow changes to the docs; they are committed to a new draft branch |
| `enabled` | boolean | no |  |

## Example request

```bash
curl -X POST https://api.butterix.com/v1/sites/acme-payments/automations \
     -H "Authorization: Bearer <token>" \
     -H "Content-Type: application/json" \
     -d '{
         "name": "Weekly documentation gaps",
         "prompt": "Look at unanswered questions from the last 7 days and list the 5 gaps most worth filling.",
         "schedule": {
           "every": "week",
           "weekday": 1,
           "hour": 9,
           "minute": 0,
           "timezone": "Asia/Shanghai"
         }
       }'
```

## Responses

### 201

New scheduled task

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `id` | string | no |  |
| `name` | string | no |  |
| `prompt` | string | no |  |
| `schedule` | object | no |  |
| `schedule.every` | enum | yes | Allowed: `day`, `week`. |
| `schedule.weekday` | integer | no | 1 (Monday) to 7 (Sunday), required when `every` is `week` |
| `schedule.hour` | integer | yes |  |
| `schedule.minute` | integer | no |  |
| `schedule.timezone` | string | no | IANA time zone |
| `canEdit` | boolean | no | Allow changes to the docs |
| `enabled` | boolean | no |  |
| `createdBy` | object | no |  |
| `createdBy.id` | string | no |  |
| `createdBy.name` | string | no |  |
| `createdAt` | integer | no |  |
| `nextAt` | integer | no | When it runs next May be null. |
| `lastRun` | union | no | The last run (without its report); `null` before the first one |
| _Variant 1_ | variant |  |  |
| `lastRun.id` | string | no |  |
| `lastRun.automationId` | string | no |  |
| `lastRun.cause` | enum | no | Allowed: `schedule`, `manual`. |
| `lastRun.status` | enum | no | Allowed: `running`, `done`, `failed`. |
| `lastRun.report` | string | no | Report (Markdown) |
| `lastRun.branch` | string | no | Draft branch, when there are changes |
| `lastRun.files` | list of strings | no | Changed files |
| `lastRun.error` | string | no | Why it failed |
| `lastRun.usage` | object | no | Token usage |
| `lastRun.usage.input` | integer | no |  |
| `lastRun.usage.output` | integer | no |  |
| `lastRun.startedAt` | integer | no |  |
| `lastRun.finishedAt` | integer | no | May be null. |

### 400

Invalid request parameters

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---|---|
| `error` | string | yes | Human-readable error message |
| `code` | string | no | Machine-readable error code (some endpoints) |

### Example response (201)

```json
{
  "id": "auto_01jd8x2k7q",
  "name": "Weekly documentation gaps",
  "prompt": "string",
  "schedule": {
    "every": "day",
    "weekday": 1,
    "hour": 0,
    "minute": 0,
    "timezone": "Asia/Shanghai"
  },
  "canEdit": true,
  "enabled": true,
  "createdBy": {
    "id": "string",
    "name": "string"
  },
  "createdAt": 1,
  "nextAt": 1,
  "lastRun": {
    "id": "run_01jd8x2k7q",
    "automationId": "string",
    "cause": "schedule",
    "status": "running",
    "report": "string",
    "branch": "automation/2k7q9x1a",
    "files": [
      "string"
    ],
    "error": "string",
    "usage": {
      "input": 1,
      "output": 1
    },
    "startedAt": 1,
    "finishedAt": 1
  }
}
```
