# RL runs

12 endpoints at `https://api.kosa8.com`, sent with `Authorization: Bearer $KOSA8_API_KEY`. Generated from the API's own [OpenAPI description](https://api.kosa8.com/openapi.json), which a test holds to the router.

## Two to four runs side by side[#]

GET`/v1/rl/compare`scope sandboxes:read

Parameters

`ids`requiredquery · string

2 to 4 run ids, comma-separated

Responses

200400401403404

```
curl -s -X GET https://api.kosa8.com/v1/rl/compare \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## Alert rules on RL runs[#]

GET`/v1/rl/alerts`scope sandboxes:read

Kinds: infra_rate and oom_rate (threshold a share 0-1 of the last window rollouts, default 100), cost (threshold USD at list rate) and idle (threshold minutes without a rollout). The minute tick checks running runs and sends rl.alert to the organization's webhooks that subscribe to it, at most once an hour per rule. At most 50 rules an organization.

Parameters

`run_id`query · string

This run's rules and the organization-wide ones

Responses

200400401403

```
curl -s -X GET https://api.kosa8.com/v1/rl/alerts \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## Add an alert rule[#]

POST`/v1/rl/alerts`scope sandboxes:write

Kinds: infra_rate and oom_rate (threshold a share 0-1 of the last window rollouts, default 100), cost (threshold USD at list rate) and idle (threshold minutes without a rollout). The minute tick checks running runs and sends rl.alert to the organization's webhooks that subscribe to it, at most once an hour per rule. At most 50 rules an organization.

JSON body

`run_id`string | null

—

`kind`required"infra_rate" | "oom_rate" | "cost" | "idle"

—

`threshold`requirednumber

—

`window`integer

—

Responses

201400401403404409

```
curl -s -X POST https://api.kosa8.com/v1/rl/alerts \
  -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' -d @body.json
```

## Change, pause or resume an alert rule[#]

PATCH`/v1/rl/alerts/{id}`scope sandboxes:write

Parameters

`id`requiredpath · string

Alert rule id (rla_…)

JSON body

`threshold`number

—

`window`integer

—

`enabled`boolean

—

Responses

200400401403404

```
curl -s -X PATCH https://api.kosa8.com/v1/rl/alerts/$SBX \
  -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' -d @body.json
```

## Delete an alert rule[#]

DELETE`/v1/rl/alerts/{id}`scope sandboxes:write

Parameters

`id`requiredpath · string

Alert rule id (rla_…)

Responses

200401403404

```
curl -s -X DELETE https://api.kosa8.com/v1/rl/alerts/$SBX \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## Start an RL run[#]

POST`/v1/rl/runs`scope sandboxes:write

Label the run's sandboxes kosa8.run=<id> (run_id on POST /v1/sandboxes/batch and /fork does it) so the run's page counts their sandbox-hours and cost, and drain can find them.

JSON body

`name`requiredstring

Max length 128.

`project`string

Max length 64.

`config`object

Anything, at most 16 KiB as JSON

Responses

201400401403

```
curl -s -X POST https://api.kosa8.com/v1/rl/runs \
  -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' -d @body.json
```

## The organization's runs, newest first, with a short summary[#]

GET`/v1/rl/runs`scope sandboxes:read

Parameters

`project`query · string

Only this project

`status`query · "running" | "finished" | "failed"

Only this status

`name`query · string

Only runs with this exact name (to attach to one)

`limit`query · integer

Default 50

`cursor`query · string

next_cursor of the page before

Responses

200400401403

```
curl -s -X GET https://api.kosa8.com/v1/rl/runs \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## A run with its summary and recommended actions[#]

GET`/v1/rl/runs/{id}`scope sandboxes:read

Cost is at list rates for sandboxes labelled kosa8.run=<id> (cost_basis: list_rate); on a plan the usage is included up to the plan's sandbox-hours. Recommendations appear only when the run's numbers support them.

Parameters

`id`requiredpath · string

Run id (run_…)

Responses

200401403404

```
curl -s -X GET https://api.kosa8.com/v1/rl/runs/$SBX \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## Rename a run or set its status[#]

PATCH`/v1/rl/runs/{id}`scope sandboxes:write

Finishing a run does not delete its sandboxes: drain them with POST /v1/sandboxes/drain {run_id}.

Parameters

`id`requiredpath · string

Run id (run_…)

JSON body

`status`"running" | "finished" | "failed"

—

`name`string

Max length 128.

Responses

200400401403404

```
curl -s -X PATCH https://api.kosa8.com/v1/rl/runs/$SBX \
  -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' -d @body.json
```

## Record rollouts[#]

POST`/v1/rl/runs/{id}/rollouts`scope sandboxes:write

At most 500 a call and 4 MiB a body; all or none are stored. The sealed grader records its own (source grade) when given run_id.

Parameters

`id`requiredpath · string

Run id (run_…)

JSON body

`rollouts`requiredarray of object

—

Responses

200400401403404413

```
curl -s -X POST https://api.kosa8.com/v1/rl/runs/$SBX/rollouts \
  -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' -d @body.json
```

## A run's rollouts, newest first, filtered[#]

GET`/v1/rl/runs/{id}/rollouts`scope sandboxes:read

Parameters

`id`requiredpath · string

Run id (run_…)

`step`query · integer

Only this step

`failure_class`query · "ok" | "exit_nonzero" | "timeout" | "oom" | "infra" | "quota" | "client"

Only this class

`min_reward`query · number

reward >= this

`max_reward`query · number

reward <= this

`sandbox_id`query · string

Only this sandbox's rollouts

`id`query · string

Only this rollout (ro_…)

`limit`query · integer

Default 100

`cursor`query · string

next_cursor of the page before

Responses

200400401403404

```
curl -s -X GET https://api.kosa8.com/v1/rl/runs/$SBX/rollouts \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## Every rollout of a run as JSONL, oldest first[#]

GET`/v1/rl/runs/{id}/export`scope sandboxes:read

Parameters

`id`requiredpath · string

Run id (run_…)

`format`query · "jsonl"

jsonl (the default)

Responses

200400401403404

```
curl -s -X GET https://api.kosa8.com/v1/rl/runs/$SBX/export \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

---
Source: https://docs.kosa8.com/api/rl-runs/
