Repository navigation
REST API
Checked against v0.6.1 (commit 3b06892) on October 19, 2026.
Kestrel's web app is a FastAPI application (kestrel/web/app.py, build_app). Its JSON endpoints are what the tray, the scripts you write and the MCP server's equivalents share with the UI. Related pages: CLI reference, MCP server.
No endpoint submits an application, sends an email or message, or posts anywhere on your behalf. The routes that start work only queue it: their docstrings say "Queues only" or "Only enqueues" (kestrel/web/routes_control.py), and POST /api/opportunities/ingest reads a page you hand it and never crawls (kestrel/web/routes_api.py).
The server has 25 JSON endpoints (/health and 24 under /api), documented below. Every other route returns HTML for the app's own pages and HTMX fragments and is not a stable API.
The JSON endpoints live in three files: kestrel/web/routes_api.py, kestrel/web/routes_control.py and kestrel/web/routes_learning.py. The HTML routes are in kestrel/web/routes_pages.py and kestrel/web/pages/*.py.
FastAPI's generated documentation is on: /docs (Swagger UI), /redoc and /openapi.json (FastAPI(..., docs_url="/docs") in app.py). The JSON handlers return plain dicts without response models, so the schema describes paths and methods but not response bodies.
The desktop app and kestrel serve run this server on 127.0.0.1. It takes the first free port from 8765 to 8774 and falls back to an OS-assigned port if all ten are taken (kestrel/web/serve.py, PORT_LADDER). The chosen port is written to runtime.json in the data folder:
{"port": 8765, "pid": 12345}uv run kestrel serve --no-open
curl http://127.0.0.1:8765/healthGET /health returns {"status":"ok","service":"kestrel","version":"0.5.0"}. Use it as the readiness check.
There are no accounts, tokens or API keys for a local caller. The server applies two controls for local callers (kestrel/web/app.py):
| Control | Effect |
|---|---|
Host check (TrustedHostMiddleware) |
A request whose Host header is not 127.0.0.1, localhost or [::1] gets 400 Invalid host header. This blocks DNS rebinding. |
| Cross-origin guard | A state-changing request (any method except GET, HEAD and OPTIONS) that carries an Origin header from another site gets 403 {"detail":"cross-origin request refused"}. A request with no Origin and no Sec-Fetch-Site header, such as curl or a script, is treated as non-browser and let through. |
Scripts on the same machine therefore need nothing extra. A script that sets its own Origin header to a non-loopback site will be refused.
- Request bodies are JSON (
Content-Type: application/json).POST /api/opportunities/{opp_id}/overrideandPOST /api/learning/labelalso accept form data. - Errors from the JSON handlers are
{"error": "<message>"}with a 400, 404 or 422 status. The run queue returns{"queued": false, "reason": "..."}. The guards above return{"detail": "..."}. - Pagination on
GET /api/opportunitiesusespageandpage_size(default 50, clamped to 1 to 200). There are no cursors. - Tracks are
employmentandconsulting. Endpoints that depend on a track read?track=, then thekestrel-trackcookie, then fall back to the first enabled track (kestrel/web/deps.py,active_track). - Confidential mode applies. When it is on,
GET /api/opportunitiesandGET /api/opportunities/{opp_id}replace your current employer's name with a placeholder, exactly as the UI does (kestrel/web/redact.py). - IDs are integers. A non-integer id returns FastAPI's standard 422 body. An id too large for SQLite's 64-bit integer returns
404 {"detail":"not found"}from a handler inapp.py.
List the pipeline. Query parameters, all optional:
| Parameter | Meaning |
|---|---|
track |
employment or consulting. |
stage |
A stage such as new, t0_reject, t1_pass, t2_done, t3_done, error, quarantined. The full list is STAGES in kestrel/db/enums.py. |
verdict |
One of apply, pursue, consider, pass, keep, kill. |
score_min, score_max
|
Numeric bounds on the Tier 2 score. |
org |
Case-insensitive substring of the organization name. |
source |
Case-insensitive substring of the source name or kind. |
q |
Case-insensitive substring of title or organization. |
needs_review |
1, true or on to keep only items flagged for review. |
archived |
1, true or on to include hidden items beside active ones. |
hidden |
1, true or on to list only hidden items. |
ghost_min |
Minimum ghost score. |
sort |
score (default), date, first_seen, pre_score or ghost. An unknown value falls back to score. |
page, page_size
|
Page number and size. |
curl "http://127.0.0.1:8765/api/opportunities?track=employment&verdict=apply&page_size=10"{
"total": 1,
"page": 1,
"pages": 1,
"page_size": 10,
"rows": [
{
"id": 1,
"track": "employment",
"title": "Head of IT",
"org": "Example Co",
"source": "Manual capture (employment)",
"stage": "new",
"verdict": null,
"score": null,
"weighted_score": null,
"needs_review": false,
"ghost_score": 0.2,
"pre_score": 0.0,
"url": "https://example.com/j/1"
}
]
}One opportunity with its latest evaluation. Returns id, title, org, track, stage, verdict, verdict_model, score, weighted_score, needs_review, dimensions, blockers, legitimacy, dedup_members (ids of duplicates) and override (your latest override, or null). The evaluation fields are null until the item has been scored. Returns 404 {"error":"not found"} for an unknown id.
Add one posting from a URL and/or the text of a page you are already reading. It enters the pipeline like any scraped posting. It reads only what you give it.
| Body field | Meaning |
|---|---|
url |
Posting URL. |
text |
Readable text of the page. |
title, org_name
|
Optional. The title is guessed from the text or URL if omitted. |
track |
employment (default) or consulting. Anything else becomes employment. |
At least one of url or text is required, otherwise 400 {"error":"provide a url or text"}. An invalid JSON body also returns 400. The response is {"id", "title", "stage", "track"}. Posting a URL that is already stored returns that record's id rather than creating a duplicate (kestrel/ingest/manual.py).
curl -X POST http://127.0.0.1:8765/api/opportunities/ingest \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com/j/1","text":"Head of IT\nLead IT.","org_name":"Example Co"}'Record your own verdict on an item. This writes a label that the learning loop trains on. It does not change anything outside Kestrel.
| Body field | Meaning |
|---|---|
mode |
agree (default), adjust or override. agree records the system verdict and score as yours. adjust keeps the verdict and sets your score. override sets your verdict. |
reason |
Required when mode is override, otherwise 400 override requires a reason. |
operator_verdict |
One of apply, pursue, consider, pass, keep, kill. Anything else is 422. |
operator_score |
Number. A non-numeric value is ignored. |
fit |
A fit word instead of a verdict: strong fit, good fit, maybe or not a fit. Setting it forces mode to override, so reason is then required. An unknown word is 422. |
The response is {"ok": true, "override": {"operator_verdict", "operator_score", "reason", "created_at", "fit_word"}}. An unknown opportunity id returns 404. If the request carries an HX-Request header, the endpoint returns an HTML fragment instead of JSON.
curl -X POST http://127.0.0.1:8765/api/opportunities/1/override \
-H "Content-Type: application/json" \
-d '{"mode":"override","operator_verdict":"pass","reason":"Scope is below director level"}'| Method and path | Purpose |
|---|---|
GET /api/runs |
Run history: {"runs":[{id, name, track, status, started_at, finished_at, counts}]}. |
GET /api/runs/active |
Live pipeline activity: {"tasks": {<type>: {<status>: n}}, "latest_run", "quarantined"}. Task types are t1, t2, embed and scrape. |
GET /api/status |
One payload for the tray and the sidebar: version, paused, mode, pending_mode, loaded_model, activity, worker, model, scan, scan_state, hosted and counts. |
POST /api/run/now |
Queue the next worker cycle in mode (local or hosted, passed as a query parameter, default the saved mode). One-shot. Returns {"queued": true, "mode": ...}. An unknown mode or an unconfigured hosted mode is 400 with a reason. A race with the worker loop is 409. |
POST /api/worker/pause |
Pause the worker. Returns {"paused": true}. |
POST /api/worker/resume |
Resume the worker. Returns {"paused": false}. |
POST /api/scan/now |
Enqueue the due source scrapes. Returns {"enqueued": n}. The worker does the fetching later. |
POST /api/scan/cancel |
Cancel pending scrapes. A scrape already running finishes its current source, and the automatic scheduler holds off for an hour. Returns {"cancelled": n}. |
curl -X POST "http://127.0.0.1:8765/api/run/now?mode=local"
curl -X POST http://127.0.0.1:8765/api/scan/now
curl http://127.0.0.1:8765/api/runs/activeThese endpoints read the track from ?track= or the track cookie. They back the Calibrate page.
| Method and path | Purpose |
|---|---|
GET /api/learning/queue |
The ten most uncertain items to label: {"track", "items":[{opportunity_id, title, score, weighted, verdict, uncertainty, components}]}. |
POST /api/learning/label |
Record a label. Body: opportunity_id (required), score, verdict, rationale, track (default employment), source (default active_learning). Returns {"ok": true, "label_id": n}. 400 without an id, 404 for an unknown opportunity. |
POST /api/learning/calibration/propose |
Compute a weight proposal. Returns {"proposed": false, "reason": "insufficient labeled examples"} when there is too little data, otherwise the proposal with id, n_samples, previous_weights, proposed_weights, cv_mae_previous and cv_mae_proposed. |
POST /api/learning/calibration/{cal_id}/accept |
Apply a proposal. {"accepted": true}, or 404 {"accepted": false}. |
POST /api/learning/calibration/{cal_id}/reject |
Reject a proposal. {"rejected": true}, or 404. |
POST /api/learning/train |
Train the reranker for the track. Returns track, n_labeled, promoted, criteria, metrics, reason. |
GET /api/learning/reranker |
{"active": false}, or {"active": true, "version", "n_samples", "metrics", "sklearn_version"}. |
GET /api/learning/outcomes |
Outcome analysis by score band, with sample sizes. Bands with fewer than five observations are marked "insufficient": true. |
These exist for the tray and the desktop window. Headless kestrel serve has no shell, so they return false.
| Method and path | Purpose |
|---|---|
GET /api/updates/status |
{"available": bool, "version": str or null}. Whether a newer version is worth advertising now. Makes no network call. |
POST /api/quit |
Ask the desktop shell to quit. Returns {"quitting": bool}, false without a shell. |
POST /api/focus |
Ask the desktop shell to raise its window. Returns {"focused": bool}. |
The remaining routes render the app's own pages and HTMX fragments under prefixes such as /settings, /documents, /opportunities, /pursuits and /sources. They return HTML, change between releases and are not an API. Routers are listed in _PAGE_MODULES in kestrel/web/app.py. Three routes under /api/documents/import (/read, the bare path and /accept) return HTML for the resume import dialog. To import a resume from a script, use kestrel doc import (CLI reference).
The browser extension is not supported.
The test suite uses Starlette's TestClient against build_app(worker=False) (tests/test_mcp.py shows the pattern). tests/conftest.py makes the client present itself as a loopback caller with a 127.0.0.1 host, because the Host check refuses the default testserver name. Tests never call a live job board or other external service.
Start here
Interfaces
Extending Kestrel
How it works
- Prompts and context budgets
- Document engine
- Learning loop internals
- Analytics internals
- Task queue and concurrency
- Database schema
Shipping and safety
- Packaging and releases
- Preflight and diagnostics
- Security and privacy model
- Outbound calls
- Benchmarking
Workarounds and Troubleshooting