# Heartbeat endpoints

> The check-in URLs a job calls to report success, failure, or a start, and what they return.

A heartbeat monitor expects your job to call its URL on a schedule. If the call doesn't arrive in time, or the job reports a failure, you get a push. To create a heartbeat and choose its schedule, see [Heartbeats](/docs/monitors/heartbeats).

## Endpoints [#endpoints]

| Path | Signal | Effect |
|---|---|---|
| `/hb/{check_id}` | Success | Records a check-in. If the heartbeat was late or failing, you get a **Back to normal** push. |
| `/hb/{check_id}/fail` | Failure | You get a push right away. |
| `/hb/{check_id}/start` | Start | Marks the start of a run. The next success records how long the run took. |

- Methods: `GET`, `POST`, and `HEAD` all work.
- No authentication. The check ID (22 letters and digits) is the secret. You find the full URL on the heartbeat's page in the app or web console.
- With `POST`, the first 1,000 characters of the body are saved as a message. For `/fail`, it shows up in the push. Send it as plain text.

```bash
# Success
curl -fsS -m 10 --retry 3 https://opu.sh/hb/CHECK_ID

# Start
curl -fsS -m 10 --retry 3 https://opu.sh/hb/CHECK_ID/start

# Failure with a message
curl -fsS -m 10 --retry 3 --data-binary "pg_dump: connection refused" https://opu.sh/hb/CHECK_ID/fail
```

## Responses [#responses]

| Status | Body | When |
|---|---|---|
| `200` | `ok` (plain text) | The check-in was recorded |
| `404` | `not found` (plain text) | Unknown check ID, a deleted heartbeat, or an unknown signal after the ID |
| `503` | `busy, try again` (plain text) | Rare: many check-ins for the same heartbeat arrived at once. Retry |

The response doesn't say whether the heartbeat is up or late. It only confirms the check-in. Use `-f` with `curl` so a `404` makes your script fail loudly.

## How signals change the state [#how-signals-change-the-state]

| Current state | Signal | New state | Push |
|---|---|---|---|
| New (never checked in) | success | Up | None |
| Up | success | Up | None |
| New or up | fail | Failing | **Reported a failure**, with your message |
| Late or failing | fail | No change | None |
| Late or failing | success | Up | **Back to normal**, with how long it was down |
| Up | none before the deadline | Late | **No check-in** |

- A heartbeat starts watching after its first check-in. It never alerts before that.
- The deadline is the last check-in plus the interval and the grace period. With a cron schedule, it's the next scheduled time after the last check-in, plus the grace period.
- Pushes only go out when the state changes. While a job stays late, you don't get more pushes.
- `start` doesn't change the state. It only starts the timer for the next success.

## Tips [#tips]

- Call the URL at the very end of the job, after the work succeeded. For example: `backup.sh && curl -fsS https://opu.sh/hb/CHECK_ID`.
- Add a timeout and retries (`-m 10 --retry 3`) so a slow network doesn't hang your job.
- Report failures with `/fail` instead of staying silent. You hear about them right away, without waiting for the deadline.
- Keep the URL in a secret store, like a CI secret. Anyone who has it can check in for your job.

More examples for crontab, GitHub Actions, and systemd are in [Heartbeats](/docs/monitors/heartbeats#examples).
