# Routine webhooks



# Routine webhooks [#routine-webhooks]

A **routine** saves instructions for work that a bot or standalone agent can run again. Use a webhook to start that work from an external system, such as a monitoring service. Routine webhooks are separate from [GitHub triggers](/docs/agents/triggers).

## Set up a routine and token [#set-up-a-routine-and-token]

For a routine with no schedule, set `input.trigger` to `{ "type": "api" }` when creating it with `POST /v1/routines`. You can also add a webhook token to an existing one-time or recurring routine without changing its schedule.

As the routine owner, generate a token in the routine editor and copy the displayed request. To manage the token over HTTP, use your sign-in token and send the routine's current `revision` in a JSON body to `POST /v1/routines/{id}/trigger?org_id=...`. Creating or rotating a token requires current organization membership and active billing. The `201` response includes the updated `routine`, the `fire_url`, and the `bearer` secret, which is shown only once. Store it securely in the sending system.

To remove the token, `DELETE` the same trigger URL with the current `revision` in the body. If either request returns `409` because the revision is stale, reload the routine before retrying. Removing or rotating a token invalidates the old token without deleting run history.

## Send an event [#send-an-event]

Send a `POST` to the issued `fire_url` with the routine token, not your sign-in token. The JSON body is optional; an oversized body returns `413`.

```bash
curl "$ROUTINE_FIRE_URL" \
  -H "Authorization: Bearer $ROUTINE_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: alert-123" \
  -d '{"state":"ALERT","event_id":"alert-123"}'
```

`202 Accepted` returns `run_id` and `run_url`. It confirms that the run was accepted, not that it finished. Open `run_url` while signed in as the routine owner to see the run on its routine's page. The event is saved with the run and given to the agent as untrusted context. The saved routine defines the work; the event cannot grant permissions or approvals.

To ignore recovery notifications, append `?match_state=ALERT` to the fire URL. The request must then include a top-level string `state`. A different state returns `204 No Content` without creating a run; a missing or non-string state returns `400`.

## Retry a delivery [#retry-a-delivery]

Use one `Idempotency-Key` per event per routine, with 1–128 printable, non-space ASCII characters. Resending the same key and JSON payload returns the original run receipt. Reusing the key with different input returns `409`. Without a key, each delivery is treated as a new invocation.

A paused routine rejects new invocations. If a delivery returns `429` because the routine is busy or too many runs were started recently, wait as directed by `Retry-After` and retry with the same key and payload.
