API for agents: tokens, /api/v1 for downloads, verify, repair, tags

Brings back the token API that 0.15 removed with deployments, for
models only, ported onto the current code (local models, lean client
bundles, MiB-rounded disk space):

- Scoped bearer tokens (models:read, downloads:create, models:verify,
  tags:write), stored as SHA-256, managed in Settings -> API tokens.
  Only /api/v1 accepts them; the rest stays OIDC-only.
- /api/v1: Hub lookup, library with the search filters, download
  requests through the add-model/queue path (idempotent), repair of
  missing or broken files, verify / deep verify, tags, job status with
  ?wait=, cancelling or withdrawing the token's own jobs, disk space.
- Guardrails for downloads and repairs: approval (default ask), max
  size per request, minimum free space incl. reserved bytes, agent jobs
  at once, author allowlist (new downloads only). Approve/reject in the
  UI, "requested by" badges and filter, activity log per token.
- Migration 0027 adds api_tokens, agent_activity and requested_by
  columns on models and jobs; job state pending_approval.
- docs/api.md, docs/agent/SKILL.md and the kaname curl helper; DB-backed
  API tests. The login gate test now expects /api/v1 to be left to
  token auth.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-11-11 21:52:28 +01:00
1 parent 7d1a8fb85a
commit 0e0445a418
63 files changed
+5448 -42

No files matched your search

+253
View File
@@ -0,0 +1,253 @@
---
name: kaname-models
description: Find, download, verify, repair and tag local LLMs (Hugging Face models, GGUF quants) on the user's Kaname server. Use when the user asks to get, download, add, check, fix or tag a model, asks which models are available locally, or how much disk space is left for models.
required_environment_variables:
- name: KANAME_URL
prompt: Kaname base URL, e.g. https://models.example.com (no trailing slash)
- name: KANAME_TOKEN
prompt: Kaname API token (kn_…), from Settings → API tokens
---
# Kaname: the user's local model library
Kaname downloads models from Hugging Face onto the user's server, pinned to an exact commit. With
this skill you can:
- see what is already downloaded, and how much disk space is left
- look up a Hugging Face repo (its commit, quants and sizes)
- request a download, and follow it until it's done
- verify a model's files, and repair the ones that are missing or broken
- add and remove tags on models
- cancel jobs that **you** requested
You **cannot** delete models or files, update a model to a newer commit, change settings, or touch
jobs someone else started. When the user needs one of those, tell them to do it in Kaname's web UI.
## Setup
You need two environment variables:
- `KANAME_URL`: e.g. `https://models.example.com` (no trailing slash)
- `KANAME_TOKEN`: the API token (`kn_…`). **Never print it, log it or put it in a URL.**
The examples use `kaname`, a two-line wrapper around `curl` that adds the token and JSON headers.
Install it once:
```bash
mkdir -p ~/.local/bin && curl -fsSL https://git.linxweiler.xyz/pascallinxweiler/Kaname/raw/branch/main/docs/agent/kaname -o ~/.local/bin/kaname && chmod +x ~/.local/bin/kaname
```
If `kaname` isn't available, write the full command every time instead:
`curl -sS -H "Authorization: Bearer $KANAME_TOKEN" -H "Content-Type: application/json" …`.
Every command may run in a fresh shell, so don't rely on a shell function or alias.
Every answer is JSON. Errors look like `{"error": {"code": "…", "message": "…"}}`, and the message
says what to do next. Read it before you do anything else.
## 0. Check who you are and your limits
```bash
kaname "$KANAME_URL/api/v1"
```
This returns your token name, your **scopes** (what you're allowed to do) and the **guardrails**:
| Field | Default | Meaning |
| --- | --- | --- |
| `approvalMode` | `approve` | Your downloads and repairs wait until the user approves them. That's normal, not an error. |
| `maxRequestSize` | 60 GB | One request may download at most this much. |
| `minFreeSize` | 100 GB | This much must stay free on disk after your download. |
| `maxOpenAgentJobs` | 2 | At most this many agent downloads may be pending or running at once. |
| `allowedAuthors` | `[]` (any) | If not empty, new downloads must come from these Hugging Face authors. |
| Scope | Lets you |
| --- | --- |
| `models:read` | look up repos, list models and tags, read jobs and disk space |
| `downloads:create` | request downloads and repairs, cancel your own downloads |
| `models:verify` | start verify and deep verify, cancel your own verify jobs |
| `tags:write` | add and remove tags on models |
If a call answers `403 forbidden`, you lack the scope. Tell the user which one is missing; don't
try another way around it.
## 1. Is the model already here?
Always check before you download.
```bash
kaname "$KANAME_URL/api/v1/models?q=qwen3%208b"
kaname "$KANAME_URL/api/v1/models?author=unsloth&quant=Q4_K_M&status=ready"
```
Filters: `q` (every word must match the repo, author, family, quant or tags), `author`, `family`,
`quant`, `tag`, `status`, `requested_by`. You can repeat a filter or separate values with commas
(OR within a filter, AND across filters).
The `status` values are `pending`, `downloading`, `ready`, `incomplete`, `failed`, `deleting`,
`pending_approval`, `update_available`, `repo_missing` and `commit_missing`.
If the model is there with `status: "ready"`, you're done. Don't request it again. For details on
one model (its files and their state, tags, latest job):
```bash
kaname "$KANAME_URL/api/v1/models/<modelId>"
```
`source: "local"` means a folder the user put there by hand, with no Hugging Face repo. Kaname
can't download into a local model or repair it, but it can verify it and tag it.
## 2. Look up the repo on Hugging Face
```bash
kaname "$KANAME_URL/api/v1/hub/lookup?repo=unsloth/Qwen3-8B-GGUF"
```
`repo` can also be a pasted Hugging Face URL. From the answer, note:
- `sha`: the exact commit. You need it to request the download.
- `quants`: one entry per GGUF quant, with `size`. Pick one that fits what the user asked for and
is no bigger than `maxRequestSize`. If the user didn't say, `Q4_K_M` is a sensible default.
- `inLibrary`: not `null` if the repo is already in Kaname (see step 1).
- `gated`: if it isn't `false`, the download only works when the user's Hugging Face account has
accepted the model's terms.
Check the free space before a big download:
```bash
kaname "$KANAME_URL/api/v1/disk" # availableForRequests = what one request may still use
```
## 3. Request the download
```bash
kaname -X POST "$KANAME_URL/api/v1/downloads" \
-d '{"repoId":"unsloth/Qwen3-8B-GGUF","sha":"<sha from the lookup>","quant":"Q4_K_M"}'
```
- `quant` downloads that quant's weight files (every split part), plus the companion files the user
picked in Kaname's settings (chat template, vision projector, …).
- For repos without GGUF quants (safetensors), send `"include": ["*.safetensors", "*.json"]` instead
of `quant`. Send exactly one of the two.
- Optional: `"tags": ["coding"]`. Run `GET /api/v1/tags` first and reuse the tags that already
exist.
Kaname answers with one of these:
| Answer | Meaning | What you do |
| --- | --- | --- |
| `201`, `state: "pending_approval"` | Waits for the user. | Tell the user what you requested (repo, quant, size) and that they need to approve it in Kaname. **Stop there. Don't retry and don't poll.** |
| `201`, `state: "queued"` | Starts on its own. | Follow it (step 4). |
| `200`, `created: false` | Exactly this was already requested. | You get the existing job back. Don't request it again. |
If the repo is already in the library at the same commit, the request adds only the missing files
(for example another quant). A repo that's in the library at a different commit is refused: only
the user can update it.
## 4. Follow a job
```bash
kaname -m 960 "$KANAME_URL/api/v1/jobs/<jobId>?wait=900"
```
With `?wait=900`, Kaname holds the request open until the job is finished, or up to 900 seconds.
One such call replaces a whole polling loop. Keep curl's `-m` a bit above the wait. Each call costs
you context, so make few of them:
| `state` | What you do |
| --- | --- |
| `pending_approval` | Don't poll. Tell the user it waits for their approval and stop. Check again only when the user says they approved it (or, if they ask for it, once later from a scheduled task). |
| `queued`, `downloading`, `verifying` | One call with `?wait=900`. If it comes back with `timedOut: true`, tell the user the progress and the ETA (`progress.etaSeconds`) instead of waiting again and again. |
| `completed` | Tell the user it's ready. For a verify job, also read `verify` (see step 5). |
| `cancelled` | The user rejected or cancelled it. Don't ask again unless they tell you to. |
| `failed` | Report `error.message` to the user. Don't retry in a loop. |
| `interrupted` | Kaname restarted. Tell the user; they can resume it. |
Add `&log=20` only when you need to explain a failure (the last lines of the download log).
## 5. Verify and repair
Run a verify when the user asks whether a model is intact, or after something went wrong:
```bash
kaname -X POST "$KANAME_URL/api/v1/models/<modelId>/verify" # presence and size, takes seconds
kaname -X POST "$KANAME_URL/api/v1/models/<modelId>/verify" -d '{"deep":true}' # hashes every byte: slow, but thorough
```
A verify starts right away; it never needs approval. Follow it like any other job. When it has
finished, the job has a `verify` block:
```json
"verify": { "ok": false, "missing": ["…gguf"], "sizeMismatch": [], "hashMismatch": [], "next": "POST /api/v1/models/…/repair …" }
```
If `ok` is `false`, repair it. That downloads only the files that are missing or broken:
```bash
kaname -X POST "$KANAME_URL/api/v1/models/<modelId>/repair"
```
A repair counts as a download: same guardrails, and by default it waits for the user's approval
just like step 3. If nothing is broken, Kaname answers `409 nothing_to_repair`. Then don't repair;
run a deep verify if you suspect damage. Deep verify and repair aren't possible for local models.
## 6. Tags
```bash
kaname "$KANAME_URL/api/v1/tags" # existing tags, with how many models use each
kaname -X POST "$KANAME_URL/api/v1/models/<modelId>/tags" -d '{"name":"coding"}' # add (creates the tag if it's new)
kaname -X DELETE "$KANAME_URL/api/v1/models/<modelId>/tags/coding" # remove (by name, case-insensitive)
```
Reuse existing tags instead of inventing near-duplicates (`code` vs `coding`). Removing a tag from a
model doesn't delete the tag itself. Tag only what the user asked for, or what clearly fits their
existing scheme.
## 7. Cancel your own job
```bash
kaname -X POST "$KANAME_URL/api/v1/jobs/<jobId>/cancel"
```
This works only for jobs your token requested:
- A job that's still `pending_approval` is withdrawn. If it was a brand-new model, the model leaves
the library again (`removedModel: true`).
- A queued or running job is stopped. Files that are already downloaded stay.
For anything else you get `403 not_own_job`: tell the user they can cancel it in Kaname.
## When a request is refused
| `error.code` | What to do |
| --- | --- |
| `too_large` | Pick a smaller quant, or fewer files, that fits `maxRequestSize`. |
| `disk_space` | Pick a smaller quant, or tell the user the disk is full. |
| `too_many_jobs` | Your earlier downloads are still pending or running. Tell the user and stop. Don't wait in a loop. |
| `author_not_allowed` | Find the model from an allowed author, or ask the user. |
| `already_exists` | The repo is in the library at another commit; the user updates it in Kaname. |
| `busy` | That model already has a job pending or running. Tell the user and stop. |
| `nothing_to_repair` | Every file is present. Run a deep verify first if you suspect damage. |
| `local_model` | A local folder: nothing to download, and no hashes to compare against. Use a plain verify. |
| `not_own_job` | Only the user can cancel this job. |
| `gated_no_access`, `gated_no_token` | The user must accept the model's terms on Hugging Face (and Kaname needs a token). |
| `disk_unknown` | Kaname's worker is offline. Tell the user and stop. |
| `rate_limited` | Hugging Face is rate limiting. Try once more later, not in a loop. |
| `unauthorized`, `forbidden` | Your token is wrong or revoked, or it lacks a scope. Tell the user. |
| `invalid_request`, `invalid_json` | Fix the request as the message says. |
Never work around a guardrail, for example by splitting one big download into several requests, or
by repairing a model to fetch files it never had. Everything you do is listed under your token's
name in Kaname, refusals included.
## A complete example
> User: "Get me Qwen3 8B, something that fits in about 6 GB."
1. `kaname "$KANAME_URL/api/v1/models?q=qwen3%208b"`: nothing ready yet.
2. `kaname "$KANAME_URL/api/v1/hub/lookup?repo=unsloth/Qwen3-8B-GGUF"`: `Q4_K_M` is 5.0 GB; note `sha`.
3. `kaname -X POST "$KANAME_URL/api/v1/downloads" -d '{"repoId":"unsloth/Qwen3-8B-GGUF","sha":"…","quant":"Q4_K_M"}'`
answers `pending_approval`.
4. Tell the user: "I've requested unsloth/Qwen3-8B-GGUF Q4_K_M (5.0 GB). It's waiting for your
approval in Kaname." Then stop.
5. When the user says it's approved: `kaname -m 960 "$KANAME_URL/api/v1/jobs/<jobId>?wait=900"`, then
report that it's done, or the progress and ETA.
+3
View File
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
# curl with the Kaname API token and JSON headers. Usage: kaname [curl options] URL
exec curl -sS -H "Authorization: Bearer $KANAME_TOKEN" -H "Content-Type: application/json" "$@"
+330
View File
@@ -0,0 +1,330 @@
# Kaname API (`/api/v1`)
A small JSON API for programs and AI agents: look up Hugging Face repos, list the library, request
downloads and follow them, verify and repair models, and tag them. Everything a token can do is
bounded by [guardrails](#guardrails). No token can delete models or files, update a model to
another commit, change settings, manage tokens, or touch jobs it didn't request.
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.
For agents there's a ready-made skill: [docs/agent/SKILL.md](agent/SKILL.md). Give it to the agent
together with `KANAME_URL` and `KANAME_TOKEN`.
- [Authentication](#authentication)
- [Errors](#errors)
- [Endpoints](#endpoints)
- [Waiting instead of polling](#waiting-instead-of-polling)
- [Guardrails](#guardrails) and [approval](#approval)
- [Activity](#activity)
- [Behind a forward-auth proxy (Traefik)](#behind-a-forward-auth-proxy-traefik)
## Authentication
Create a token in **Settings → API tokens**. It is shown once; Kaname stores only its SHA-256.
Send it with every request:
```
Authorization: Bearer kn_…
```
| Scope | Allows |
| --- | --- |
| `models:read` | Hub lookup, list models and tags, read jobs (and their log), disk space |
| `downloads:create` | Request downloads and repairs (within the guardrails); cancel its own downloads |
| `models:verify` | Start verify and deep verify; cancel its own verify jobs |
| `tags:write` | Add and remove tags on models (a new tag is created on first use) |
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. **Scopes** changes what a token may do (from its
next request on); **Revoke** stops it immediately; a revoked token can be deleted to free its name.
Everything a token requests is marked with its name ("requested by hermes") on the model and job
pages and in the library, where you can filter by it (**Requested by**).
## Errors
Errors are JSON with a message meant to be read and acted on:
```json
{ "error": { "code": "too_large", "message": "exceeds max size per request 60.0 GB: requested 74.2 GB. Pick a smaller quant or fewer files." } }
```
| Status | Codes |
| --- | --- |
| 400 | `invalid_request` (also unknown fields), `invalid_json`, `empty_selection` (the quant or globs match nothing), `invalid_repo_id`, `invalid` (e.g. an empty tag name) |
| 401 / 403 | `unauthorized`, `forbidden` (scope), `not_own_job`, `author_not_allowed`, `gated_no_token`, `gated_no_access` |
| 404 | `not_found`, `repo_not_found`, `revision_not_found` |
| 409 | `already_exists` (the repo is in the library at another commit), `busy` (the model has a pending, queued or running job), `nothing_to_repair`, `local_model`, `not_cancellable`, `hub_missing` |
| 422 | `too_large` |
| 429 | `too_many_jobs`, `rate_limited` (Hugging Face) |
| 503 / 507 | `disk_unknown` (worker offline), `disk_space` |
Sizes come as bytes plus a readable `"… GB"` field (decimal GB, like the Hub).
## Endpoints
| Method and path | Scope |
| --- | --- |
| [`GET /api/v1`](#get-apiv1) | any token |
| [`GET /api/v1/hub/lookup?repo=`](#get-apiv1hublookup) | `models:read` |
| [`GET /api/v1/models`](#get-apiv1models), [`GET /api/v1/models/{id}`](#get-apiv1modelsid) | `models:read` |
| [`GET /api/v1/tags`](#tags) | `models:read` |
| [`GET /api/v1/jobs/{id}`](#get-apiv1jobsid) | `models:read` |
| [`GET /api/v1/disk`](#get-apiv1disk) | `models:read` |
| [`POST /api/v1/downloads`](#post-apiv1downloads) | `downloads:create` |
| [`POST /api/v1/models/{id}/repair`](#post-apiv1modelsidrepair) | `downloads:create` |
| [`POST /api/v1/models/{id}/verify`](#post-apiv1modelsidverify) | `models:verify` |
| [`POST /api/v1/jobs/{id}/cancel`](#post-apiv1jobsidcancel) | `downloads:create` or `models:verify` (own jobs only) |
| [`POST /api/v1/models/{id}/tags`, `DELETE /api/v1/models/{id}/tags/{name}`](#tags) | `tags:write` |
### `GET /api/v1`
Who you are, your scopes, the current guardrails and the endpoint list.
```bash
curl -s -H "Authorization: Bearer $KANAME_TOKEN" "$KANAME_URL/api/v1"
```
```json
{
"token": { "name": "hermes", "scopes": ["models:read", "downloads:create"] },
"guardrails": { "approvalMode": "approve", "maxRequestBytes": 60000000000, "maxRequestSize": "60.0 GB",
"minFreeBytes": 100000000000, "minFreeSize": "100.0 GB", "maxOpenAgentJobs": 2, "allowedAuthors": [] },
"endpoints": ["…"]
}
```
### `GET /api/v1/hub/lookup`
`?repo=org/name[&revision=main][&files=all]`. Resolves the revision to a commit SHA and lists quants
and files: the same data as the Add model dialog. `repo` may also be a Hub URL. Up to 200 files are
listed unless `files=all`.
```json
{
"repoId": "unsloth/Qwen3-8B-GGUF", "revision": "main", "sha": "9e6855bc…", "gated": false,
"lastModified": "2026-05-01T10:00:00.000Z",
"inLibrary": null,
"quants": [{ "quant": "Q4_K_M", "files": 1, "bytes": 5027783488, "size": "5.0 GB" }, "…"],
"fileCount": 31, "totalBytes": 104000000000,
"files": [{ "path": "Qwen3-8B-Q4_K_M.gguf", "bytes": 5027783488 }, "…"],
"filesTruncated": false
}
```
`inLibrary` is `{ modelId, pinnedSha, status }` when the repo is already in Kaname.
### `GET /api/v1/models`
The library, filtered like the library page:
| Parameter | Meaning |
| --- | --- |
| `q` | Search text; every word must match (repo, author, family, quant, tags, …) |
| `author`, `family`, `quant`, `tag` | Facets; repeat or comma-separate values (OR within a facet, AND across) |
| `status` | `pending`, `downloading`, `ready`, `incomplete`, `failed`, `deleting`, `pending_approval`, `update_available`, `repo_missing`, `commit_missing` |
| `requested_by` | Token name |
```json
{ "count": 1, "models": [{ "id": "01M…", "repoId": "unsloth/Qwen3-8B-GGUF", "source": "hub", "status": "ready",
"pendingApproval": false, "pinnedSha": "9e68…", "quants": ["Q4_K_M"], "tags": ["agent"], "selectedFiles": 2,
"selectedBytes": 5027783488, "onDiskBytes": 5027783488, "onDisk": "5.0 GB", "updateAvailable": false,
"hubState": "available", "requestedBy": "hermes", "createdAt": "…", "downloadedAt": "…" }] }
```
`source` is `local` for folders imported without a Hub repo; they have no `pinnedSha`.
### `GET /api/v1/models/{id}`
One model: status, pinned commit, tags, folder (`localPath`, relative to the models folder), the
selected files with their state (`pending`, `present`, `missing`, `size_mismatch`, `hash_mismatch`,
`verified`), the last verify time and the latest job.
### `POST /api/v1/downloads`
Request a download of a repo **at a pinned commit**: take `sha` from the lookup.
| Field | |
| --- | --- |
| `repoId` | `"org/name"` |
| `sha` | The full 40-character commit SHA |
| `quant` | e.g. `"Q4_K_M"`: that quant's weight files (all split parts), plus the companion files ticked in Settings → Downloads (chat template, mmproj, …), as in the Add model dialog |
| `include` | Instead of `quant`: glob patterns, e.g. `["*.safetensors", "*.json"]` |
| `tags` | Optional user tags for the model |
| `revision` | Optional branch to track for update checks (default `main`) |
```bash
curl -s -X POST -H "Authorization: Bearer $KANAME_TOKEN" -H "Content-Type: application/json" \
-d '{"repoId":"unsloth/Qwen3-8B-GGUF","sha":"9e6855bc…","quant":"Q4_K_M"}' \
"$KANAME_URL/api/v1/downloads"
```
```json
{ "created": true, "modelId": "01M…", "jobId": "01M…", "state": "pending_approval",
"requestedBytes": 5027783488, "requestedSize": "5.0 GB", "files": ["Qwen3-8B-Q4_K_M.gguf", "template"],
"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 *Ask me*) or `queued` (*Automatic*).
- **200** with `"created": false`: the same repo, commit and files were requested before; you get the
existing model and its latest job. Nothing is queued twice.
- If the repo is already in the library at the same commit, the request adds the files missing from
its selection (only the added bytes count against the guardrails). At another commit it is
refused: updating a model is done in the UI. A local model with the same name is refused too.
It uses the same code as the Add model dialog: the file list is fetched again from the Hub at that
commit (the client's list isn't trusted).
### `POST /api/v1/models/{id}/repair`
Downloads again the selected files that aren't `present` or `verified` (after a verify found them
missing or broken, or after a failed download). The guardrails and approval apply as for a download;
only the author allowlist doesn't (the model is already in the library). `409 nothing_to_repair` if
every file is present; `409 local_model` for a local model.
```json
{ "modelId": "01M…", "jobId": "01M…", "state": "pending_approval", "requestedBytes": 8000000000,
"requestedSize": "8.0 GB", "files": ["Qwen3-8B-Q8_0.gguf"], "message": "…" }
```
### `POST /api/v1/models/{id}/verify`
Body optional: `{"deep": true}` hashes every file against the Hub (slow); without it, Kaname checks
each selected file's presence and size (seconds). Verify only reads files, so it never waits for
approval and doesn't count against the guardrails. Deep verify isn't possible for a local model.
Answers `201` with the `jobId`; the finished job carries a [`verify`](#get-apiv1jobsid) block.
### `GET /api/v1/jobs/{id}`
`[?wait=S][&log=N]`. Compact job state:
```json
{ "id": "01M…", "modelId": "01M…", "repoId": "unsloth/Qwen3-8B-GGUF", "kind": "download", "purpose": "initial",
"state": "downloading", "cancelRequested": false, "requestedBy": "hermes",
"progress": { "doneBytes": 3000000000, "totalBytes": 5027783488, "percent": 59.7, "done": "3.0 GB", "total": "5.0 GB",
"speedBytesPerSecond": 52000000, "etaSeconds": 39 },
"error": null,
"files": [{ "path": "Qwen3-8B-Q4_K_M.gguf", "state": "downloading", "doneBytes": 3000000000, "totalBytes": 5027783488 }],
"createdAt": "…", "startedAt": "…", "finishedAt": null,
"next": "Downloading; GET with ?wait=900 instead of polling." }
```
- `kind`: `download`, `verify`, `deep_verify` or `delete`. `purpose` (downloads): `initial`, `add`,
`import`, `repair`, `update`.
- `state`: `pending_approval`, `queued`, `downloading`, `verifying`, `completed`, `failed`,
`cancelled` (also when the user rejected the request), `interrupted`.
- A finished verify adds
`"verify": { "checked": 2, "missing": [], "sizeMismatch": [], "hashMismatch": [], "ok": true, "next": "…" }`.
- The `hf` log only with `?log=N` (the last N lines, at most 200). For `?wait=S` see
[Waiting instead of polling](#waiting-instead-of-polling).
### `POST /api/v1/jobs/{id}/cancel`
Only for jobs this token requested (`403 not_own_job` otherwise); download jobs need
`downloads:create`, verify jobs `models:verify`.
- A job that waits for approval is **withdrawn**, exactly like a rejection: a model that only this
request added leaves the library again (`"removedModel": true`), and added files leave the
selection again.
- A queued or running job is stopped by the worker (`"state": "cancelling"`). Files already on disk
stay.
### Tags
- `GET /api/v1/tags`: every tag with the number of models using it:
`{ "count": 2, "tags": [{ "name": "coding", "models": 3 }, …] }`.
- `POST /api/v1/models/{id}/tags` with `{"name": "coding"}`: attaches the tag, creating it if no
tag of that name exists (names match case-insensitively). Answers with the model's tags.
- `DELETE /api/v1/models/{id}/tags/{name}`: detaches the tag (by name, case-insensitive; URL-encode
it). The tag itself stays; delete or rename tags in Settings → Tags.
### `GET /api/v1/disk`
Space on the models folder, as reported by the worker every few seconds:
```json
{ "workerOnline": true, "freeBytes": 945600000000, "totalBytes": 2000000000000, "usedBytes": 1054400000000,
"reservedBytes": 105454144, "minFreeBytes": 100000000000, "availableForRequestsBytes": 845494545856,
"free": "945.6 GB", "total": "2000.0 GB", "availableForRequests": "845.5 GB" }
```
`reservedBytes` is what open downloads still have to fetch; `availableForRequests` is what a
request may use before it hits the minimum-free guardrail.
## Waiting instead of polling
Every status call costs an agent a round of its context. `GET /api/v1/jobs/{id}` takes `?wait=S`
(seconds, at most 900): the request is held until the job is settled (finished, failed, cancelled,
interrupted) or the time is up, then answers with the current state plus `waitedSeconds` and
`timedOut`. A job that waits for the user's approval answers right away: there's 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
Settings → API tokens → **Guardrails for API downloads**. They apply to every token together and to
downloads and repairs; downloads you start in the UI aren't affected.
| Setting | Default | Rejection |
| --- | --- | --- |
| Approval | **Ask me**: requests wait as *pending approval* until you approve or reject them | (not an error: `state: pending_approval`) |
| Max size per request | 60 GB | `422 too_large` |
| Keep free on the models folder | 100 GB, after the download and after what other open downloads still need | `507 disk_space` (`503 disk_unknown` if the worker is offline) |
| Agent jobs at once | 2 downloads or repairs (pending approval, queued or running) | `429 too_many_jobs` |
| Allowed authors | empty = any; e.g. `unsloth, ggml-org, Qwen` (case-insensitive). New downloads only | `403 author_not_allowed` |
Verify, deep verify and tags never need approval and don't count against these limits; a model can
have only one job at a time either way (`409 busy`).
### Approval
A pending request shows an **Approve / Reject** bar on the model page and the job page, and
*awaiting approval* in the library (filter Status → awaiting approval). Approving queues it.
Rejecting cancels the 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.
## Activity
Settings → API tokens → **Activity** next to each token lists what it did: every request that
creates or changes something (downloads, repairs, verifies, tags, cancels), whether it waits for
approval, and every refusal with its 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
API calls with a login redirect. Let `/api/v1/` through without forward auth; Kaname checks the
bearer token itself there. Everything else keeps forward auth.
Two routers for the same host, the API one with a higher priority and no auth middleware:
```yaml
# docker compose labels on the kaname "web" service
labels:
- traefik.enable=true
- traefik.http.services.kaname.loadbalancer.server.port=3000
# UI and internal API: forward auth as before
- traefik.http.routers.kaname.rule=Host(`models.example.com`)
- traefik.http.routers.kaname.entrypoints=websecure
- traefik.http.routers.kaname.tls=true
- traefik.http.routers.kaname.middlewares=tinyauth
- traefik.http.routers.kaname.service=kaname
# Token API: no forward auth (bearer tokens are checked by Kaname)
- traefik.http.routers.kaname-api.rule=Host(`models.example.com`) && PathPrefix(`/api/v1/`)
- traefik.http.routers.kaname-api.entrypoints=websecure
- traefik.http.routers.kaname-api.tls=true
- traefik.http.routers.kaname-api.priority=100
- traefik.http.routers.kaname-api.service=kaname
```
Notes:
- Use ``PathPrefix(`/api/v1/`)`` with the trailing slash, so nothing else that starts with `/api/v1`
slips past forward auth. Kaname's own login gate also excludes exactly `/api/v1` and `/api/v1/…`.
- Don't exempt `/api` as a whole: the internal routes rely on the login session.
- Agents on the same network can also call Kaname directly (`http://<host>:3000/api/v1/…`) without
going through the proxy.
- `?wait=` holds a request open for up to 15 minutes; raise the proxy's response timeout, or ask
agents to use a shorter wait.