# Routines

> Routines: work your agent does for you without being asked, such as a morning brief. A routine has an owner, a trigger, an action, proactivity and caps. It runs as its owner only, reads and notifies only, and owns one Runtime schedule whose slots each start one job. It is its owner's, and its organization's owners' and admins' to read, pause and delete; to anyone else it does not exist.

## List routines

`GET /v1/routines`

Your routines, newest first, at most 200. With `all=true`, the organization's: its owners and admins only. Each carries its schedule's next run.

Permission: `routines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `all` | query | "true" \| "false" | no | `true`: every member's routines (owners and admins) |

### Responses

- `200` OK (application/json, RoutineList)
  - `routines` (array of Routine, required)
    - `id` (string, required): `rtn_` and 32 hex characters
    - `title` (string, required)
    - `ownerId` (string, required): The person it runs as.
    - `teamId` (string): The team its model calls go to; absent when its owner is in none.
    - `executor` ("gateway", required): `gateway`: each slot is a Runtime job. Desktop routines come with W4 step 2.
    - `trigger` (RoutineTrigger, required)
      - `kind` ("schedule" | "watch", required): `schedule` runs on a time; `watch` checks `watch` every `everySeconds`. `event`, `webhook` and `manual` come later.
      - `everySeconds` (integer): Every N seconds from the routine's creation. Not with `at`. A watch needs it: it checks at most every 10 minutes. [min 600; max 604800]
      - `watch` (RoutineWatch): What a `watch` trigger checks. The agent reads it as you, and tells you once it is met.
        - `source` ("github_pull" | "github_issue" | "spend_today", required): `github_pull`: the pull request `target` is merged or closed. `github_issue`: the issue `target` changes state. `spend_today`: your own AI spend today passes `overUsd`. Today is the UTC day, whatever the routine's `timezone`.
        - `target` (string): A repository and a number, `owner/repo#N`. With `github_pull` and `github_issue` only. [pattern ^[A-Za-z0-9_.-]{1,100}/[A-Za-z0-9_.-]{1,100}#[1-9][0-9]{0,9}$]
        - `overUsd` (string): An amount above zero in US dollars, as a decimal string with at most six decimals (root rule 9). With `spend_today` only.
      - `at` (string): A local time, `HH:MM`, 24-hour. Not with `everySeconds`. [pattern ^([01][0-9]|2[0-3]):[0-5][0-9]$]
      - `days` (array of "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun"): The days `at` runs on, in week order; every day when absent.
      - `timezone` (string): An IANA name; `UTC` when absent.
      - `catchUp` ("latest" | "none"): After downtime: `latest` runs the newest missed slot (the default), `none` runs none.
    - `action` (RoutineAction, required)
      - `kind` ("brief" | "notify", required): `brief`: what changed in your open pull requests, your assigned issues and the channels you follow, read through your own connectors. `notify`, a watch's action: you are told its condition is met. Both read only.
    - `proactivity` (RoutineProactivity, required)
      - `notify` ("always" | "on_change" | "digest"): When a run speaks up; `always` by default.
      - `writes` ("never"): A routine reads and notifies only. `ask_first` waits for Policy PO1.
    - `caps` (RoutineCaps, required)
      - `maxRunsPerDay` (integer): Runs a day, counted in the trigger's time zone. A slot past it is skipped. [min 1; max 144]
    - `reportTo` ("slack", required)
    - `state` ("active" | "paused", required)
    - `pausedReason` ("owner" | "admin")
    - `scheduleId` (string): Its Runtime schedule (`sch_…`).
    - `nextRunAt` (string (date-time)): Its schedule's next slot; absent while paused.
    - `lastRunAt` (string (date-time)): Its schedule's last slot.
    - `delivery` (RoutineDelivery, required)
      - `available` (boolean, required): Whether this Gateway can deliver the routine's action now.
      - `code` (string): Why not: `routine_brief_unavailable` or `routine_watch_unavailable`.
      - `reason` (string)
    - `createdVia` ("api" | "cli" | "ui" | "slack" | "desktop" | "agent", required)
    - `version` (integer, required)
    - `createdAt` (string (date-time), required)
    - `updatedAt` (string (date-time), required)
- `400` `all` is not `true` or `false`. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `401` No credential (`missing_credential`), or a credential Gateway does not accept (`invalid_credential`). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `403` The key does not hold `products.use` (`role_required`), it is not a person's (`routine_agent_refused`), or a member who is not an owner or admin asked for `all`. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `503` Routines are off on this Gateway (`routines_disabled`): they need `NEXUS_ROUTINES` and `NEXUS_SCHEDULER`. The route still mounts. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | `all` is not `true` or `false`. |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | Routines are off on this Gateway (`routines_disabled`): they need `NEXUS_ROUTINES` and `NEXUS_SCHEDULER`. The route still mounts. |

### Example

```sh
curl "$NEXUS_URL/v1/routines" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Froutines)

## Create routine

`POST /v1/routines`

Create a routine for yourself: a `schedule` trigger and the `brief` action. It runs as you and no one else, reads and notifies only (`writes: never`), and reports to your Slack direct messages. Gateway records it and its Runtime schedule (`source: routine:<id>`), whose slots each start one job. The brief is not available yet: `delivery.available` is `false` with `routine_brief_unavailable`, and each slot's job ends without reading or sending anything. A person owns at most 50 routines in an organization. `team` (or `x-nexus-team`) names the team its model calls go to.

Permission: `routines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `title` (string): `Morning brief` when absent; `Watch` for a watch. [min length 1; max length 200]
- `trigger` (RoutineTrigger, required)
  - `kind` ("schedule" | "watch", required): `schedule` runs on a time; `watch` checks `watch` every `everySeconds`. `event`, `webhook` and `manual` come later.
  - `everySeconds` (integer): Every N seconds from the routine's creation. Not with `at`. A watch needs it: it checks at most every 10 minutes. [min 600; max 604800]
  - `watch` (RoutineWatch): What a `watch` trigger checks. The agent reads it as you, and tells you once it is met.
    - `source` ("github_pull" | "github_issue" | "spend_today", required): `github_pull`: the pull request `target` is merged or closed. `github_issue`: the issue `target` changes state. `spend_today`: your own AI spend today passes `overUsd`. Today is the UTC day, whatever the routine's `timezone`.
    - `target` (string): A repository and a number, `owner/repo#N`. With `github_pull` and `github_issue` only. [pattern ^[A-Za-z0-9_.-]{1,100}/[A-Za-z0-9_.-]{1,100}#[1-9][0-9]{0,9}$]
    - `overUsd` (string): An amount above zero in US dollars, as a decimal string with at most six decimals (root rule 9). With `spend_today` only.
  - `at` (string): A local time, `HH:MM`, 24-hour. Not with `everySeconds`. [pattern ^([01][0-9]|2[0-3]):[0-5][0-9]$]
  - `days` (array of "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun"): The days `at` runs on, in week order; every day when absent.
  - `timezone` (string): An IANA name; `UTC` when absent.
  - `catchUp` ("latest" | "none"): After downtime: `latest` runs the newest missed slot (the default), `none` runs none.
- `action` (RoutineAction, required)
  - `kind` ("brief" | "notify", required): `brief`: what changed in your open pull requests, your assigned issues and the channels you follow, read through your own connectors. `notify`, a watch's action: you are told its condition is met. Both read only.
- `proactivity` (RoutineProactivity)
  - `notify` ("always" | "on_change" | "digest"): When a run speaks up; `always` by default.
  - `writes` ("never"): A routine reads and notifies only. `ask_first` waits for Policy PO1.
- `caps` (RoutineCaps)
  - `maxRunsPerDay` (integer): Runs a day, counted in the trigger's time zone. A slot past it is skipped. [min 1; max 144]
- `reportTo` ("slack"): Your Slack direct messages; the default.
- `team` (string): The team its model calls go to, by slug or id; your default team when absent.

### Responses

- `201` Created: the routine and its schedule (application/json, Routine)
  - `id` (string, required): `rtn_` and 32 hex characters
  - `title` (string, required)
  - `ownerId` (string, required): The person it runs as.
  - `teamId` (string): The team its model calls go to; absent when its owner is in none.
  - `executor` ("gateway", required): `gateway`: each slot is a Runtime job. Desktop routines come with W4 step 2.
  - `trigger` (RoutineTrigger, required)
    - `kind` ("schedule" | "watch", required): `schedule` runs on a time; `watch` checks `watch` every `everySeconds`. `event`, `webhook` and `manual` come later.
    - `everySeconds` (integer): Every N seconds from the routine's creation. Not with `at`. A watch needs it: it checks at most every 10 minutes. [min 600; max 604800]
    - `watch` (RoutineWatch): What a `watch` trigger checks. The agent reads it as you, and tells you once it is met.
      - `source` ("github_pull" | "github_issue" | "spend_today", required): `github_pull`: the pull request `target` is merged or closed. `github_issue`: the issue `target` changes state. `spend_today`: your own AI spend today passes `overUsd`. Today is the UTC day, whatever the routine's `timezone`.
      - `target` (string): A repository and a number, `owner/repo#N`. With `github_pull` and `github_issue` only. [pattern ^[A-Za-z0-9_.-]{1,100}/[A-Za-z0-9_.-]{1,100}#[1-9][0-9]{0,9}$]
      - `overUsd` (string): An amount above zero in US dollars, as a decimal string with at most six decimals (root rule 9). With `spend_today` only.
    - `at` (string): A local time, `HH:MM`, 24-hour. Not with `everySeconds`. [pattern ^([01][0-9]|2[0-3]):[0-5][0-9]$]
    - `days` (array of "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun"): The days `at` runs on, in week order; every day when absent.
    - `timezone` (string): An IANA name; `UTC` when absent.
    - `catchUp` ("latest" | "none"): After downtime: `latest` runs the newest missed slot (the default), `none` runs none.
  - `action` (RoutineAction, required)
    - `kind` ("brief" | "notify", required): `brief`: what changed in your open pull requests, your assigned issues and the channels you follow, read through your own connectors. `notify`, a watch's action: you are told its condition is met. Both read only.
  - `proactivity` (RoutineProactivity, required)
    - `notify` ("always" | "on_change" | "digest"): When a run speaks up; `always` by default.
    - `writes` ("never"): A routine reads and notifies only. `ask_first` waits for Policy PO1.
  - `caps` (RoutineCaps, required)
    - `maxRunsPerDay` (integer): Runs a day, counted in the trigger's time zone. A slot past it is skipped. [min 1; max 144]
  - `reportTo` ("slack", required)
  - `state` ("active" | "paused", required)
  - `pausedReason` ("owner" | "admin")
  - `scheduleId` (string): Its Runtime schedule (`sch_…`).
  - `nextRunAt` (string (date-time)): Its schedule's next slot; absent while paused.
  - `lastRunAt` (string (date-time)): Its schedule's last slot.
  - `delivery` (RoutineDelivery, required)
    - `available` (boolean, required): Whether this Gateway can deliver the routine's action now.
    - `code` (string): Why not: `routine_brief_unavailable` or `routine_watch_unavailable`.
    - `reason` (string)
  - `createdVia` ("api" | "cli" | "ui" | "slack" | "desktop" | "agent", required)
  - `version` (integer, required)
  - `createdAt` (string (date-time), required)
  - `updatedAt` (string (date-time), required)
- `400` A body that is not a routine, or a malformed `Idempotency-Key`. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `401` No credential (`missing_credential`), or a credential Gateway does not accept (`invalid_credential`). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `403` The key does not hold `routines.use` (`role_required`), or it is not a person's own key, Nexus UI or an agent link its person granted `routines.use` (`routine_agent_refused`). A module's scoped key, a service account and a sandbox are refused the same way. An agent link's routine writes nothing: any `proactivity.writes` but `never` is `routine_agent_writes_refused`. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `409` You own 50 routines in this organization (`routine_limit`), or the `Idempotency-Key`'s first request still runs. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `422` A routine Gateway does not build yet or cannot run (`invalid_routine`): a trigger other than `schedule`, both or neither of `everySeconds` and `at`, an interval under 600 s, an unknown time zone or day, an action other than `brief`, a `reportTo` other than `slack`. `writes: ask_first` is `routine_writes_unavailable`: it waits for Policy's approval records (PO1). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `503` Routines are off on this Gateway (`routines_disabled`): they need `NEXUS_ROUTINES` and `NEXUS_SCHEDULER`. The route still mounts. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | A body that is not a routine, or a malformed `Idempotency-Key`. |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 409 |  | You own 50 routines in this organization (`routine_limit`), or the `Idempotency-Key`'s first request still runs. |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 |  | A routine Gateway does not build yet or cannot run (`invalid_routine`): a trigger other than `schedule`, both or neither of `everySeconds` and `at`, an interval under 600 s, an unknown time zone or day, an action other than `brief`, a `reportTo` other than `slack`. `writes: ask_first` is `routine_writes_unavailable`: it waits for Policy's approval records (PO1). |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | Routines are off on this Gateway (`routines_disabled`): they need `NEXUS_ROUTINES` and `NEXUS_SCHEDULER`. The route still mounts. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/routines" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "trigger": {
      "kind": "schedule"
    },
    "action": {
      "kind": "brief"
    }
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Froutines)

## Get routine

`GET /v1/routines/{id}`

A routine, with its schedule's next run and its last slot.

Permission: `routines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The routine's id (`rtn_…`), as POST /v1/routines answered it |

### Responses

- `200` OK (application/json, Routine)
  - `id` (string, required): `rtn_` and 32 hex characters
  - `title` (string, required)
  - `ownerId` (string, required): The person it runs as.
  - `teamId` (string): The team its model calls go to; absent when its owner is in none.
  - `executor` ("gateway", required): `gateway`: each slot is a Runtime job. Desktop routines come with W4 step 2.
  - `trigger` (RoutineTrigger, required)
    - `kind` ("schedule" | "watch", required): `schedule` runs on a time; `watch` checks `watch` every `everySeconds`. `event`, `webhook` and `manual` come later.
    - `everySeconds` (integer): Every N seconds from the routine's creation. Not with `at`. A watch needs it: it checks at most every 10 minutes. [min 600; max 604800]
    - `watch` (RoutineWatch): What a `watch` trigger checks. The agent reads it as you, and tells you once it is met.
      - `source` ("github_pull" | "github_issue" | "spend_today", required): `github_pull`: the pull request `target` is merged or closed. `github_issue`: the issue `target` changes state. `spend_today`: your own AI spend today passes `overUsd`. Today is the UTC day, whatever the routine's `timezone`.
      - `target` (string): A repository and a number, `owner/repo#N`. With `github_pull` and `github_issue` only. [pattern ^[A-Za-z0-9_.-]{1,100}/[A-Za-z0-9_.-]{1,100}#[1-9][0-9]{0,9}$]
      - `overUsd` (string): An amount above zero in US dollars, as a decimal string with at most six decimals (root rule 9). With `spend_today` only.
    - `at` (string): A local time, `HH:MM`, 24-hour. Not with `everySeconds`. [pattern ^([01][0-9]|2[0-3]):[0-5][0-9]$]
    - `days` (array of "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun"): The days `at` runs on, in week order; every day when absent.
    - `timezone` (string): An IANA name; `UTC` when absent.
    - `catchUp` ("latest" | "none"): After downtime: `latest` runs the newest missed slot (the default), `none` runs none.
  - `action` (RoutineAction, required)
    - `kind` ("brief" | "notify", required): `brief`: what changed in your open pull requests, your assigned issues and the channels you follow, read through your own connectors. `notify`, a watch's action: you are told its condition is met. Both read only.
  - `proactivity` (RoutineProactivity, required)
    - `notify` ("always" | "on_change" | "digest"): When a run speaks up; `always` by default.
    - `writes` ("never"): A routine reads and notifies only. `ask_first` waits for Policy PO1.
  - `caps` (RoutineCaps, required)
    - `maxRunsPerDay` (integer): Runs a day, counted in the trigger's time zone. A slot past it is skipped. [min 1; max 144]
  - `reportTo` ("slack", required)
  - `state` ("active" | "paused", required)
  - `pausedReason` ("owner" | "admin")
  - `scheduleId` (string): Its Runtime schedule (`sch_…`).
  - `nextRunAt` (string (date-time)): Its schedule's next slot; absent while paused.
  - `lastRunAt` (string (date-time)): Its schedule's last slot.
  - `delivery` (RoutineDelivery, required)
    - `available` (boolean, required): Whether this Gateway can deliver the routine's action now.
    - `code` (string): Why not: `routine_brief_unavailable` or `routine_watch_unavailable`.
    - `reason` (string)
  - `createdVia` ("api" | "cli" | "ui" | "slack" | "desktop" | "agent", required)
  - `version` (integer, required)
  - `createdAt` (string (date-time), required)
  - `updatedAt` (string (date-time), required)
- `401` No credential (`missing_credential`), or a credential Gateway does not accept (`invalid_credential`). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `403` The key does not hold `products.use` (`role_required`), or it is not a person's own key or Nexus UI (`routine_agent_refused`): an agent link creates a routine only after the person's confirm card, which is not built yet. A module's scoped key, a service account and a sandbox are refused the same way. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `404` No such routine you may see (`not_found`). A routine is its owner's, and its organization's owners' and admins' to read, pause and delete. Another member's routine, and another organization's, is as absent as a missing one. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `503` Routines are off on this Gateway (`routines_disabled`): they need `NEXUS_ROUTINES` and `NEXUS_SCHEDULER`. The route still mounts. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such routine you may see (`not_found`). A routine is its owner's, and its organization's owners' and admins' to read, pause and delete. Another member's routine, and another organization's, is as absent as a missing one. |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | Routines are off on this Gateway (`routines_disabled`): they need `NEXUS_ROUTINES` and `NEXUS_SCHEDULER`. The route still mounts. |

### Example

```sh
curl "$NEXUS_URL/v1/routines/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Froutines%2F%7Bid%7D)

## Update routine

`PATCH /v1/routines/{id}`

Pause (`state: paused`) or resume (`state: active`) a routine. A pause stops its schedule first, so no slot after it starts a job. A resume runs from the next slot after now and replays nothing. The owner does both. An owner or admin of the organization may pause someone else's routine, and may not resume it. Pausing twice is the same as once.

Permission: `routines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The routine's id (`rtn_…`), as POST /v1/routines answered it |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `state` ("paused" | "active", required)

### Responses

- `200` OK (application/json, Routine)
  - `id` (string, required): `rtn_` and 32 hex characters
  - `title` (string, required)
  - `ownerId` (string, required): The person it runs as.
  - `teamId` (string): The team its model calls go to; absent when its owner is in none.
  - `executor` ("gateway", required): `gateway`: each slot is a Runtime job. Desktop routines come with W4 step 2.
  - `trigger` (RoutineTrigger, required)
    - `kind` ("schedule" | "watch", required): `schedule` runs on a time; `watch` checks `watch` every `everySeconds`. `event`, `webhook` and `manual` come later.
    - `everySeconds` (integer): Every N seconds from the routine's creation. Not with `at`. A watch needs it: it checks at most every 10 minutes. [min 600; max 604800]
    - `watch` (RoutineWatch): What a `watch` trigger checks. The agent reads it as you, and tells you once it is met.
      - `source` ("github_pull" | "github_issue" | "spend_today", required): `github_pull`: the pull request `target` is merged or closed. `github_issue`: the issue `target` changes state. `spend_today`: your own AI spend today passes `overUsd`. Today is the UTC day, whatever the routine's `timezone`.
      - `target` (string): A repository and a number, `owner/repo#N`. With `github_pull` and `github_issue` only. [pattern ^[A-Za-z0-9_.-]{1,100}/[A-Za-z0-9_.-]{1,100}#[1-9][0-9]{0,9}$]
      - `overUsd` (string): An amount above zero in US dollars, as a decimal string with at most six decimals (root rule 9). With `spend_today` only.
    - `at` (string): A local time, `HH:MM`, 24-hour. Not with `everySeconds`. [pattern ^([01][0-9]|2[0-3]):[0-5][0-9]$]
    - `days` (array of "mon" | "tue" | "wed" | "thu" | "fri" | "sat" | "sun"): The days `at` runs on, in week order; every day when absent.
    - `timezone` (string): An IANA name; `UTC` when absent.
    - `catchUp` ("latest" | "none"): After downtime: `latest` runs the newest missed slot (the default), `none` runs none.
  - `action` (RoutineAction, required)
    - `kind` ("brief" | "notify", required): `brief`: what changed in your open pull requests, your assigned issues and the channels you follow, read through your own connectors. `notify`, a watch's action: you are told its condition is met. Both read only.
  - `proactivity` (RoutineProactivity, required)
    - `notify` ("always" | "on_change" | "digest"): When a run speaks up; `always` by default.
    - `writes` ("never"): A routine reads and notifies only. `ask_first` waits for Policy PO1.
  - `caps` (RoutineCaps, required)
    - `maxRunsPerDay` (integer): Runs a day, counted in the trigger's time zone. A slot past it is skipped. [min 1; max 144]
  - `reportTo` ("slack", required)
  - `state` ("active" | "paused", required)
  - `pausedReason` ("owner" | "admin")
  - `scheduleId` (string): Its Runtime schedule (`sch_…`).
  - `nextRunAt` (string (date-time)): Its schedule's next slot; absent while paused.
  - `lastRunAt` (string (date-time)): Its schedule's last slot.
  - `delivery` (RoutineDelivery, required)
    - `available` (boolean, required): Whether this Gateway can deliver the routine's action now.
    - `code` (string): Why not: `routine_brief_unavailable` or `routine_watch_unavailable`.
    - `reason` (string)
  - `createdVia` ("api" | "cli" | "ui" | "slack" | "desktop" | "agent", required)
  - `version` (integer, required)
  - `createdAt` (string (date-time), required)
  - `updatedAt` (string (date-time), required)
- `400` `state` is not `paused` or `active`. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `401` No credential (`missing_credential`), or a credential Gateway does not accept (`invalid_credential`). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `403` Not a person's key (`routine_agent_refused`), or an admin resuming someone else's routine (`routine_resume_refused`). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `404` No such routine you may see (`not_found`). A routine is its owner's, and its organization's owners' and admins' to read, pause and delete. Another member's routine, and another organization's, is as absent as a missing one. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `503` Routines are off on this Gateway (`routines_disabled`): they need `NEXUS_ROUTINES` and `NEXUS_SCHEDULER`. The route still mounts. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | `state` is not `paused` or `active`. |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such routine you may see (`not_found`). A routine is its owner's, and its organization's owners' and admins' to read, pause and delete. Another member's routine, and another organization's, is as absent as a missing one. |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | Routines are off on this Gateway (`routines_disabled`): they need `NEXUS_ROUTINES` and `NEXUS_SCHEDULER`. The route still mounts. |

### Example

```sh
curl -X PATCH "$NEXUS_URL/v1/routines/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "state": "paused"
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#patch%3A%2Fv1%2Froutines%2F%7Bid%7D)

## Delete routine

`DELETE /v1/routines/{id}`

Delete a routine and its schedule: its owner, or an owner or admin of the organization. The schedule goes first, so no slot after it starts a job. A job already started runs to its end.

Permission: `routines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The routine's id (`rtn_…`), as POST /v1/routines answered it |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Responses

- `200` OK (application/json, RoutineDeleted)
  - `id` (string, required)
  - `deleted` (boolean, required)
- `401` No credential (`missing_credential`), or a credential Gateway does not accept (`invalid_credential`). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `403` The key does not hold `products.use` (`role_required`), or it is not a person's own key or Nexus UI (`routine_agent_refused`): an agent link creates a routine only after the person's confirm card, which is not built yet. A module's scoped key, a service account and a sandbox are refused the same way. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `404` No such routine you may see (`not_found`). A routine is its owner's, and its organization's owners' and admins' to read, pause and delete. Another member's routine, and another organization's, is as absent as a missing one. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `503` Routines are off on this Gateway (`routines_disabled`): they need `NEXUS_ROUTINES` and `NEXUS_SCHEDULER`. The route still mounts. (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such routine you may see (`not_found`). A routine is its owner's, and its organization's owners' and admins' to read, pause and delete. Another member's routine, and another organization's, is as absent as a missing one. |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | Routines are off on this Gateway (`routines_disabled`): they need `NEXUS_ROUTINES` and `NEXUS_SCHEDULER`. The route still mounts. |

### Example

```sh
curl -X DELETE "$NEXUS_URL/v1/routines/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#delete%3A%2Fv1%2Froutines%2F%7Bid%7D)
