# Tracks through the API

A track is a lane of work on a channel's configurations. Saving into a track changes nothing an agent runs: the track's versions wait there until a rollout ships them, and you can try them on a few hosts first with a soundcheck. This page walks through that flow with the API, one call per step, as a coding agent or a script would make it.

The calls use a personal API token at the Editor role. An Editor token can read the channel, save versions, work in tracks and soundcheck them on a few named hosts; it cannot deploy, start a rollout, change the channel's rules or manage agent keys. Shipping the track, step 10, takes a second token at the Admin role. See [API tokens](https://ampbase.io/docs/api-tokens.md) to mint one and [The Ampbase API](https://ampbase.io/docs/api.md) for how calls and errors work.

Each call is a `POST` with a JSON body, with your token in `AMPBASE_TOKEN`, and the Admin's in `AMPBASE_ADMIN_TOKEN`. The examples use this channel, configuration and host; put your own in their place:

- channel `edge-metrics`, named by its slug
- configuration `cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC`, as the `config_id` that `ListConfigs` answers (step 1)
- host `6f1c2a3b0d4e4f5a8b6c7d8e9f0a1b2c`, an agent in the channel, as the `agent_id` that `ListAgents` answers

A token belongs to one org, so a call does not name it. `channel_id` takes the channel's slug or its id.

Every other id, version and hash a call sends is one an earlier response answered, and the text before each call says which. Ids are written as [IDs in the API](https://ampbase.io/docs/ids.md) describes. Hashes and file contents are shortened here with `...`; send them whole.

## Working rules

A script or a coding agent that works a channel this way keeps to these:

- Open one track per task, with the task as its note (step 2).
- Save only into that track. The first save names the track alone; each later save also names the head you last read (steps 3 and 4).
- Before marking it ready, soundcheck it on one host of each build the channel runs, and check each host picked up the head (step 6).
- Soundcheck on hosts no other track is soundchecking. If `SetSoundcheck` is refused with `SOUNDCHECK_HOST_TAKEN`, pick other hosts; send `take_over` only when the task says to take a host from another track (step 6).
- Mark it ready and stop there: do not ship it (step 7), unless the task said to deploy and the token is an Admin's (step 10).
- When the broadcast moves under the track, rebase it (step 9). A ready track is handed back as the ship that moved it lands, with `handed_back.rebase_onto` the version to save against; an open one learns it from a `TRACK_BASE_MOVED` refusal.
- Poll a ready track or a rollout, as steps 7 and 10 do, only when the task asks you to wait for its outcome.
- Send an `Ampbase-Run` header naming your session on every call, such as `Ampbase-Run: claude-code/session-7f3e2a`, so the audit log labels your changes; [The Ampbase API](https://ampbase.io/docs/api.md) describes it. The examples here leave it out.
- Keep the token in the environment: never print it, log it or write it to a file.
- Close a track you will not ship (step 11). A channel holds at most 50 open or ready tracks, and one nobody touches stays open for 30 days before it is closed for you.

## 1. Read what is broadcasting

`ListConfigs` with the channel answers its configurations, each with its `config_id` and `name`; it is paged, so follow `next_page_token` until it comes back empty.

`GetConfig` answers the configuration with its files. `config.current_version_ulid` is the version broadcasting now. `version` is the version a save that names no track builds on, with each file's content and `content_hash`: the broadcast here. A save that names no track goes into your own track, an unnamed one per person per configuration, and once you have saved that way `version` is its newest version. A caller that always names its track, as this page does, can ignore your own track. A track you open, as in step 2, is read with `GetTrack`.

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/GetConfig \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC"}'
```

```json
{
  "config": {"config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC", "name": "edge", "current_version_ulid": "01JBQ1A2B3C4D5E6F7G8H9J0K1"},
  "version": {
    "version_ulid": "01JBQ1A2B3C4D5E6F7G8H9J0K1",
    "files": [{"name": "vector.yaml", "content": "c291cmNlczoK...", "content_hash": "q0Wl3x..."}]
  }
}
```

`content` and `content_hash` are bytes, so JSON carries them as base64. Keep `content_hash` as it is: a save sends it back to say which file it changes. A configuration with a single file may hold it unnamed, in which case that file has no `name` in the response.

## 2. Open a track

`OpenTrack` opens a named track on the channel. The note is what the track's page and the Tracks list show for it.

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/OpenTrack \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "note": "raise the sink batch size"}'
```

```json
{"track": {"track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1", "note": "raise the sink batch size", "state": "TRACK_STATE_OPEN"}}
```

## 3. Save a version into the track

`CreateConfigVersion` saves a version made of your changes. Each `put` writes one file: its `name`, its new `content`, and in `replaces` the `content_hash` of the file you changed, so a save made from a file that has since changed is refused rather than overwriting it. A new file has no `replaces`. A `delete` removes a file by `name`, with the same `replaces`.

Here the change raises the sink's batch size:

```yaml
sources:
  host:
    type: host_metrics
sinks:
  out:
    type: http
    inputs: [host]
    uri: https://collector.example.com
    batch:
      max_events: 500
```

`content` is the file's bytes as base64, which `base64 < vector.yaml | tr -d '\n'` prints. To change an unnamed file, leave `name` out of the `put`: naming it there puts a second file beside the unnamed one, and its `replaces` names no file of that name, so the save is refused with `FILE_CHANGED`. `track_id` is the one step 2 answered, and `replaces` is the `content_hash` step 1 answered.

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/CreateConfigVersion \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC",
       "track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1",
       "change_summary": "raise the sink batch size",
       "put": [{"name": "vector.yaml", "content": "c291cmNlczoK...", "replaces": "q0Wl3x..."}]}'
```

```json
{"version": {"version_ulid": "01JBQ3A2B3C4D5E6F7G8H9J0K1", "parent_version": "01JBQ1A2B3C4D5E6F7G8H9J0K1", "track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1",
  "files": [{"name": "vector.yaml", "content_hash": "r7Tn2c..."}]}}
```

The new version is the track's head for this configuration, built on the broadcast. Nothing an agent runs has changed.

## 4. Save again on top of your head

The next save builds on the track's head. Name that head in `track_head`, so the save is refused if someone else saved into the track since you read it, and send the `content_hash` of the file as you last saved it. Both are in step 3's answer.

```yaml
sources:
  host:
    type: host_metrics
sinks:
  out:
    type: http
    inputs: [host]
    uri: https://collector.example.com
    batch:
      max_events: 800
```

To see what the save would change first, `PreviewConfigVersion` takes the same `put` and saves nothing. Name the head in `parent`: unset, the preview diffs against your own track's newest version, not a named track's. Before the first save into a track, which has no head yet, name the broadcast, step 1's `current_version_ulid`.

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/PreviewConfigVersion \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC",
       "parent": "01JBQ3A2B3C4D5E6F7G8H9J0K1",
       "put": [{"name": "vector.yaml", "content": "c291cmNlczoK...", "replaces": "r7Tn2c..."}]}'
```

```json
{"current_version": {"version_ulid": "01JBQ3A2B3C4D5E6F7G8H9J0K1"}, "files": [{"name": "vector.yaml", "added": 1, "deleted": 1}], "added": 1, "deleted": 1, "hunks": 1}
```

`added`, `deleted` and `hunks` are the sums over `files`.

Then save it:

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/CreateConfigVersion \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC",
       "track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1",
       "track_head": "01JBQ3A2B3C4D5E6F7G8H9J0K1",
       "change_summary": "800 rather than 500",
       "put": [{"name": "vector.yaml", "content": "c291cmNlczoK...", "replaces": "r7Tn2c..."}]}'
```

```json
{"version": {"version_ulid": "01JBQ4A2B3C4D5E6F7G8H9J0K1", "parent_version": "01JBQ3A2B3C4D5E6F7G8H9J0K1"}}
```

## 5. Read the track

`GetTrack` answers the track with the version it started from (`base`) and its newest version (`head`).

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/GetTrack \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1"}'
```

```json
{"track": {"track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1", "state": "TRACK_STATE_OPEN", "targets": [{"config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC", "base": "01JBQ1A2B3C4D5E6F7G8H9J0K1", "head": "01JBQ4A2B3C4D5E6F7G8H9J0K1"}]}}
```

## 6. Soundcheck the track on a host of each build

`SetSoundcheck` serves the track's heads to the hosts you name, ahead of the channel's rules, until the track ships or closes. It is how you see a change run before a rollout takes it. A save into the track moves its hosts to the new head. An empty `agent_ids` ends the soundcheck. With an Editor token, a head that arms enforcement cannot be soundchecked: that is refused with `permission_denied`.

Pick one host of each build the channel runs, from those whose `status` is not `AGENT_STATUS_OFFLINE`. `ListAgents` answers the channel's hosts, each with the supervisor build it runs in `labels["supervisor.version"]`, the build the track page's soundcheck shows; hosts with no such label count as one build of their own. Any one host of a build will do, as long as no other track is soundchecking it: a host whose `rule_evaluations` holds `ampbase.soundcheck` naming another track is taken. `ListAgents` is paged: follow `next_page_token` until it comes back empty before counting builds.

```bash
curl https://ampbase.io/ampbase.api.v1.AgentService/ListAgents \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics"}'
```

```json
{"agents": [
  {"agent_id": "6f1c2a3b0d4e4f5a8b6c7d8e9f0a1b2c", "status": "AGENT_STATUS_HEALTHY", "labels": {"supervisor.version": "0.18.0"}},
  {"agent_id": "2b7d5e6f7a8b9c0d1e2f3a4b5c6d7e8f", "status": "AGENT_STATUS_HEALTHY", "labels": {"supervisor.version": "0.18.0"}},
  {"agent_id": "9e4a7c1d2b3f4e5a6b7c8d9e0f1a2b3c", "status": "AGENT_STATUS_HEALTHY", "labels": {"supervisor.version": "0.17.2"}}
]}
```

Two builds here, so soundcheck one host of each:

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/SetSoundcheck \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1",
       "agent_ids": ["6f1c2a3b0d4e4f5a8b6c7d8e9f0a1b2c", "9e4a7c1d2b3f4e5a6b7c8d9e0f1a2b3c"]}'
```

```json
{"track": {"track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1", "soundcheck": {"agent_ids": ["6f1c2a3b0d4e4f5a8b6c7d8e9f0a1b2c", "9e4a7c1d2b3f4e5a6b7c8d9e0f1a2b3c"]}}}
```

A host another track's soundcheck holds is refused with `SOUNDCHECK_HOST_TAKEN`, whose `hosts` and `tracks` name each such host and the track holding it, and nothing changes. A host can be taken in the moments before `ListAgents` shows it, so the refusal is the answer to trust. Pick other hosts of those builds. `take_over: true` moves the hosts into your track and out of the other's soundcheck; send it only when the task says to.

Then read each host with `GetAgent` until it has picked up the head:

```bash
curl https://ampbase.io/ampbase.api.v1.AgentService/GetAgent \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "agent_id": "6f1c2a3b0d4e4f5a8b6c7d8e9f0a1b2c"}'
```

```json
{"agent": {"agent_id": "6f1c2a3b0d4e4f5a8b6c7d8e9f0a1b2c", "status": "AGENT_STATUS_HEALTHY",
           "rule_evaluations": [{"rule_key": "ampbase.soundcheck", "variant_key": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1"}],
           "current_config_version": "01JBQ4A2B3C4D5E6F7G8H9J0K1", "drift_status": "DRIFT_STATUS_IN_SYNC"}}
```

A host has picked up the head when one read shows all three: the soundcheck evaluation names your track, `current_config_version` is the head, and there is no `remote_config_error`. One such read is enough; `drift_status` tells you more, but is not required.

- `rule_evaluations` holding `ampbase.soundcheck` with your track's id says the host is served your track.
- `current_config_version` set to the track's head says the host applied it. `drift_status` says whether the config the host reports running is that version:
  - `DRIFT_STATUS_IN_SYNC`: it is.
  - `DRIFT_STATUS_UNKNOWN`: the host has not reported the config it runs, which some agents never do, so do not wait on `DRIFT_STATUS_IN_SYNC` alone.
  - `DRIFT_STATUS_DRIFTED`: it is not. A host can read this for one check-in after applying the head, so keep reading within the wait below, and if it stays drifted, read `remote_config_error`.
  - `DRIFT_STATUS_NOT_LIVE`: a policy in the config did not load.
- A `remote_config_error` says the host refused the config, with the agent's own message.

Read every 15 seconds. A host that is checking in picks the head up at its next check-in, every 30 seconds unless its supervisor is set otherwise, so a host that has not picked it up within 4 check-ins, 2 minutes at the default, is not checking in: soundcheck another host of that build in its place with `SetSoundcheck`, say so in your result, and do not wait on it. A `remote_config_error` means stop: the head is refused, so fix it in the track and save again.

This shows where the head is served and applied, not that the change works: there is no soundcheck verdict. Judge each host's health from its `GetAgent` answer: `status`, `health_reason`, `pipeline_report` and `apply_verification_report`. `health_reason` is empty on a healthy host, and `apply_verification_report` is absent when the supervisor verified nothing, so a missing one is not a fault.

## 7. Mark the track ready

`SetTrackReady` with `ready: true` queues the track for the next rollout, which needs the Admin role to start. It deploys nothing. `ready: false` takes it back out of the queue. Leave the soundcheck on: it ends when the track ships or closes, and until then its hosts run the track's head.

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/SetTrackReady \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1",
       "ready": true}'
```

```json
{"track": {"track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1", "state": "TRACK_STATE_READY"}}
```

To wait for the outcome, read the track with `GetTrack` every 15 seconds until it is no longer `TRACK_STATE_READY`, and set your own limit: nothing ends a wait on a track nobody ships.

- `TRACK_STATE_SHIPPED`: it shipped.
- `TRACK_STATE_OPEN` with `handed_back`: it was handed back, and `handed_back` says why. A ship that moves the broadcast of a configuration the track changes hands it back at once when its base no longer holds; rebase it as step 9 says.
- `TRACK_STATE_OPEN` without `handed_back`: it was taken out of the queue with `SetTrackReady`.
- `TRACK_STATE_CLOSED`: someone closed it, or it sat too long without a change and was closed for you; see [Tracks](https://ampbase.io/docs/tracks.md) for the rule.

A track a rollout handed back reads like this, with `rebase_onto` the version to save against as step 9 does:

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/GetTrack \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1"}'
```

```json
{"track": {"track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1", "state": "TRACK_STATE_OPEN",
           "handed_back": {"reason": "TRACK_HAND_BACK_REASON_STALE", "rollout_id": "rol-01JBQ8A2B3C4D5E6F7G8H9J0K1", "rebase_onto": "01JBQ5A2B3C4D5E6F7G8H9J0K1", "at": "2026-11-25T10:00:00Z", "config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC"}}}
```

## 8. When a file changed under you: FILE_CHANGED

A save whose `replaces` is not the hash of the file in the version it builds on is refused with `FILE_CHANGED`: the file is no longer the one your change was made from. Here the save on step 4's head sends the hash step 1 answered, from before the track's own saves:

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/CreateConfigVersion \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC",
       "track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1",
       "track_head": "01JBQ4A2B3C4D5E6F7G8H9J0K1",
       "put": [{"name": "vector.yaml", "content": "c291cmNlczoK...", "replaces": "q0Wl3x..."}]}'
```

```json
{"code": "failed_precondition", "details": [{"debug": {"reason": "FILE_CHANGED", "domain": "ampbase.io", "metadata": {"config": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC", "name": "vector.yaml", "parent": "01JBQ4A2B3C4D5E6F7G8H9J0K1"}}}]}
```

Read the file at version `parent` with `GetConfigVersion`, apply your change to it, and save again with that file's `content_hash` in `replaces`.

## 9. When the broadcast moves under your track

Your track starts from the version that was broadcasting when you first saved into it, its `base`. If a deploy moves the broadcast on, your track no longer starts from what agents run, and a rollout will not ship it until it does. A ready track is handed back as that deploy lands: `GetTrack` shows it `TRACK_STATE_OPEN`, its `handed_back.rebase_onto` the new broadcast. An open track is not handed back; a rollout naming it refuses with `TRACK_BASE_MOVED`. Read the new broadcast:

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/GetConfig \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC"}'
```

```json
{"config": {"config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC", "current_version_ulid": "01JBQ5A2B3C4D5E6F7G8H9J0K1"}}
```

Read its files with `GetConfigVersion`, naming the `current_version_ulid` just answered:

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/GetConfigVersion \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC",
       "version_ulid": "01JBQ5A2B3C4D5E6F7G8H9J0K1"}'
```

```json
{"version": {"version_ulid": "01JBQ5A2B3C4D5E6F7G8H9J0K1", "files": [{"name": "vector.yaml", "content": "c291cmNlczoK...", "content_hash": "t5Vb1m..."}]}}
```

Here the new broadcast moved the sink to another collector. Apply your change to its file:

```yaml
sources:
  host:
    type: host_metrics
sinks:
  out:
    type: http
    inputs: [host]
    uri: https://collector-2.example.com
    batch:
      max_events: 800
```

Save it with `parent` set to the new broadcast, `replaces` set to its file's `content_hash`, and `track_head` set to step 4's head:

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/CreateConfigVersion \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC",
       "track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1",
       "track_head": "01JBQ4A2B3C4D5E6F7G8H9J0K1",
       "parent": "01JBQ5A2B3C4D5E6F7G8H9J0K1",
       "change_summary": "800, on the new broadcast",
       "put": [{"name": "vector.yaml", "content": "c291cmNlczoK...", "replaces": "t5Vb1m..."}]}'
```

```json
{"version": {"version_ulid": "01JBQ6A2B3C4D5E6F7G8H9J0K1", "parent_version": "01JBQ5A2B3C4D5E6F7G8H9J0K1"}}
```

To preview the rebase first, name the new broadcast as `parent` in `PreviewConfigVersion`. The save moves the track's soundcheck hosts to its new head, so read them again as step 6 does.

The track's `base` is now the new broadcast, and the save cleared `handed_back`. It stays open until you mark it ready again as step 7 does:

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/GetTrack \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1"}'
```

```json
{"track": {"track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1", "state": "TRACK_STATE_OPEN", "targets": [{"config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC", "base": "01JBQ5A2B3C4D5E6F7G8H9J0K1", "head": "01JBQ6A2B3C4D5E6F7G8H9J0K1"}]}}
```

A save that names a `track_head` which is no longer the track's head is refused with `TRACK_HEAD_MOVED`, naming the head to read.

## 10. Ship the track

Previewing takes your own token. Starting a rollout or broadcasting changes what agents run, so those calls take a token at the Admin role, here in `AMPBASE_ADMIN_TOKEN`; an Editor's token is refused.

`PreviewRollout` shows what a rollout of the track would ship with a plan, and saves nothing: each configuration it moves, at the track's head, the stages, and any ready track it would hand back instead.

```bash
curl https://ampbase.io/ampbase.api.v1.RolloutService/PreviewRollout \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "tracks": ["trk-01JBQ2A2B3C4D5E6F7G8H9J0K1"],
       "plan": {"percentage": {"stages": [10, 50, 100]}}}'
```

```json
{"stages": [{"stage": {"percent": 10, "name": "10%"}, "coverage": {"required": [{"kind": "sink", "name": "http"}, {"kind": "source", "name": "host_metrics"}]}}, {"stage": {"percent": 50, "name": "50%"}}, {"stage": {"percent": 100, "name": "100%"}}],
 "targets": [{"target": {"config": {"config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC", "version_ulid": "01JBQ6A2B3C4D5E6F7G8H9J0K1"}}, "name": "config edge"}]}
```

Each stage lists under `coverage.required` the components the version needs, which the agents that stage reaches must run.

To ship it stage by stage, each stage judged before the next, start a rollout with the same `tracks` and plan. `request_id` is any string you choose; sending the same call again with it answers the rollout it started rather than starting a second.

```bash
curl https://ampbase.io/ampbase.api.v1.RolloutService/StartRollout \
  -H "Authorization: Bearer $AMPBASE_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "tracks": ["trk-01JBQ2A2B3C4D5E6F7G8H9J0K1"],
       "plan": {"percentage": {"stages": [10, 50, 100]}},
       "request_id": "ship-batch-800"}'
```

```json
{"rollout": {"rollout_id": "rol-01JBQ7A2B3C4D5E6F7G8H9J0K1", "state": "ROLLOUT_STATE_ROLLING_OUT"}}
```

Then read the rollout every 15 seconds until it is over: a stage is judged over minutes, and four calls a minute sit well inside the smallest plan's 120.

```bash
curl https://ampbase.io/ampbase.api.v1.RolloutService/GetRollout \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "rollout_id": "rol-01JBQ7A2B3C4D5E6F7G8H9J0K1"}'
```

```json
{"rollout": {"rollout_id": "rol-01JBQ7A2B3C4D5E6F7G8H9J0K1", "state": "ROLLOUT_STATE_COMPLETE"}}
```

The rollout is over when its `state` is `ROLLOUT_STATE_COMPLETE`, `ROLLOUT_STATE_ROLLED_BACK` or `ROLLOUT_STATE_FAILED`; in any other, call again. Then `GetTrack` says what became of the track:

- After `ROLLOUT_STATE_COMPLETE`, it is `TRACK_STATE_SHIPPED`.
- After `ROLLOUT_STATE_ROLLED_BACK`, it is `TRACK_STATE_OPEN` again, with `handed_back` giving the reason. Save a fix into it and mark it ready again.
- After `ROLLOUT_STATE_FAILED`, it is still `TRACK_STATE_READY`: the rollout stopped without moving it. Start a new one.

Those are the usual ends. A track its owner or an Admin closed, or its owner took out of the queue, while the rollout ran stays as they left it, so act on the state `GetTrack` answers.

If Ampbase can reach an endpoint of yours, you can take the `io.ampbase.track.*` and `io.ampbase.rollout.*` [webhooks](https://ampbase.io/docs/webhooks.md) instead of polling.

When the last stage is green, the rollout makes the track's head the broadcast and marks the track shipped. See [Rollouts](https://ampbase.io/docs/rollouts.md) for plans, stages and judgement.

To ship it to every agent at once instead, with no stages, `Broadcast` it. Use one or the other: while a rollout runs, `Broadcast` is refused.

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/Broadcast \
  -H "Authorization: Bearer $AMPBASE_ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "tracks": ["trk-01JBQ2A2B3C4D5E6F7G8H9J0K1"]}'
```

```json
{"configs": [{"config_id": "cfg-01JBQ0Z5M6V3T8K2R4N7P9W1XC", "current_version_ulid": "01JBQ6A2B3C4D5E6F7G8H9J0K1"}], "shipped": ["trk-01JBQ2A2B3C4D5E6F7G8H9J0K1"]}
```

The track's head is now the broadcast, and the track is shipped. Shipping ends its soundcheck, and a shipped track takes no more saves: your next change goes into a new track.

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/GetTrack \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1"}'
```

```json
{"track": {"track_id": "trk-01JBQ2A2B3C4D5E6F7G8H9J0K1", "state": "TRACK_STATE_SHIPPED"}}
```

## 11. Close a track you will not ship

`CloseTrack` closes a track without shipping it, and ends its soundcheck. Its versions stay in the configuration's history. You can close your own tracks; closing someone else's needs the Admin role. Here a second track, opened for a change you decide against:

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/OpenTrack \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "note": "try a smaller batch"}'
```

```json
{"track": {"track_id": "trk-01JBQ8A2B3C4D5E6F7G8H9J0K1", "state": "TRACK_STATE_OPEN", "note": "try a smaller batch"}}
```

```bash
curl https://ampbase.io/ampbase.api.v1.ConfigService/CloseTrack \
  -H "Authorization: Bearer $AMPBASE_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"channel_id": "edge-metrics",
       "track_id": "trk-01JBQ8A2B3C4D5E6F7G8H9J0K1"}'
```

```json
{"track": {"track_id": "trk-01JBQ8A2B3C4D5E6F7G8H9J0K1", "state": "TRACK_STATE_CLOSED"}}
```
