API¶
The REST API at https://gradient.example.com/api/v1 powers both the web UI and the CLI. Every endpoint, with parameters and responses, appears in the OpenAPI spec.
Authentication¶
All endpoints require a bearer token except /auth/*, /health and /config.
Two ways to obtain a token:
| Token | Source | Form |
|---|---|---|
| Session | POST /auth/basic/login or gradient login |
JWT |
| API key | Settings -> API Keys or POST /user/keys |
GRAD... |
Responses use the envelope { "error": false, "message": <payload> }. Set error to true on failure and place the reason in message.
API Keys¶
- Each key acts with its own permission set. These permissions intersect with the owner's role in each project.
- A key pinned to a project returns
404for every other project. - A key pinned to a cache can operate on that cache only.
- The
allowed_ipsfield can limit a key to a list of CIDR blocks. Requests from other sources receive403 forbidden_source_ip. - The server reads
X-Forwarded-Foronly from proxies listed inhttp.trustedProxies. - API keys cannot create, edit or delete other API keys. Only a session can do this.
- No key can exceed the permissions of its owner. A key pinned to a project can only grant permissions the owner holds in that project.
- Every project key includes
viewProject. createProjectis valid only on a key without a pin. A key with it can callPUT /projectswhen its owner can create projects.- Add
openJobTerminalto the key to use shell, console and port forwarding for exec jobs. A key with onlyviewProjectandtriggerEvaluationcannot open shell, console or port forwarding. GET /user/keys/{id}/reachlists the projects and caches a key can reach, with its permissions on each.- Use
POST /user/keys/{id}/regenerateto assign a new secret to the key. The name, permissions, pins and expiry stay the same. Requests that use the old secret fail from that moment. The response can return the new key one time only. - 401 and 403 responses to signed-in callers list the missing permissions in
missing_permissions(for example,["readStore"]). Add these names to the key'spermissionsto allow the request.
curl -X POST https://gradient.example.com/api/v1/user/keys \
-H "Authorization: Bearer $SESSION" -H "Content-Type: application/json" \
-d '{ "name": "ci", "permissions": ["viewProject", "triggerEvaluation"], "project": "acme", "expires_in_days": 90 }'
Examples¶
Create endpoints return the new UUID in message.id, its name in message.name and its web page in message.url. Starting an evaluation returns the evaluation UUID in message.id.
The task page, the evaluation menu and the build log menu each have a Copy menu. It copies the matching CLI command, API URL or page link.
curl -X POST https://gradient.example.com/api/v1/tasks/acme/web-app/evaluate \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{ "commit": "9c1a2b3c...", "attr": "packages.x86_64-linux.web-app" }'
To find the store path of a single attribute at a single commit, for example when preparing a deployment tool, run two requests. The first request locate the evaluation, the second fetch its entry point.
curl -G https://gradient.example.com/api/v1/tasks/acme/web-app/evaluations \
-H "Authorization: Bearer $TOKEN" \
--data-urlencode "commit=9c1a2b3c..." --data-urlencode "attr=packages.x86_64-linux.web-app"
curl -G https://gradient.example.com/api/v1/tasks/acme/web-app/entry-points \
-H "Authorization: Bearer $TOKEN" --data-urlencode "evaluation_id=$EVAL_ID"
Once the evaluation has resolved the attribute, the entry point carry outputs.out. The build_status field indicate whether the path has been built and cached.
Closure data live at /builds/{build}/closure and /runtime-closure, and at the same paths under /evals. A response contain the fields roots, total_size_bytes (always exact), truncated, nodes (id, name, path, nar_size) and edges (source, target). In each edge, the target depend on the source. The closure view draw this data as a graph.
GET /api/v1/builds/{build}/log returns the build log. Pass format=plain to remove color codes or format=ansi to keep them. Requests with Accept: text/plain get plain text by default.
Live Updates¶
Each path below upgrades to a WebSocket. On every resource change, the server pushes one event envelope per frame.
| Path | Events |
|---|---|
/tasks/{project}/{task}/live |
evaluation.<phase>, evaluation.progress, evaluation.activity and build.status_changed for the task's evaluations |
/evals/{evaluation}/live |
The same set, scoped to one evaluation |
/builds/{build}/live |
evaluation.<phase>, evaluation.progress and build.status_changed for the build's evaluation, plus build.progress with the phase, bytes and paths of the build's transfers |
/board/live |
worker.queue_depth, worker.job_dispatched, worker.connected and worker.disconnected, restricted to superusers |
/board/cache/live |
board.cache with the full cache statistics and upstream caches, at most one frame per 2 seconds and only after a change |
Binary Cache¶
The cache endpoints sit at the host root and carry no /api/v1 prefix. Private caches require Basic authentication over HTTP. The username can be anything. Use a session or an API key with cache scope as the password. See netrc for one way to pass credentials. API keys can't create caches and can't use team endpoints.
| Method | Path | Description |
|---|---|---|
GET |
/cache/{cache}/nix-cache-info |
Cache metadata for Nix |
GET |
/cache/{cache}/{hash}.narinfo |
Path info. X-Cache: HIT means the response came from this cache, MISS from an upstream cache |
GET |
/cache/{cache}/nar/{hash}.nar.zst |
NAR archive |
GET |
/cache/{cache}/log/{drv} |
Build log, used by nix log |
GET |
/cache/{cache}/debuginfo/{build_id} |
Debug info for nixseparatedebuginfod, dwarffs and gdb |
GET |
/cache/{cache}/ls/{hash} |
File listing of a NAR |
GET |
/cache/{cache}/serve/{hash}/{path} |
A single file from a NAR, or a whole directory as tar.zst |
- A request for an unknown key answers with
404, and Nix then tries the next substituter. - Requests for an HTML page get a
302to the web frontend at the cache root, together withnix-cache-info,gradient-cache-info,{hash}.narinfo, andls/{hash}. Clicks on store path links in the terminal open the page for that path. Thefrontend.redirectBrowserRequestsToFrontendPagesoption can disable redirects. loganddebuginfofall back to upstream caches for substituted paths.- Every client IP can make 1000
narinfoand NAR requests per second, after a burst of 20000. The optionshttp.cacheRequestsPerSecondandhttp.cacheRequestBurstcan raise both limits. - Requests over a limit receive
429. Clients behind one proxy share a single limit unless the proxy is inhttp.trustedProxies. ls,serveandloghave a rate limit that refills at one request per 333 ms, about 180 per minute.- The burst allowance is 180 for
lsandserve, and 900 forlog.