# Turn an automation on or off, set or clear its monthly budget, or change how far back it reads

`PATCH` `/api/v1/workspaces/{workspace}/automations/{id}`

`updateAutomation`

Credits pay for the X reads a workspace's automations make: watched accounts and topics, replies to your posts, the posts you reply to and voice learning. One credit is one post read; an account's profile is two. Only what X bills is spent: a post another workspace or this one already read today (UTC) costs nothing. Before each read the worst case is held, the page shrinks to what fits, and the rest goes back once X answers; with too few credits nothing is read and the automation pauses until credits arrive or its next plan month. Never a charge, never an automatic purchase. Included credits are spent before bought ones. Off until Flaghand turns credits on (enabled false): reads then work as before and nothing is spent. When Flaghand puts posting on credits too (spends lists it; prices has each action's credits: an X post, one with a link, a repost, a take-down, reading a post), approving a post sets aside the most it can spend (startApproval's credits, "Up to N credits") and it never spends more, so it goes out as approved even at zero; what it doesn't spend comes back when its job ends. A take-down never waits for credits. Best times' reads spend as they go and pause at zero, keeping the last best times. Settings apply while credits are on. Raising or clearing a budget lifts a budget pause at once. The only ranges are X's own: a topic reads back at most 7 days, voice learning at most 3,200 posts. Who can call it: An API token with the "drafts" scope, or an owner of this workspace, signed in.

**Scopes:** `drafts`

**Parameters**

| Name | In | Required | Type and constraints | Description / example |
| --- | --- | --- | --- | --- |
| `workspace` | path | Yes | `string`; pattern: `"^ws_[a-z0-9]{16}$"` |  Example: `"ws_aaaaaaaaaaaaaaaa"` |
| `id` | path | Yes | `string` | x_replies, x_reply_targets, x_voice_bootstrap, x_best_times, x_media_import, or a watch's id (xwa_...). Example: `"x_replies"` |

**JSON body**

| Field | Required | Type and constraints | Description |
| --- | --- | --- | --- |
| `enabled` | No | `boolean` |  |
| `budget` | No | `integer or null`; minimum: `0` | Credits per plan month; null for no budget. |
| `lookback_days` | No | `integer or null`; minimum: `1` | Watches only; 1 to 7 for a topic. Null for the default (7). |
| `voice_posts` | No | `integer or null`; minimum: `1`; maximum: `3200` | x_voice_bootstrap only. Null for the default (200). |

**Request example**

```http
PATCH https://app.flaghand.com/api/v1/workspaces/ws_aaaaaaaaaaaaaaaa/automations/x_replies
Authorization: Bearer tok_<your workspace token>
Content-Type: application/json

{
  "budget": null,
  "enabled": true
}
```

**Response example**

```json
{
  "id": "x_replies",
  "name": "Replies to your posts",
  "kind": "replies",
  "feature": "x_replies",
  "on_credits": false,
  "enabled": true,
  "budget": null,
  "spent": 0,
  "lookback_days": null,
  "lookback_max_days": null,
  "voice_posts": null,
  "paused": null
}
```

Success: HTTP 200. Content-Type: application/json.

**Errors:** `invalid_request` (400), `internal` (500), `unauthorized` (401), `invalid_token` (401), `session_expired` (401), `bad_origin` (403), `scope_missing` (403), `owner_session_required` (403), `invalid_json` (400), `not_found` (404). See the [error codes](https://app.flaghand.com/docs/errors.md) for meanings and the shared default error response. Other domain errors from that catalog may apply; the response's code and message are authoritative.

**CLI:** `flaghand automations update`

```sh
flaghand automations update --workspace ws_aaaaaaaaaaaaaaaa --id x_replies -d '{"budget":null,"enabled":true}' --json
```

**MCP tool:** `updateAutomation` (also reachable through `callWriteOperation`; use `getOperation` to load its full schema).

```json
{
  "name": "callWriteOperation",
  "arguments": {
    "operation_id": "updateAutomation",
    "arguments": {
      "workspace": "ws_aaaaaaaaaaaaaaaa",
      "id": "x_replies",
      "budget": null,
      "enabled": true
    }
  }
}
```

Base URL: `https://app.flaghand.com/api/v1`. Part of the [API reference](https://app.flaghand.com/docs/api.md); every error code is in [errors](https://app.flaghand.com/docs/errors.md).
