Authentication
A program authenticates with an API key, sent as a bearer token: the recommended credential, and the one every example in this reference uses. A key belongs to one workspace and holds the scopes you gave it; it does not end when a browser session ends. Three other credentials exist beside it, each for its own kind of caller.
Status. Written on 2026-11-14 from the token calls as they run on this service; the credential table and the read rule for self-inspection were corrected on 2026-11-16.
Credentials
| Credential | For | How it is sent | What it may do |
|---|---|---|---|
API key, weights_… | Programs, scripts and agents | Authorization: Bearer $WEIGHTS_API_KEY | The key's own scopes, in its one workspace. A key issued by a person with the member role acts with read and submit at most. |
| OIDC bearer token | A service that signs in through this deployment's identity issuer, where one is configured | Authorization: Bearer <token> | What the issuer's token maps to here. Without a configured issuer, a bearer that is not an API key answers 401 invalid_token. |
| Browser session | A person signed in to the panel | The session cookie; every call that changes something also needs X-CSRF-Token, else 403 csrf_required | The person's role in the selected workspace: owners and admins every scope, members read and submit. |
| Worker credentials | A computer you enrolled to serve your own model (Bring your own model) | A single-use wjt_ join token once, then the worker's own key and short-lived certificate | Enroll, renew its certificate and serve calls. They open none of the calls in this reference, and an API key cannot stand in for them. |
Bearer tokens
Authorization: Bearer $WEIGHTS_API_KEYMake a key on your panel under API tokens, or from code with a manage key (POST /v1/tokens). The key is shown once, in that answer only; lists show its prefix. A call without a working credential is refused:
| Status | Code | Meaning |
|---|---|---|
401 | unauthorized | No Authorization header; the answer carries WWW-Authenticate: Bearer. |
401 | invalid_token | The header holds no key of this service. |
401 | token_revoked, token_expired | The key was revoked, or its expires_at has passed. |
403 | scope_required | The key lacks the call's scope; required and granted say which. |
403 | workspace_role_required | The call also needs a role in the workspace that the key's issuer does not hold, as the owner for POST /v1/credit/topups. |
403 | account_suspended | The account is suspended. |
Scopes
Each call needs one scope, named on its reference page and as x-required-scope in /openapi.json. A few calls check the issuer's role in the workspace as well; their pages say so.
| Scope | Lets the key |
|---|---|
read | Read models, quotes, jobs, results, logs, usage, exports, datasets, plans and endpoints, and check itself with GET /v1/tokens/self. |
submit | Send work: classify, batches, datasets, training jobs, compute plans and packs, LLM endpoints and chat; cancel a job; make the model ready. |
manage | Make, list and revoke keys; trace destinations and content logging; register a workspace; rename an endpoint; open a prepaid payment page (the workspace owner's keys only). |
A new key gets submit and read unless you ask for other scopes, and a key can only make keys with scopes it holds itself (403 scope_escalation). Give each program the narrowest key it needs: a batch runner needs submit and read, a dashboard read alone.
Workspaces
A key belongs to the workspace it was made in, and everything it reads or makes is that workspace's: its jobs, datasets, endpoints, usage and credit. An id of another workspace answers 404, so a key cannot learn what other workspaces hold. Switching workspace in the browser does not move a key. Removing a person from a workspace, or changing their role, revokes the keys they issued there and the keys made from those keys. GET /v1/workspaces answers the key's own workspace.
Check a key
A key that holds read can read itself: its scopes, expiry, spend cap, request rate and workspace. A key with only submit or manage answers 403 scope_required here, so give a program that must identify itself the read scope.
curl -s https://weights.fyi/run/v1/tokens/self -H "Authorization: Bearer $WEIGHTS_API_KEY"{
"token": {
"id": 2,
"name": "batch runner",
"scopes": ["submit", "read"],
"expires_at": null,
"revoked_at": null,
"daily_cap_usd_micros": 25000000,
"rate_limit": {"requests_per_second": 1.3125, "burst": 28}
},
"account": {"id": 7}
}Rotate a key
- Make the new key with the same scopes, expiry and spend cap (POST /v1/tokens), or on your panel.
- Put it where your program reads
WEIGHTS_API_KEY, and restart or reload the program. - Confirm the program uses it: the old key's
last_used_aton GET /v1/tokens stops moving. - Revoke the old key (DELETE /v1/tokens/{token_id}). Revoking is final: the key answers
401 token_revokedfrom then on.
curl -s https://weights.fyi/run/v1/tokens \
-H "Authorization: Bearer $WEIGHTS_API_KEY" -H "Content-Type: application/json" \
-d '{"name": "batch runner 2026-11", "scopes": ["submit", "read"], "daily_cap_usd": "25"}'
curl -s -X DELETE https://weights.fyi/run/v1/tokens/OLD_TOKEN_ID -H "Authorization: Bearer $WEIGHTS_API_KEY"Making a key takes no Idempotency-Key: a retry after a lost answer makes a second key, so revoke the one you do not keep.
Keep keys out of code
Load the key from the environment or your secret store, never from source code, a URL or a log line:
export WEIGHTS_API_KEY="$(cat ~/.config/weights/api-key)" # or read it from your secret storeimport os
key = os.environ["WEIGHTS_API_KEY"] # a KeyError when it is missing, not a call without a keyconst key = process.env.WEIGHTS_API_KEY;
if (!key) throw new Error("WEIGHTS_API_KEY is not set");Keep .env files out of version control. If a key leaks, revoke it at once and make a new one.