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>
20 KiB
Kaname API (/api/v1)
A small JSON API for programs and AI agents: look up Hugging Face repos, list the local library, request downloads, deploy models and benchmark them to tune launch options. Everything an agent can do here is bounded by 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
- Errors
- Endpoints: models and downloads, deployments, benchmarks
- Waiting instead of polling
- Guardrails
- 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, 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.
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.
Errors
Errors are JSON with a message meant to be read and acted on:
{ "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 (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 (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).
Endpoints
GET /api/v1
Any valid token. Who you are, your scopes, the current guardrails and the endpoint list.
curl -s -H "Authorization: Bearer $KANAME_TOKEN" "$KANAME_URL/api/v1"
{
"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]
models:read. 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.
{
"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
models:read. 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 |
{ "count": 1, "models": [{ "id": "01M…", "repoId": "unsloth/Qwen3-8B-GGUF", "status": "ready", "pendingApproval": false,
"pinnedSha": "9e68…", "quants": ["Q4_K_M"], "tags": ["agent"], "selectedFiles": 1, "selectedBytes": 5027783488,
"onDiskBytes": 5027783488, "onDisk": "5.0 GB", "updateAvailable": false, "hubState": "available",
"requestedBy": "hermes", "createdAt": "…", "downloadedAt": "…" }] }
GET /api/v1/models/{id}
models:read. One model with its selected files (path, bytes, state) and latest job.
POST /api/v1/downloads
downloads:create. Request a download of a repo at a pinned commit: take sha from the lookup.
| Field | |
|---|---|
repoId |
"org/name" |
sha |
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) |
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"
{ "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 or poll; tell the user and stop." }
- 201: a new job,
statepending_approval(approval modeapprove) orqueued(auto). - 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 that are 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.
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}[?wait=S][&log=N]
models:read. Compact job state:
{ "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; check again in a minute." }
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). ?wait=S returns once the job is finished (or right away
while it waits for approval); see Waiting instead of polling.
GET /api/v1/disk
models:read. Space on the models folder, as reported by the worker every few seconds:
{ "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 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 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). 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 |
{ "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 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:
{ "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.
| Setting | Default | Rejection |
|---|---|---|
| Approval | Ask me: requests wait as pending approval until you approve or reject them on the model or job page | (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 (pending approval, queued or running) | 429 too_many_jobs |
| Allowed authors | empty = any; e.g. unsloth, ggml-org, Qwen (case-insensitive) |
403 author_not_allowed |
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
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:
# 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
The same in a file provider:
http:
routers:
kaname-api:
rule: Host(`models.example.com`) && PathPrefix(`/api/v1/`)
entryPoints: [websecure]
tls: {}
priority: 100
service: kaname
Notes:
- Use
PathPrefix(/api/v1/)with the trailing slash, so nothing else that starts with/api/v1slips past forward auth. Kaname's own login gate also excludes exactly/api/v1and/api/v1/…. - Don't exempt
/apias 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.