Release 0.13.0: agent API for deployments and benchmarks
Release / release (push) Successful in 3m0s

Scopes deployments:read/write and benchmarks:read/run; /api/v1 endpoints
for runtimes, deployments (create with dry run, edit, start, stop, delete
own ones), benchmark runs, A/B, sweeps and comparisons; ?wait= on all
status endpoints. Guardrails: approval, agent deployments at once, one
GPU job at a time, time limits, sweep variants, runtime and argument
allowlists, host port range, memory/CPU caps, protected deployments with
a VRAM check. Requested-by filters, approval bars, per-token activity log,
scope editing, docs/agent/SKILL-tuning.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-10-21 15:11:06 +02:00
1 parent e007a35143
commit 716bd8f2f0
62 files changed
+6091 -219

No files matched your search

+162 -12
View File
@@ -1,16 +1,17 @@
# Kaname API (`/api/v1`)
A small JSON API for programs and AI agents: look up Hugging Face repos, list the local library,
request downloads and follow them. Everything an agent can do here is bounded by
[guardrails](#guardrails); it can't delete models or files, change settings, or manage runtimes or
tokens.
request downloads, deploy models and benchmark them to tune launch options. Everything an agent can
do here is bounded by [guardrails](#guardrails); it can't delete models or files, change settings,
manage runtimes or tokens, or touch deployments it didn't create.
The rest of Kaname (the web UI and its internal `/api/*` routes) stays behind your OIDC login. Only
`/api/v1` accepts tokens, and it accepts *only* tokens (a browser session doesn't work there).
- [Authentication](#authentication)
- [Errors](#errors)
- [Endpoints](#endpoints)
- [Endpoints](#endpoints): models and downloads, [deployments](#deployments), [benchmarks](#benchmarks)
- [Waiting instead of polling](#waiting-instead-of-polling)
- [Guardrails](#guardrails)
- [Behind a forward-auth proxy (Traefik)](#behind-a-forward-auth-proxy-traefik)
@@ -27,6 +28,13 @@ Authorization: Bearer kn_…
| --- | --- |
| `models:read` | Hub lookup, list models, read jobs (and their log), disk space |
| `downloads:create` | `POST /api/v1/downloads`, within the guardrails |
| `deployments:read` | List runtimes and deployments, read a deployment's state and log |
| `deployments:write` | Create deployments; edit, start, stop and delete **its own** ones, within the guardrails |
| `benchmarks:read` | Read runs, sweeps and comparisons |
| `benchmarks:run` | Start runs, A/B runs and sweeps on **its own** deployments; cancel its own |
Tokens created before 0.13 keep the scopes they had; grant new ones with **Scopes** next to the
token in Settings → API tokens.
A missing, unknown or revoked token gets `401`; a token without the needed scope gets `403`. The
settings page shows when each token was last used; **Revoke** stops it immediately.
@@ -44,12 +52,12 @@ Errors are JSON with a message meant to be read and acted on:
| Status | Codes |
| --- | --- |
| 400 | `invalid_request`, `invalid_json`, `empty_selection` (quant or globs match nothing), `invalid_repo_id` |
| 401 / 403 | `unauthorized`, `forbidden` (scope), `author_not_allowed`, `gated_no_token`, `gated_no_access` |
| 400 | `invalid_request` (also unknown fields), `invalid_json`, `empty_selection` (quant or globs match nothing), `invalid_repo_id`, `invalid` |
| 401 / 403 | `unauthorized`, `forbidden` (scope), `author_not_allowed`, `gated_no_token`, `gated_no_access`, `runtime_not_allowed`, `arg_not_allowed`, `port_not_allowed`, `protected`, `not_owner` |
| 404 | `not_found`, `repo_not_found`, `revision_not_found` |
| 409 | `already_exists` (repo is in the library at another commit), `busy` (the model has an open job) |
| 422 | `too_large` |
| 429 | `too_many_jobs`, `rate_limited` (Hugging Face) |
| 409 | `already_exists` (repo is in the library at another commit), `busy` (a model with an open job; a deployment that must be stopped first), `runtime_not_pulled`, `vram_protected`, `invalid` (e.g. benchmarking a stopped deployment) |
| 422 | `too_large`, `limit_exceeded`, `too_many_variants` |
| 429 | `too_many_jobs`, `too_many_deployments`, `gpu_busy`, `rate_limited` (Hugging Face) |
| 503 / 507 | `disk_unknown` (worker offline), `disk_space` |
Sizes appear as bytes plus a readable `"… GB"` field (decimal GB, like the Hub).
@@ -136,7 +144,7 @@ curl -s -X POST -H "Authorization: Bearer $KANAME_TOKEN" -H "Content-Type: appli
```json
{ "created": true, "modelId": "01M…", "jobId": "01M…", "state": "pending_approval",
"requestedBytes": 5027783488, "requestedSize": "5.0 GB", "files": ["Qwen3-8B-Q4_K_M.gguf"],
"message": "Requested; waiting for the user to approve it in Kaname. Do not retry: check GET /api/v1/jobs/01M… every few minutes." }
"message": "Requested; waiting for the user to approve it in Kaname. Do not retry or poll; tell the user and stop." }
```
- **201**: a new job, `state` `pending_approval` (approval mode `approve`) or `queued` (`auto`).
@@ -149,7 +157,7 @@ curl -s -X POST -H "Authorization: Bearer $KANAME_TOKEN" -H "Content-Type: appli
It uses the same code path as the Add model dialog (the file list is fetched again from the Hub at
that commit; the client's list isn't trusted).
### `GET /api/v1/jobs/{id}[?log=N]`
### `GET /api/v1/jobs/{id}[?wait=S][&log=N]`
`models:read`. Compact job state:
@@ -166,7 +174,8 @@ that commit; the client's list isn't trusted).
States: `pending_approval`, `queued`, `downloading`, `verifying`, `completed`, `failed`, `cancelled`
(also when the user rejected the request), `interrupted`. The `hf` log is only included with
`?log=N` (the last N lines, at most 200).
`?log=N` (the last N lines, at most 200). `?wait=S` returns once the job is finished (or right away
while it waits for approval); see [Waiting instead of polling](#waiting-instead-of-polling).
### `GET /api/v1/disk`
@@ -181,8 +190,117 @@ States: `pending_approval`, `queued`, `downloading`, `verifying`, `completed`, `
`reservedBytes` is what open downloads still have to fetch; `availableForRequests` is what a request
may use before hitting the minimum-free guardrail.
### Deployments
A deployment is a model served by a runtime container. Agents use the same validation, estimates and
`docker run` command as the UI; they can only edit, start, stop, delete and benchmark deployments their
own token created, and never [protected](#protected-deployments) ones.
#### `GET /api/v1/runtimes`
`deployments:read`. Runtimes with a pulled image: engine (`llama.cpp` or `vllm`), accelerator
(`cpu`, `nvidia`, `dri` for Intel/AMD), what they serve, whether agents may use them (`allowed`) and
the extra argument flags agents may pass (`allowedExtraArgs`); plus the host's GPUs.
#### `GET /api/v1/deployments[?mine=1]`, `GET /api/v1/deployments/{id}[?wait=S][&log=N]`
`deployments:read`. State (`stopped`, `pending_approval`, `starting`, `running`, `stopping`,
`failed`), `mine`, `protected`, runtime, model, options, limits, the endpoint inside the Docker
network, what the server reported once ready (version, slots, context), live CPU/RAM, error and a
`next` hint. `?wait=S` returns once it is running, stopped or failed (or right away while the start
waits for approval). `?log=N` adds the last N log lines (max 200).
#### `POST /api/v1/deployments`
`deployments:write`.
| Field | |
| --- | --- |
| `runtimeId`, `modelId` | From `GET /api/v1/runtimes` and `GET /api/v1/models` |
| `options` | The deployment form's launch options: `modelFile` (llama.cpp: the `.gguf`; vLLM: `""`), `contextSize`, `parallel`, `cacheTypeK`/`cacheTypeV`, `flashAttn`, `gpuLayers`, `batchSize`/`ubatchSize`, `maxNumSeqs`, `gpuMemoryUtilization`, … and `extraArgs` (only [allowed flags](#deployments-and-benchmarks)). Unknown fields are refused. |
| `cpus`, `memoryMb` | Optional limits within the caps; without `memoryMb` the estimate is used |
| `hostPort` | Optional, only inside the configured range (none by default) |
| `name` | Optional |
| `start` | Default `true`; with approval mode `approve` the start waits for the user |
| `dryRun` | `true`: only validate; returns the command and estimates, creates nothing |
```json
{ "created": true, "id": "01M…", "state": "pending_approval",
"command": "docker run -v <models>:/models:ro ghcr.io/ggml-org/llama.cpp:server-intel -m /models/… -c 16384 -ctk q8_0 …",
"estimates": { "memoryMb": 9800, "vramMb": 7900, "gpuVramMb": 32768 }, "limits": { "memoryMb": 9800, "cpus": null },
"message": "Created; the start waits for the user's approval in Kaname. Don't retry or poll; tell the user and stop." }
```
#### `PATCH /api/v1/deployments/{id}`, `POST …/start`, `POST …/stop`, `DELETE …`
`deployments:write`, own deployments only. `PATCH` takes `options` (merged into the current ones),
`cpus`, `memoryMb`, `hostPort`, `name`, and only while the deployment is stopped; it returns the new
command and estimates. `start` goes through the same guardrails as creating one (and approval);
`stop` and `DELETE` never need approval.
### Benchmarks
#### `POST /api/v1/benchmarks`
`benchmarks:run`. A [BetterBench](https://github.com/GGZ14/BetterBench) run against the token's own
**running** deployment.
| Field | |
| --- | --- |
| `kind` | `run` (default) or `ab` (paired A/B with `deploymentBId`, same model; needs 2 agent deployments) |
| `deploymentId`, `deploymentBId` | Own, running deployments |
| `quick` | `true`: 5 passes, a smoke check; default `false`: 20 passes, comparable |
| `passes`, `phases` | Optional: passes per category; phases `decode`, `prefill`, `concurrency` (default all) |
| `label`, `description` | Optional; the description goes into the report and the launch80 preview |
Answers `201` with `state` `pending_approval` (default) or `queued`, and the run's time limit.
#### `GET /api/v1/benchmarks/{id}[?wait=S][&full=1]`, `GET /api/v1/benchmarks[?deployment=&requested_by=&limit=]`
`benchmarks:read`. Compact result:
```json
{ "id": "01M…", "kind": "run", "state": "completed", "label": "q8_0 KV", "mine": true,
"headline": { "decodeTps": 61.3, "prefillTps": 1840, "prefillDepth": 16000, "ttftMs": 92, "peakParallelTps": 155.2, "peakParallelLevel": 8 },
"setup": { "gpus": "1× Intel Arc Pro B65 (32 GiB)", "pcie": "Gen5 x8 of Gen5 x16", "p2p": "n/a", "rebar": "on",
"engine": "llama.cpp b11541-f2918cabb", "image": "ghcr.io/ggml-org/llama.cpp:server-intel", "digest": "sha256:…",
"model": "Qwen3-8B-GGUF Q4_K_M with q8_0 KV cache", "ctx": "16,384", "concurrency": "4" },
"resources": { "cpuAvgCores": 1.1, "ramPeakBytes": 2100000000,
"gpus": [{ "name": "Intel Arc Pro B65", "vramPeakMb": 9100, "vramTotalMb": 32768, "utilAvg": 88.5, "powerAvgW": 151.2, "tempPeakC": 71 }] },
"error": null, "next": "Done. Compare runs with GET /api/v1/benchmarks/compare?ids=…" }
```
`?full=1` adds BetterBench's complete summary (per category, per prompt depth, per concurrency
level). A/B runs add `ab` (pairs, verdict, decode difference with its confidence interval).
`POST /api/v1/benchmarks/{id}/cancel` cancels an own run.
#### `GET /api/v1/benchmarks/compare?ids=a,b,…`
`benchmarks:read`. 2–16 runs: headline numbers side by side, the setup values that differ per run
(`differs`) and the ones they share (`same`).
#### `POST /api/v1/sweeps`, `GET /api/v1/sweeps/{id}[?wait=S]`, `POST /api/v1/sweeps/{id}/cancel`
`benchmarks:run` / `benchmarks:read`. One or two settings varied from an own base deployment, e.g.
`{"baseDeploymentId": "…", "params": [{"key": "kvCache", "values": ["f16", "q8_0"]}], "quick": true}`.
Keys: `contextSize`, `modelFile`, `kvCache`, `threads`, `parallel`, `batchSize`, `ubatchSize`,
`flashAttn`, `cacheRamMb`, `gpuLayers`, `dtype`, `maxNumSeqs`, `kvCacheGb`, `gpuMemoryUtilization`,
`cpus` (per engine, as in the UI). Each variant is deployed, benchmarked and removed again. The
answer lists every variant with its headline numbers and setup.
## Waiting instead of polling
Every status call costs an agent a round of its context. The status endpoints (`/jobs/{id}`,
`/deployments/{id}`, `/benchmarks/{id}`, `/sweeps/{id}`) take `?wait=S` (seconds, at most 900): the
request is held until the state is settled (finished, running, failed, cancelled) or the time is up,
then answers with the current state plus `waitedSeconds` and `timedOut`. Something that waits for the
user's approval answers right away: there is nothing to wait for. Use one waiting call instead of a
polling loop, with a wait shorter than your HTTP client's timeout (and any proxy's).
## Guardrails
### Downloads
Settings → API tokens → **Guardrails for API downloads**. They apply to every token together;
downloads started in the UI aren't affected.
@@ -197,6 +315,38 @@ downloads started in the UI aren't affected.
Rejecting a request cancels its job. A model that only that request added leaves the library again;
for a request that added files to an existing model, the previous selection is restored.
### Deployments and benchmarks
Settings → API tokens → **Guardrails for API deployments and benchmarks**, for every token together:
| Setting | Default | Rejection |
| --- | --- | --- |
| Approval | **Ask me**: starts, runs and sweeps wait as *pending approval* on the deployment, run or sweep page. Creating or editing a stopped deployment, stopping and deleting own ones need none. | (not an error) |
| Agent deployments at once | 1 (running, starting or waiting to start); 2 for A/B runs | `429 too_many_deployments` |
| One GPU job at a time | No agent start while an agent run or sweep is pending or running, or another agent deployment is still loading; one agent run or sweep at a time; no sweep while an agent deployment runs (the sweep deploys its variants itself) | `429 gpu_busy` |
| Max minutes per run / sweep | 30 / 180, then the worker stops it | (`failed` with the reason) |
| Max variants per sweep | 8 | `422 too_many_variants` |
| Runtimes | Any with a pulled image, or an allowlist | `403 runtime_not_allowed`, `409 runtime_not_pulled` |
| Extra arguments | Tuning flags only, per engine (editable list); values can't be paths or URLs | `403 arg_not_allowed`, naming the argument |
| Host ports | None (Kaname reaches deployments over the Docker network), or a range | `403 port_not_allowed` |
| Memory / CPU caps | The host's size, or what you set; agent deployments always get a memory limit (the estimate if they don't give one) | `422 limit_exceeded` |
| Own deployments only | Agents change and benchmark only what their token created | `403 not_owner` |
Docker options (devices, volumes, privileges, capabilities, network) are never arguments: they belong
to the runtime, which tokens can't change.
### Protected deployments
The **Protect** button on a deployment's page: agents can't edit, start, stop, delete or benchmark
it, and can't start a deployment on the same GPUs if the estimated VRAM of everything running there
plus the new one (and 1 GiB to spare) exceeds the GPUs' VRAM (`409 vram_protected`). When the need
can't be estimated (only some layers on the GPU), such a start is refused too.
### Activity
Settings → API tokens → **Activity** next to each token lists what it did: every request that
creates or changes something, waits for approval, or was refused (with the error code).
## Behind a forward-auth proxy (Traefik)
If Kaname sits behind forward auth (e.g. Traefik with Tinyauth or Pocket ID), the proxy would answer