# API reference

Every operation of the Kajiya API, generated from the [OpenAPI 3.1 description](/api/v1/openapi.json). Base URL `https://kajiya.app`. Send `Authorization: Bearer <key>` with every request; the scope each operation needs is listed with it. Read the [API overview](/docs/api) first for keys, rate limits, pagination and errors.

| Method | Path | Scope | Summary |
|---|---|---|---|
| GET | [`/api/v1/account`](#get-api-v1-account) | `read` | Balance, spend, concurrency, caps |
| GET | [`/api/v1/queue`](#get-api-v1-queue) | `read` | Running jobs and jobs waiting to start, with the reason |
| GET | [`/api/v1/jobs`](#get-api-v1-jobs) | `read` | List jobs (newest first) |
| GET | [`/api/v1/jobs/{id}`](#get-api-v1-jobs-id) | `read` | One job |
| POST | [`/api/v1/jobs/{id}/cancel`](#post-api-v1-jobs-id-cancel) | `write` | Cancel a job's workflow run on GitHub |
| GET | [`/api/v1/usage`](#get-api-v1-usage) | `read` | Usage and cost, grouped by day, repository or label |
| GET | [`/api/v1/repos`](#get-api-v1-repos) | `read` | Connected repositories with dispatch mode, caps and 30-day cost |
| POST | [`/api/v1/repos`](#post-api-v1-repos) | `write` | Connect one, many, or all repositories with one GitHub token |
| PATCH | [`/api/v1/repos/{id}`](#patch-api-v1-repos-id) | `write` | Pause/resume or cap a repository's concurrent vCPUs |
| DELETE | [`/api/v1/repos/{id}`](#delete-api-v1-repos-id) | `write` | Disconnect a repository (history is kept) |
| POST | [`/api/v1/repos/{id}/sync`](#post-api-v1-repos-id-sync) | `write` | Check GitHub for queued jobs now |
| GET | [`/api/v1/keys`](#get-api-v1-keys) | `admin` | List active API keys |
| POST | [`/api/v1/keys`](#post-api-v1-keys) | `admin` | Create an API key (returned once) |
| DELETE | [`/api/v1/keys/{id}`](#delete-api-v1-keys-id) | `admin` | Revoke an API key |
| GET | [`/api/v1/settings`](#get-api-v1-settings) | `read` | Spend caps, low-balance threshold, webhook URL |
| PATCH | [`/api/v1/settings`](#patch-api-v1-settings) | `admin` | Update spend caps, low-balance threshold or webhook URL |
| POST | [`/api/v1/webhook/rotate-secret`](#post-api-v1-webhook-rotate-secret) | `admin` | Issue a new webhook signing secret (returned once) |
| POST | [`/api/v1/webhook/test`](#post-api-v1-webhook-test) | `admin` | Queue a `test` event to your webhook |
| GET | [`/api/v1/webhook/deliveries`](#get-api-v1-webhook-deliveries) | `read` | Last 50 webhook deliveries with status and errors |
| GET | [`/api/v1/payments`](#get-api-v1-payments) | `read` | Compute pack purchases |
| GET | [`/api/v1/usage/daily`](#get-api-v1-usage-daily) | `read` | Cost per UTC day, split by repository or label |
| GET | [`/api/v1/concurrency`](#get-api-v1-concurrency) | `read` | vCPUs in use over the last hours |
| GET | [`/api/v1/activity`](#get-api-v1-activity) | `read` | Recent job events and current waits |
| GET | [`/api/v1/repos/{id}/workflows`](#get-api-v1-repos-id-workflows) | `read` | The repository's workflow files, with links to edit them on GitHub |
| GET | [`/api/v1/github/installations`](#get-api-v1-github-installations) | `read` | GitHub App installations linked to your account |
| DELETE | [`/api/v1/github/installations/{id}`](#delete-api-v1-github-installations-id) | `write` | Stop using a GitHub App installation |
| POST | [`/api/v1/github/installations/{id}/sync`](#post-api-v1-github-installations-id-sync) | `write` | Re-read an installation's repositories from GitHub now |
| DELETE | [`/api/v1/sessions`](#delete-api-v1-sessions) | `admin` | Sign out everywhere |
| POST | [`/api/v1/account/token`](#post-api-v1-account-token) | `admin` | Replace the legacy account token (returned once) |
| DELETE | [`/api/v1/account/token`](#delete-api-v1-account-token) | `admin` | Revoke the legacy account token |

## Account

Balance, spend, limits and the live queue.

### GET /api/v1/account

**Balance, spend, concurrency, caps.** Scope: `read`.

One call that tells a script or agent how much it may run: balance, the concurrency limit and what is in use, spend so far and the caps.

#### Response 200

Account.

```json
{
  "id": 42,
  "email": "dev@acme.dev",
  "github_login": "acme-dev",
  "balance_usd": 18.734512,
  "vcpu_hours_left": 4163.22,
  "rate_per_vcpu_hour_usd": 0.0045,
  "spend": {
    "today_usd": 0.4215,
    "month_usd": 6.2655,
    "last_7d_usd": 3.1185,
    "last_30d_usd": 6.2655,
    "avg_daily_7d_usd": 0.4455,
    "est_days_left": 42
  },
  "concurrency": {
    "limit_vcpu": 32,
    "in_use_vcpu": 6,
    "active_jobs": 2,
    "waiting_jobs": 1
  },
  "limits": {
    "max_vcpu": 32,
    "daily_pack_usd": 500,
    "established": true,
    "has_repo": true
  },
  "caps": {
    "daily_usd": 25,
    "monthly_usd": 400,
    "low_balance_usd": 5
  },
  "auth": {
    "via": "key",
    "scope": "read"
  }
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/account" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### GET /api/v1/queue

**Running jobs and jobs waiting to start, with the reason.** Scope: `read`.

Use this to see why a job is not starting (concurrency limit, repository cap, paused repository, prepaid compute, spend cap, or no free runner). Waiting jobs stay queued on GitHub and start by themselves when the reason clears.

#### Response 200

Queue.

```json
{
  "limit_vcpu": 32,
  "in_use_vcpu": 6,
  "fleet": {
    "sellable_vcpu": 96,
    "free_vcpu": 40
  },
  "active": [
    {
      "id": 1290,
      "repo": "acme/api",
      "name": "build",
      "label": "kajiya-4",
      "state": "running",
      "created_at": "2026-12-04T09:20:01.000Z",
      "started_at": "2026-12-04T09:20:07.000Z",
      "github_url": "https://github.com/acme/api/actions/runs/12045570001/job/33861290001"
    },
    {
      "id": 1291,
      "repo": "acme/web",
      "name": "lint",
      "label": "kajiya-2",
      "state": "dispatched",
      "created_at": "2026-12-04T09:20:12.000Z",
      "started_at": null,
      "github_url": "https://github.com/acme/web/actions/runs/12045571234/job/33861299870"
    }
  ],
  "waiting": [
    {
      "repo": "acme/web",
      "name": "e2e (1)",
      "label": "kajiya-8",
      "reason": "repo_limit",
      "message": "This repository's concurrency cap is reached; starts when its running jobs finish.",
      "waiting_since": "2026-12-04T09:20:15.000Z",
      "last_checked": "2026-12-04T09:21:05.000Z",
      "github_url": "https://github.com/acme/web/actions/runs/12045571234/job/33861299871"
    }
  ]
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/queue" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### GET /api/v1/concurrency

**vCPUs in use over the last hours.** Scope: `read`.

Average number of vCPUs running in each time bucket (about 120 buckets, at least one minute each). Running jobs count up to now.

#### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `hours` | query | integer | no | Default `6` |

#### Response 200

Concurrency.

```json
{
  "since": "2026-12-04T03:21:00.000Z",
  "until": "2026-12-04T09:21:40.000Z",
  "step_seconds": 180,
  "limit_vcpu": 32,
  "running_vcpu": 6,
  "points": [
    {
      "t": "2026-12-04T09:15:00.000Z",
      "vcpu": 4.5
    },
    {
      "t": "2026-12-04T09:18:00.000Z",
      "vcpu": 6
    }
  ]
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/concurrency" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

## Jobs

Jobs Kajiya ran or is running, and cancelling them.

### GET /api/v1/jobs

**List jobs (newest first).** Scope: `read`.

Cursor pagination: pass `next_before` from a page as `before` to get the next (older) page; it is null on the last page.

#### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `state` | query | string | no | `active` (reserved, dispatched, running), or a comma list of reserved, dispatched, running, done, failed |
| `repo` | query | string | no | Only this repository, `owner/name` (case-insensitive) |
| `since` | query | string | no | Created at or after: `YYYY-MM-DD` (UTC midnight) or an ISO timestamp |
| `until` | query | string | no | Created before: `YYYY-MM-DD` or an ISO timestamp |
| `limit` | query | integer | no | Page size (JSON). With format=csv: up to 10,000, default 10,000. Default `50` |
| `before` | query | integer | no | Cursor: only jobs with a smaller id; pass `next_before` from the previous page |
| `format` | query | `json`, `csv` | no | `csv` returns a file with one row per job. Default `json` |

#### Response 200

Jobs.

```json
{
  "jobs": [
    {
      "id": 1287,
      "repo": "acme/api",
      "name": "test (3)",
      "label": "kajiya-4",
      "vcpu": 4,
      "state": "done",
      "runtime_seconds": 412,
      "billed_seconds": 420,
      "cost_usd": 0.0021,
      "not_billed": false,
      "created_at": "2026-12-04T09:12:03.000Z",
      "started_at": "2026-12-04T09:12:09.000Z",
      "finished_at": "2026-12-04T09:19:01.000Z",
      "github_run_id": 12045567890,
      "github_job_id": 33861234567,
      "github_url": "https://github.com/acme/api/actions/runs/12045567890/job/33861234567"
    }
  ],
  "next_before": 1286
}
```

With `format=csv` (`text/csv`):

```csv
id,created_at,finished_at,repo,name,label,state,runtime_seconds,billed_seconds,cost_usd,not_billed,github_url
1287,2026-12-04T09:12:03.000Z,2026-12-04T09:19:01.000Z,acme/api,test (3),kajiya-4,done,412,420,0.0021,false,https://github.com/acme/api/actions/runs/12045567890/job/33861234567
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/jobs?state=done%2Cfailed&repo=acme%2Fapi&since=2026-12-01" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### GET /api/v1/jobs/{id}

**One job.** Scope: `read`.

#### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | integer | yes | Job id |

#### Response 200

Job.

```json
{
  "id": 1287,
  "repo": "acme/api",
  "name": "test (3)",
  "label": "kajiya-4",
  "vcpu": 4,
  "state": "done",
  "runtime_seconds": 412,
  "billed_seconds": 420,
  "cost_usd": 0.0021,
  "not_billed": false,
  "created_at": "2026-12-04T09:12:03.000Z",
  "started_at": "2026-12-04T09:12:09.000Z",
  "finished_at": "2026-12-04T09:19:01.000Z",
  "github_run_id": 12045567890,
  "github_job_id": 33861234567,
  "github_url": "https://github.com/acme/api/actions/runs/12045567890/job/33861234567"
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `404` No such object on this account
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/jobs/1287" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### POST /api/v1/jobs/{id}/cancel

**Cancel a job's workflow run on GitHub.** Scope: `write`.

GitHub cancels the whole workflow run (GitHub has no per-job cancel). A job no runner machine has received yet is released and never billed (`billed: false`); otherwise the VM is billed for the minutes it ran. Needs the repository token to have Actions: Read and write (or the GitHub App installation).

#### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | integer | yes | Job id |

#### Response 200

Cancelled.

```json
{
  "ok": true,
  "cancelled_run_id": 12045570001,
  "billed": false,
  "note": "GitHub cancels the whole workflow run. This job had not reached a machine and is not billed."
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `404` No such object on this account
- `409` The object is in a state that does not allow this
- `429` Too many requests this minute
- `502` GitHub could not be reached or refused the call

#### Example

```bash
curl -X POST "https://kajiya.app/api/v1/jobs/1287/cancel" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### GET /api/v1/activity

**Recent job events and current waits.** Scope: `read`.

Newest first: `job.dispatched`, `job.started`, `job.finished` (with runtime and cost) for your latest 500 jobs, and `job.waiting` for jobs that wait right now (with the reason).

#### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `limit` | query | integer | no | Default `30` |

#### Response 200

Activity.

```json
{
  "events": [
    {
      "type": "job.finished",
      "at": "2026-12-04T09:19:01.000Z",
      "job_id": 1042,
      "repo": "acme/api",
      "name": "test (3)",
      "label": "kajiya-4",
      "state": "done",
      "runtime_seconds": 402,
      "cost_usd": 0.0021,
      "not_billed": false,
      "github_url": "https://github.com/acme/api/actions/runs/7001/job/9001"
    },
    {
      "type": "job.waiting",
      "at": "2026-12-04T09:18:40.000Z",
      "job_id": null,
      "repo": "acme/web",
      "name": "e2e",
      "label": "kajiya-8",
      "state": "waiting",
      "reason": "limit",
      "message": "Account concurrency limit reached; starts when your running jobs finish.",
      "github_url": "https://github.com/acme/web/actions/runs/7002/job/9002"
    }
  ]
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/activity" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

## Usage

Usage and cost reports.

### GET /api/v1/usage

**Usage and cost, grouped by day, repository or label.** Scope: `read`.

Counts jobs that finished in [since, until). The range can be at most 400 days. Rows are sorted by day, or by cost (highest first) for repo and label.

#### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `since` | query | string | no | `YYYY-MM-DD` or ISO time. Default: 30 days before `until` |
| `until` | query | string | no | `YYYY-MM-DD` or ISO time (exclusive). Default: end of today (UTC) |
| `group_by` | query | `day`, `repo`, `label` | no | Row key: UTC day, `owner/name`, or `kajiya-N`. Default `day` |
| `format` | query | `json`, `csv` | no | `csv` returns the rows (no total) as a file. Default `json` |

#### Response 200

Usage.

```json
{
  "since": "2026-11-04T00:00:00.000Z",
  "until": "2026-12-05T00:00:00.000Z",
  "group_by": "repo",
  "rows": [
    {
      "key": "acme/api",
      "jobs": 412,
      "failed_jobs": 1,
      "billed_minutes": 3120,
      "vcpu_hours": 208,
      "cost_usd": 0.936
    },
    {
      "key": "acme/web",
      "jobs": 160,
      "failed_jobs": 0,
      "billed_minutes": 900,
      "vcpu_hours": 30,
      "cost_usd": 0.135
    }
  ],
  "total": {
    "jobs": 572,
    "failed_jobs": 1,
    "billed_minutes": 4020,
    "vcpu_hours": 238,
    "cost_usd": 1.071
  }
}
```

With `format=csv` (`text/csv`):

```csv
key,jobs,failed_jobs,billed_minutes,vcpu_hours,cost_usd
acme/api,412,1,3120,208,0.936
acme/web,160,0,900,30,0.135
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/usage?since=2026-11-01" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### GET /api/v1/usage/daily

**Cost per UTC day, split by repository or label.** Scope: `read`.

One row per day of the range (days without jobs included, with zeros), each with the cost per repository or label in `by`. `keys` lists every repository or label of the range, most expensive first. Only finished jobs count.

#### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `days` | query | integer | no | Days up to and including today (UTC). Default `30` |
| `group_by` | query | `repo`, `label` | no | Default `repo` |

#### Response 200

Daily usage.

```json
{
  "since": "2026-12-03T00:00:00.000Z",
  "until": "2026-12-05T00:00:00.000Z",
  "group_by": "repo",
  "keys": [
    {
      "key": "acme/api",
      "cost_usd": 0.4185
    },
    {
      "key": "acme/web",
      "cost_usd": 0.072
    }
  ],
  "days": [
    {
      "day": "2026-12-03",
      "jobs": 31,
      "vcpu_hours": 52,
      "cost_usd": 0.234,
      "by": {
        "acme/api": 0.198,
        "acme/web": 0.036
      }
    },
    {
      "day": "2026-12-04",
      "jobs": 27,
      "vcpu_hours": 57,
      "cost_usd": 0.2565,
      "by": {
        "acme/api": 0.2205,
        "acme/web": 0.036
      }
    }
  ],
  "total_usd": 0.4905
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/usage/daily" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

## Repositories

Connected repositories, caps and pausing.

### GET /api/v1/repos

**Connected repositories with dispatch mode, caps and 30-day cost.** Scope: `read`.

#### Response 200

Repositories.

```json
{
  "repos": [
    {
      "id": 3,
      "full_name": "acme/api",
      "dispatch": "webhook",
      "dispatch_note": null,
      "paused": false,
      "max_vcpu": 16,
      "running_vcpu": 4,
      "waiting_jobs": 0,
      "jobs_30d": 412,
      "cost_30d_usd": 0.936,
      "last_event_at": "2026-12-04T09:20:01.000Z",
      "last_polled_at": "2026-12-04T09:17:44.000Z",
      "last_error": null,
      "connected_at": "2026-11-02T03:15:22.000Z"
    }
  ]
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/repos" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### POST /api/v1/repos

**Connect one, many, or all repositories with one GitHub token.** Scope: `write`.

Send `github_token` and exactly one of `repo`, `repos` (up to 200), `owner` (every repository of an organization the token administers) or `all: true` (everything the token administers). The token needs Administration: Read and write (to register one-time runners); with Webhooks: Read and write Kajiya also installs a workflow_job webhook so jobs start within seconds. Re-sending a connected repository updates its token. Status: 201 when at least one repository was connected or updated, 400 when the single `repo` failed, otherwise 200 with per-repository results.

#### Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `github_token` | string | yes | Fine-grained personal access token (github_pat_...) |
| `repo` | string | no | One repository, owner/name |
| `repos` | array of string | no | A list of owner/name. up to 200 items |
| `owner` | string | no | Every repository of this organization the token administers |
| `all` | boolean | no | Every repository the token administers |

```json
{
  "github_token": "github_pat_11ABCDEFG0123456789_abcdefghijklmnopqrstuvwxyz",
  "owner": "acme"
}
```

#### Response 200

Nothing connected; see results.

```json
{
  "summary": {
    "connected": 0,
    "updated": 0,
    "skipped": 1,
    "error": 1
  },
  "results": [
    {
      "repo": "acme/docs",
      "status": "skipped",
      "message": "Token has no admin permission here."
    },
    {
      "repo": "acme/private",
      "status": "error",
      "message": "GitHub 404: Not Found"
    }
  ]
}
```

#### Response 201

At least one connected or updated.

```json
{
  "summary": {
    "connected": 2,
    "updated": 0,
    "skipped": 2,
    "error": 0
  },
  "results": [
    {
      "repo": "acme/api",
      "status": "connected",
      "id": 3,
      "dispatch": "webhook"
    },
    {
      "repo": "acme/web",
      "status": "connected",
      "id": 4,
      "dispatch": "webhook"
    },
    {
      "repo": "acme/docs",
      "status": "skipped",
      "message": "Token has no admin permission here."
    },
    {
      "repo": "acme/legacy",
      "status": "skipped",
      "message": "Archived."
    }
  ]
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute
- `502` GitHub could not be reached or refused the call

#### Example

```bash
curl -X POST "https://kajiya.app/api/v1/repos" \
  -H "Authorization: Bearer $KAJIYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"github_token":"github_pat_11ABCDEFG0123456789_abcdefghijklmnopqrstuvwxyz","owner":"acme"}'
```

### PATCH /api/v1/repos/{id}

**Pause/resume or cap a repository's concurrent vCPUs.** Scope: `write`.

Send either field or both. `max_vcpu: null` removes the cap. Waiting jobs are re-checked on the next poll.

#### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | integer | yes | Repository id |

#### Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `paused` | boolean | no |  |
| `max_vcpu` | integer or null | no | min 2, max 10000 |

```json
{
  "max_vcpu": 16
}
```

#### Response 200

Updated.

```json
{
  "id": 3,
  "full_name": "acme/api",
  "paused": false,
  "max_vcpu": 16
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `404` No such object on this account
- `429` Too many requests this minute

#### Example

```bash
curl -X PATCH "https://kajiya.app/api/v1/repos/3" \
  -H "Authorization: Bearer $KAJIYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"max_vcpu":16}'
```

### DELETE /api/v1/repos/{id}

**Disconnect a repository (history is kept).** Scope: `write`.

Stops dispatching for the repository and deletes the webhook Kajiya created on it, when the token still allows that. Job history stays.

#### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | integer | yes | Repository id |

#### Response 200

Removed.

```json
{
  "ok": true
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `404` No such object on this account
- `429` Too many requests this minute

#### Example

```bash
curl -X DELETE "https://kajiya.app/api/v1/repos/3" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### POST /api/v1/repos/{id}/sync

**Check GitHub for queued jobs now.** Scope: `write`.

Polls this repository immediately instead of waiting for the next scheduled check, for example after replacing its token.

#### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | integer | yes | Repository id |

#### Response 200

Polled.

```json
{
  "dispatched": 1,
  "last_error": null
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `404` No such object on this account
- `429` Too many requests this minute

#### Example

```bash
curl -X POST "https://kajiya.app/api/v1/repos/3/sync" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### GET /api/v1/repos/{id}/workflows

**The repository's workflow files, with links to edit them on GitHub.** Scope: `read`.

Use the links to change `runs-on` to a Kajiya label. When the repository has no workflow yet, `new_workflow_url` opens GitHub's editor with a starter workflow. If GitHub cannot be reached, `workflows` is empty and `error` says why.

#### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | integer | yes | Repository id |

#### Response 200

Workflows.

```json
{
  "repo": "acme/api",
  "workflows": [
    {
      "name": "CI",
      "path": ".github/workflows/ci.yml",
      "html_url": "https://github.com/acme/api/blob/main/.github/workflows/ci.yml",
      "edit_url": "https://github.com/acme/api/edit/main/.github/workflows/ci.yml"
    }
  ],
  "new_workflow_url": null,
  "actions_url": "https://github.com/acme/api/actions"
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `404` No such object on this account
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/repos/3/workflows" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### GET /api/v1/github/installations

**GitHub App installations linked to your account.** Scope: `read`.

Installations of the Kajiya CI GitHub App that this account uses, with how many repositories each connects. `app.enabled` is false when the server has no GitHub App; connect with a token then.

#### Response 200

Installations.

```json
{
  "app": {
    "enabled": true,
    "slug": "kajiya-ci",
    "url": "https://github.com/apps/kajiya-ci"
  },
  "installations": [
    {
      "id": 58123401,
      "account_login": "acme",
      "account_type": "Organization",
      "repository_selection": "selected",
      "suspended": false,
      "repos": 12,
      "linked_at": "2026-12-04T08:02:11.000Z",
      "manage_url": "https://github.com/organizations/acme/settings/installations/58123401"
    }
  ]
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/github/installations" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### DELETE /api/v1/github/installations/{id}

**Stop using a GitHub App installation.** Scope: `write`.

Disconnects the installation's repositories from this account (job history stays). The app stays installed on GitHub until its owner uninstalls it there.

#### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | integer | yes | Installation id |

#### Response 200

Unlinked.

```json
{
  "ok": true,
  "disconnected": [
    "acme/api",
    "acme/web"
  ]
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `404` No such object on this account
- `429` Too many requests this minute

#### Example

```bash
curl -X DELETE "https://kajiya.app/api/v1/github/installations/3" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### POST /api/v1/github/installations/{id}/sync

**Re-read an installation's repositories from GitHub now.** Scope: `write`.

Kajiya follows installation changes from GitHub's events; use this if a repository you just granted is missing.

#### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | integer | yes | Installation id |

#### Response 200

Synced.

```json
{
  "installation": 58123401,
  "account": "acme",
  "connected": [
    "acme/api",
    "acme/web"
  ],
  "skipped": [
    {
      "repo": "acme/legacy",
      "reason": "Archived."
    }
  ],
  "removed": []
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `404` No such object on this account
- `429` Too many requests this minute

#### Example

```bash
curl -X POST "https://kajiya.app/api/v1/github/installations/3/sync" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

## API keys

Named, scoped keys for scripts and agents.

### GET /api/v1/keys

**List active API keys.** Scope: `admin`.

#### Response 200

Keys.

```json
{
  "keys": [
    {
      "id": 7,
      "name": "agent-07",
      "prefix": "kjk_Zp3LqA9x",
      "scope": "write",
      "created_at": "2026-12-04T08:00:00.000Z",
      "last_used_at": "2026-12-04T09:21:40.000Z",
      "expires_at": null
    }
  ]
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/keys" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### POST /api/v1/keys

**Create an API key (returned once).** Scope: `admin`.

Give every agent or machine its own named key so you can see its last use and revoke it alone. At most 100 active keys per account. The secret `key` is in this response only.

#### Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `name` | string | yes | Who uses the key, e.g. the agent or machine. up to 80 characters |
| `scope` | `read`, `write`, `admin` | yes |  |
| `expires_in_days` | integer | no | Omit for a key that does not expire. min 1, max 3650 |

```json
{
  "name": "agent-07",
  "scope": "write",
  "expires_in_days": 90
}
```

#### Response 201

Key with secret.

```json
{
  "id": 7,
  "name": "agent-07",
  "prefix": "kjk_Zp3LqA9x",
  "scope": "write",
  "created_at": "2026-12-04T08:00:00.000Z",
  "last_used_at": null,
  "expires_at": "2027-03-04T08:00:00.000Z",
  "key": "kjk_Zp3LqA9xR2mT7vW1cN8bY4kH6sJ0dF5gQ3eU9iO2aL7",
  "note": "Store the key now; it is shown only once."
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `409` The object is in a state that does not allow this
- `429` Too many requests this minute

#### Example

```bash
curl -X POST "https://kajiya.app/api/v1/keys" \
  -H "Authorization: Bearer $KAJIYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"agent-07","scope":"write","expires_in_days":90}'
```

### DELETE /api/v1/keys/{id}

**Revoke an API key.** Scope: `admin`.

Takes effect immediately. A key cannot revoke itself (409); use another admin key or the dashboard.

#### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `id` | path | integer | yes | API key id |

#### Response 200

Revoked.

```json
{
  "ok": true
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `404` No such object on this account
- `409` The object is in a state that does not allow this
- `429` Too many requests this minute

#### Example

```bash
curl -X DELETE "https://kajiya.app/api/v1/keys/7" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### DELETE /api/v1/sessions

**Sign out everywhere.** Scope: `admin`.

Ends every browser session of the account, including the one making the call. API keys and the account token keep working; revoke those separately.

#### Response 200

Signed out.

```json
{
  "ok": true,
  "sessions_ended": 3
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl -X DELETE "https://kajiya.app/api/v1/sessions" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### POST /api/v1/account/token

**Replace the legacy account token (returned once).** Scope: `admin`.

Issues a new `kjt_...` account token; the previous one stops working at once. Call it with a browser session or an admin API key: the account token cannot replace itself (409).

#### Response 200

New token.

```json
{
  "token": "kjt_Q7wE2rT9yU4iO1pA6sD3fG8hJ5kL0zX2cV7bN4mQ9wE",
  "note": "Store the token now; it is shown only once. The previous account token no longer works."
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `409` The object is in a state that does not allow this
- `429` Too many requests this minute

#### Example

```bash
curl -X POST "https://kajiya.app/api/v1/account/token" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### DELETE /api/v1/account/token

**Revoke the legacy account token.** Scope: `admin`.

The account token stops working at once. Call it with a browser session or an admin API key: the account token cannot revoke itself (409).

#### Response 200

Revoked.

```json
{
  "ok": true
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `409` The object is in a state that does not allow this
- `429` Too many requests this minute

#### Example

```bash
curl -X DELETE "https://kajiya.app/api/v1/account/token" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

## Settings

Spend caps, low-balance alert and webhook URL.

### GET /api/v1/settings

**Spend caps, low-balance threshold, webhook URL.** Scope: `read`.

#### Response 200

Settings.

```json
{
  "daily_cap_usd": 25,
  "monthly_cap_usd": 400,
  "low_balance_usd": 5,
  "webhook_url": "https://ci.acme.dev/kajiya",
  "webhook_secret_set": true
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/settings" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### PATCH /api/v1/settings

**Update spend caps, low-balance threshold or webhook URL.** Scope: `admin`.

Dollar amounts from 0 to 1,000,000; null removes a cap or the threshold, and a cap of 0 holds every new job. When a cap would be exceeded new jobs wait (reason daily_cap / monthly_cap); running jobs finish. The webhook URL must be public https. Setting a webhook URL when none was set before returns its signing secret once (`webhook_secret`). Unknown fields are rejected.

#### Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `daily_cap_usd` | number or null | no | Per UTC day. min 0, max 1000000 |
| `monthly_cap_usd` | number or null | no | Per UTC calendar month. min 0, max 1000000 |
| `low_balance_usd` | number or null | no | Send balance.low when the balance drops below this. min 0, max 1000000 |
| `webhook_url` | string or null | no | Public https URL; null or empty removes it |

```json
{
  "daily_cap_usd": 25,
  "monthly_cap_usd": 400,
  "low_balance_usd": 5,
  "webhook_url": "https://ci.acme.dev/kajiya"
}
```

#### Response 200

Settings.

```json
{
  "daily_cap_usd": 25,
  "monthly_cap_usd": 400,
  "low_balance_usd": 5,
  "webhook_url": "https://ci.acme.dev/kajiya",
  "webhook_secret_set": true,
  "webhook_secret": "whsec_7Hc2pQx9LmV4tRb8NwZ1sKd6Fy3Ja0Ue5Go2Mi7Xq4",
  "note": "Store the webhook secret now; it is shown only once."
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl -X PATCH "https://kajiya.app/api/v1/settings" \
  -H "Authorization: Bearer $KAJIYA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"daily_cap_usd":25,"monthly_cap_usd":400,"low_balance_usd":5,"webhook_url":"https://ci.acme.dev/kajiya"}'
```

## Webhooks

Webhook secret, test events and delivery log.

### POST /api/v1/webhook/rotate-secret

**Issue a new webhook signing secret (returned once).** Scope: `admin`.

The old secret stops working at once: every delivery from now on, including retries, is signed with the new one.

#### Response 200

Secret.

```json
{
  "webhook_secret": "whsec_7Hc2pQx9LmV4tRb8NwZ1sKd6Fy3Ja0Ue5Go2Mi7Xq4",
  "note": "Store the webhook secret now; it is shown only once."
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl -X POST "https://kajiya.app/api/v1/webhook/rotate-secret" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### POST /api/v1/webhook/test

**Queue a `test` event to your webhook.** Scope: `admin`.

#### Response 202

Queued.

```json
{
  "queued": true,
  "event_id": "evt_Ck5Nw0Ef3Gh8Jq2Lr6Ts9Vx1Yz"
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `409` The object is in a state that does not allow this
- `429` Too many requests this minute

#### Example

```bash
curl -X POST "https://kajiya.app/api/v1/webhook/test" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

### GET /api/v1/webhook/deliveries

**Last 50 webhook deliveries with status and errors.** Scope: `read`.

Deliveries are kept for 7 days.

#### Response 200

Deliveries.

```json
{
  "deliveries": [
    {
      "event_id": "evt_9bXr5MtA2qWc7UeLs0DkHy3vNj",
      "type": "job.finished",
      "status": "delivered",
      "attempts": 1,
      "last_status": 200,
      "last_error": null,
      "created_at": "2026-12-04T09:19:01.000Z",
      "delivered_at": "2026-12-04T09:19:01.000Z",
      "next_attempt_at": null
    },
    {
      "event_id": "evt_Pz6Fs1oKa8GmV3xQe5TcLw0rYd",
      "type": "job.waiting",
      "status": "pending",
      "attempts": 2,
      "last_status": 502,
      "last_error": "HTTP 502",
      "created_at": "2026-12-04T09:20:15.000Z",
      "delivered_at": null,
      "next_attempt_at": "2026-12-04T09:22:46.000Z"
    }
  ]
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/webhook/deliveries" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

## Payments

Compute pack purchases.

### GET /api/v1/payments

**Compute pack purchases.** Scope: `read`.

Completed and refunded purchases, newest first. Receipts and invoices come from Paddle by email.

#### Response 200

Payments.

```json
{
  "payments": [
    {
      "method": "card",
      "reference": "txn_01jeh7q4x0k9m2c8v5b3n6r1t",
      "usd": 100,
      "refunded_usd": 0,
      "status": "completed",
      "paid_at": "2026-11-02T03:20:10.000Z"
    }
  ]
}
```

#### Errors

- `400` Invalid parameter or body
- `401` Missing, unknown, revoked or expired key
- `403` The key's scope is too small
- `429` Too many requests this minute

#### Example

```bash
curl "https://kajiya.app/api/v1/payments" \
  -H "Authorization: Bearer $KAJIYA_API_KEY"
```

## Error responses

Every error is a JSON object with one `error` string, and the HTTP status tells you the kind:

- **BadRequest**: Invalid parameter or body. Example: `{"error":"limit must be an integer from 1 to 500."}`
- **Unauthorized**: Missing, unknown, revoked or expired key. Example: `{"error":"Invalid token."}`
- **Forbidden**: The key's scope is too small. Example: `{"error":"This API key has the \"read\" scope; this action needs \"write\"."}`
- **NotFound**: No such object on this account. Example: `{"error":"Job not found."}`
- **Conflict**: The object is in a state that does not allow this. Example: `{"error":"Job is already done."}`
- **RateLimited**: Too many requests this minute. Example: `{"error":"Rate limit: 1,200 requests per minute per account."}`
- **BadGateway**: GitHub could not be reached or refused the call. Example: `{"error":"Marked as cancelled in Kajiya, but GitHub did not cancel the run: GitHub 403: Resource not accessible by personal access token"}`

## Webhook events

Kajiya also calls you: see [Webhooks](/docs/webhooks) for every event with a full sample payload, the headers and signature verification.
