# Integrations

19 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.

## GitHub Actions runners: linked installations and the link to install the kosa8 GitHub App[#]

GET`/v1/integrations/github`scope admin

Jobs whose runs-on includes the kosa8 label then run on an ephemeral self-hosted runner in a persistent sandbox of this org; a kosa8-4x8 (2x4, 8x16, 16x32) label picks the size.

Responses

200401403

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

## GitHub Actions runners: the repositories the linked installations can see, and which run on kosa8[#]

GET`/v1/integrations/github/repos`scope admin

Runners are opt-in per repository: a workflow_job from a repository not turned on is ignored.

Responses

200401403

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

## Turn kosa8 runners on or off for a repository[#]

POST`/v1/integrations/github/repos`scope admin

JSON body

`repo`requiredstring

owner/name, of an account with a linked installation

`enabled`requiredboolean

—

Responses

200400401403404

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

## Stop taking this installation's jobs[#]

DELETE`/v1/integrations/github/{installation_id}`scope admin

Parameters

`installation_id`requiredpath · integer

—

Responses

200401403404

```
curl -s -X DELETE https://api.kosa8.com/v1/integrations/github/$INSTALLATION_ID \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## GitHub Actions jobs that ran on kosa8 runners, newest first, with this month's CI minutes[#]

GET`/v1/ci/jobs`scope sandboxes:read

Parameters

`state`query · "queued" | "booting" | "launched" | "busy" | "done" | "failed" | "cancelled"

Only jobs in this state

`repo`query · string

owner/name

`limit`query · integer

How many, 1 to 200 (50)

Responses

200401403

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

## GitHub: is it connected, its installations, and what permissions they lack[#]

GET`/v1/github`scope sandboxes:read

install_url (admins only) installs the kosa8 GitHub App and links it to this organization. missing_permissions lists which of contents:write, pull_requests:write, metadata:read, checks:write and statuses:write an installation lacks: open its manage_url to accept them (checks and statuses only show results on commits; without them kosa8 still works). An installation limited to picked repositories (repository_selection selected) carries add_repos_url and a hint: choose "All repositories" there (recommended) or add the ones you want. Errors (error field): 409 github_not_connected {connect_url}, 404 repo_not_found (not visible to this organization's installations), 409 github_permissions {missing, settings_url}, 409 no_changes, 502 github_unavailable (retry_after_s when GitHub rate-limits).

Responses

200401403

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

## GitHub: the repositories this organization's installations can see, most recently pushed first[#]

GET`/v1/github/repos`scope sandboxes:write

Every repository of every linked installation, all pages (up to 2000 per installation; past that truncated: true), cached 60 s. Errors (error field): 409 github_not_connected {connect_url}, 404 repo_not_found (not visible to this organization's installations), 409 github_permissions {missing, settings_url}, 409 no_changes, 502 github_unavailable (retry_after_s when GitHub rate-limits).

Parameters

`q`query · string

Only names or descriptions containing this

`page`query · integer

Page, from next_page

`per_page`query · integer

Repositories a page (30)

`fresh`query · "1"

1: ask GitHub now, not the 60 s cache

Responses

200401403409502

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

## GitHub: a repository's branches (first 100, the default first)[#]

GET`/v1/github/repos/{owner}/{repo}/branches`scope sandboxes:write

Errors (error field): 409 github_not_connected {connect_url}, 404 repo_not_found (not visible to this organization's installations), 409 github_permissions {missing, settings_url}, 409 no_changes, 502 github_unavailable (retry_after_s when GitHub rate-limits).

Parameters

`owner`requiredpath · string

Owner

`repo`requiredpath · string

Repository name

Responses

200401403404409502

```
curl -s -X GET https://api.kosa8.com/v1/github/repos/$OWNER/$REPO/branches \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## The sandbox's GitHub repo and its changes since the clone[#]

GET`/v1/sandboxes/{id}/repo`scope sandboxes:read

A pending clone is tried again here. changes (while the sandbox runs, with sandboxes:write): files_changed, insertions, deletions, commits_ahead; null otherwise. The block's fields are also under repo. Errors (error field): 409 github_not_connected {connect_url}, 404 repo_not_found (not visible to this organization's installations), 409 github_permissions {missing, settings_url}, 409 no_changes, 502 github_unavailable (retry_after_s when GitHub rate-limits).

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

Responses

200401403404

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

## Commit every change in the sandbox's repo and push it to a branch[#]

POST`/v1/sandboxes/{id}/github/push`scope sandboxes:write

Commits as kosa8 <bot@kosa8.com> (Co-authored-by the member, when known) in a command with no token, then pushes with a contents:write token for that one repository, revoked right after. Audited as github.push. Errors (error field): 409 github_not_connected {connect_url}, 404 repo_not_found (not visible to this organization's installations), 409 github_permissions {missing, settings_url}, 409 no_changes, 502 github_unavailable (retry_after_s when GitHub rate-limits).

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

JSON body

`branch`string

default kosa8/<sandbox short id>

`message`string

default "Changes from kosa8 sandbox <id>"

`path`string

the checkout, default the repo's path

Responses

200400401403404409502

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

## Push the sandbox's changes and open a pull request[#]

POST`/v1/sandboxes/{id}/github/pull-request`scope sandboxes:write

A draft by default (opened ready where the repository has no drafts). An open pull request for the branch already: 200 with existing: true. Audited as github.pr. Errors (error field): 409 github_not_connected {connect_url}, 404 repo_not_found (not visible to this organization's installations), 409 github_permissions {missing, settings_url}, 409 no_changes, 502 github_unavailable (retry_after_s when GitHub rate-limits).

Parameters

`id`requiredpath · string

Sandbox id (sbx_…)

JSON body

`title`string

—

`body`string

Markdown

`base`string

default: the repository's default branch

`branch`string

default kosa8/<sandbox short id>

`draft`boolean

Default `true`.

`message`string

commit message

Responses

201400401403404409502

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

## Work from GitHub: @kosa8 comment triggers and check-run settings[#]

GET`/v1/github/automation`scope sandboxes:read

Needs the `sandboxes:read` scope. Comment `@kosa8 run <command>` on a pull request (runs at its head commit; on an issue: the default branch) or `@kosa8 agent <task>` (the org's coding agent makes the change in a sandbox and opens a draft pull request on a kosa8/ branch). Only people with write, maintain or admin permission on the repository trigger; bots and GitHub Apps never do; edits never do; quoted lines, code and hidden HTML comments are ignored. kosa8 reacts with eyes, keeps one reply comment updated (status, sandbox, duration, cost, egress, then pass or fail) and, on a pull request, posts a check run named kosa8.

Responses

200401403

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

## Change the GitHub automation settings (send only what changes; {"triggers": true} turns triggers on)[#]

PUT`/v1/github/automation`scope admin

Needs the `admin` scope. 400 invalid_automation names the bad field; 404 unknown_secret when agent.secret does not exist (with an example secret for that kit).

JSON body

`triggers`boolean

@kosa8 comment triggers (default false: off until an admin turns them on)

`commands`"any" | "allowlist" | "off"

What @kosa8 run may run: any command, only allowed_commands, or none

`allowed_commands`array of string

With commands allowlist: exact commands, or prefixes ending in * ("npm test*"); plain words only, no shell characters

`agent`object | null

The coding agent for @kosa8 agent, or null (then it answers with a setup link)

`max_runtime_s`integer

Longest one trigger runs (default 1800) Min 60. Max 21600.

`budget_usd`number

Most one trigger's sandbox may cost (default 2); the run stops there, and its timeout is cut to what the budget buys Min 0.01. Max 100.

`size`string

Sandbox size (default 2x4)

`egress`"registries" | "open"

registries (default): package registries and GitHub only. An agent always runs with registries

`check_runs`boolean

Post the kosa8 evidence check run on pull requests from triggers and from POST /v1/sandboxes/{id}/github/pull-request (default true)

Responses

200400401403404

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

## Recent @kosa8 comment triggers, newest first[#]

GET`/v1/github/triggers`scope sandboxes:read

Needs the `sandboxes:read` scope.

Parameters

`limit`query · integer

Default 50

`repo`query · string

owner/name

Responses

200400401403

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

## One pull request of a connected repository: its head and base, to continue it in a sandbox[#]

GET`/v1/github/repos/{owner}/{repo}/pulls/{number}`scope sandboxes:write

Needs the `sandboxes:write` scope and an unrestricted key. Read with a token for that one repository (metadata and pull_requests read), revoked after. head.fork is true when the head branch is on another repository: a sandbox can clone it (repo {name, pr}) but never push to it. 409 github_permissions when the installation lacks Pull requests: read; 404 pr_not_found.

Parameters

`owner`requiredpath · string

Repository owner

`repo`requiredpath · string

Repository name

`number`requiredpath · integer

Pull request number

Responses

200400401403404409502

```
curl -s -X GET https://api.kosa8.com/v1/github/repos/$OWNER/$REPO/pulls/$NUMBER \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## The token ledger: every GitHub token kosa8 minted, for which repo, for what and until when[#]

GET`/v1/github/activity`scope sandboxes:read

Needs `sandboxes:read` or `audit:read`. Read from the audit log; never a token (none is stored). Repository look-ups (purpose list or lookup, metadata:read) are left out unless lookups=1. format=csv downloads up to 5000 rows.

Parameters

`repo`query · string

owner/name

`purpose`query · string

clone, push, pr, check, …

`actor`query · string

member:<email> or key:<id>

`sandbox_id`query · string

A sandbox ID

`since`query · string

Epoch ms or ISO 8601

`until`query · string

Epoch ms or ISO 8601

`lookups`query · "1"

Include repository look-ups

`before_seq`query · integer

Page back

`limit`query · integer

Default 50

`format`query · "json" | "csv"

csv: a download

Responses

200400401403

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

## Pull requests opened from this organization's sandboxes, newest first[#]

GET`/v1/github/pull-requests`scope sandboxes:read

Needs the `sandboxes:read` scope.

Parameters

`repo`query · string

owner/name

`state`query · "open" | "draft" | "closed" | "merged"

Only this state

`limit`query · integer

Default 50

Responses

200400401403

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

## Preview moving a repository's GitHub Actions workflows to kosa8 runners[#]

GET`/v1/github/repos/{owner}/{repo}/runners/migration`scope admin

Needs the `admin` scope. Reads .github/workflows/*.yml at the default branch with a read-only token for that one repository and answers the diff (runs-on: ubuntu-* to a kosa8 label); changes nothing. Jobs chosen by an expression, multi-line runs-on lists, macOS and Windows are left alone and listed under skipped. missing_permissions lists what the App installation still needs to open the pull request (contents:write, pull_requests:write, workflows:write), with settings_url.

Parameters

`owner`requiredpath · string

Repository owner

`repo`requiredpath · string

Repository name

`label`query · "kosa8" | "kosa8-2x4" | "kosa8-4x8" | "kosa8-8x16" | "kosa8-16x32"

The runner label (default kosa8: the default size)

Responses

200400401403404409502

```
curl -s -X GET https://api.kosa8.com/v1/github/repos/$OWNER/$REPO/runners/migration \
  -H "Authorization: Bearer $KOSA8_API_KEY"
```

## Open a pull request that moves the workflows to kosa8 runners (branch kosa8/runners; kosa8 never merges it)[#]

POST`/v1/github/repos/{owner}/{repo}/runners/migration`scope admin

Needs the `admin` scope. Commits each changed workflow file to kosa8/runners (started again from the default branch) through GitHub's contents API with a token for that one repository (contents, pull_requests and workflows write), revoked right after, and opens a draft pull request; an open one from kosa8/runners is updated and answered 200 with existing: true. 409 github_permissions {missing, settings_url} when the installation lacks Workflows: write (or another); 409 no_changes when no job runs on a GitHub-hosted Ubuntu runner. Audited as github.runners_pr.

Parameters

`owner`requiredpath · string

Repository owner

`repo`requiredpath · string

Repository name

JSON body

`label`"kosa8" | "kosa8-2x4" | "kosa8-4x8" | "kosa8-8x16" | "kosa8-16x32"

—

`paths`array of string

Only these workflow files (default: every one with a change)

Responses

200201400401403404409502

```
curl -s -X POST https://api.kosa8.com/v1/github/repos/$OWNER/$REPO/runners/migration \
  -H "Authorization: Bearer $KOSA8_API_KEY" \
  -H 'Content-Type: application/json' -d @body.json
```

---
Source: https://docs.kosa8.com/api/integrations/
