Backend API reference
The backend is a FastAPI app. All routes are mounted under the /api prefix in backend/app/main.py and grouped into 22 routers (one file each under backend/app/api/routes/), plus three health checks defined directly in main.py. Interactive OpenAPI docs are always available at /docs (and /redoc) on a running backend.
The auth model
Almost every endpoint requires an AdjustSquare JWT. The token arrives either as an Authorization: Bearer <jwt> header or as the bt_shared_data cookie. Three FastAPI dependencies wrap this:
| Dependency | Returns | Used when |
|---|---|---|
get_current_user | the User ORM row (auto-provisioned) | the route needs the full user or team |
get_actor | a lightweight Actor(user_id, user_name, team_id, is_admin, permissions, visible_team_ids), with the caller's effective access-profile permissions | the route writes an activity-log entry or checks a permission |
require_admin | the User ORM row, only if on the admin allowlist | the route is part of the internal admin dashboard (/api/admin/...) |
get_actor depends on get_current_user, so both resolve the same token once per request. Team scoping is enforced in the route: reads and writes check that the target claim's team_id matches the caller's, returning 403 on mismatch and 404 when the record does not exist. See authentication for the validation flow.
Some job, room, and inventory read endpoints resolve by id without a team check (they are reached only after a team-scoped claim load in the UI). Treat the claim-level checks as the security boundary. This is noted per group below.
GET /api/training/certificates/{code} (read-only certificate verification) and the whole of /api/public/insured/... (the insured's own inventory link) take no JWT at all. The second is the only public write surface in the app, and its rules are different: an unguessable token whose hash alone is stored, one claim per token, per-token rate limits, per-file and per-link size ceilings, and a deliberate rule that it never answers 401 (the frontend session guard logs a user out on any 401 from /api/*, and a homeowner has no account to log back into). Read Insured inventory link and the module docstring in routes/insured_public.py before adding anything under /api/public/.
A few machine-to-machine endpoints also skip the JWT but authenticate another way: the ContentsCapture webhook (per-delivery HMAC) and provisioning call (shared secret), the Mailgun webhook (HMAC), and the browser telemetry passthrough (accepts anything, forwards only to the configured collector).
auth
| Method & path | Purpose | Auth |
|---|---|---|
GET /api/auth/me | Return the current user and team, including is_admin, the user's timezone preference, permissions / access_profile / access_profile_name (effective access profile), and features (the team's resolved component visibility, e.g. {"training": true}); logs a login event whenever it is called with a bearer token (the callback exchange, and the session refresh on every page load). | get_current_user |
PUT /api/auth/me | Update the caller's display preferences. Currently {timezone}: an IANA zone name validated against the zoneinfo database, or "" for browser-local time. Returns the refreshed /auth/me payload. | get_current_user |
POST /api/auth/logout | Record a logout activity event. | get_actor |
GET /api/auth/access | The signed-in person's product access and nothing else: {product_access} (null when nothing applies). The browser asks it once a minute. Writes no activity row. | get_current_user |
GET /api/auth/config | Public: returns the AdjustSquare login URL so the frontend can redirect. | none |
GET /api/auth/debug | Debug view of the signed-in identity: resolved user and team, raw JWT claims when a token is present, auth mode (local bypass vs JWT), and Adjust Square readiness (base URL set + a team/fallback token). The team token is masked, never returned in full. | get_current_user |
sso
| Method & path | Purpose | Auth |
|---|---|---|
GET /api/sso/contents-estimation/authorize | Mint a short-lived login token for the signed-in user and return {redirect_url}: the Contents Estimation callback with the token attached, so the Integrations card opens CE already signed in. 503 when the hand-off is unconfigured, 409 for a user with no Contents Estimation id. See the hand-off. | get_current_user Optional ?next=contentscapture (the product switcher) adds next to that link, so CE's landing page carries on to the ContentsCapture admin console with its own console sign-in. |
claims
| Method & path | Purpose | Auth & scope |
|---|---|---|
POST /api/claims | Create a claim for the caller's team. Writes activity. | get_actor |
GET /api/contents-estimation/claims | The caller's team's open claims on Contents Estimation (?q= free text), each with its details in our vocabulary and contentsvision_claim_id when this team already has it. available: false when the team or instance cannot ask. For the Dashboard's Import from ContentsEstimation. See importing. | get_actor, team key |
POST /api/contents-estimation/claims/import | Create a claim linked to one of the team's Contents Estimation claims (ClaimCreate + claim_key); its sends append to that claim. Only the claim and its rooms are copied, not its items; item numbers here continue after its highest one. Returns {claim, created}; created: false returns the team's existing copy. 404 when the key is not one of the team's open claims there. Writes activity. | get_actor, team key |
POST /api/claims/{id}/contents-estimation-refresh | On a claim linked to Contents Estimation, add any of its rooms this claim lacks and raise contents_estimation_item_offset to its highest item number. Best effort: always returns the claim (ClaimResponse), unchanged when it is not linked or Contents Estimation cannot be reached. Called by the import picker before opening a claim already imported. | get_actor, 403 on other team |
GET /api/claims | List the claims the caller can see (their team's, plus their organization's with claims.view_org) with per-claim spend, status, assigned_to_user_id / assigned_to_name and tags. Active claims by default; ?archived=true lists the archived ones; ?assigned_to=me (or a user id) narrows to that person's assignments. | get_actor, scoped to visible teams |
GET /api/claims/{id} | Get one claim with spend and status. | get_current_user, 403 on other team |
POST /api/claims/status | Set the status of one or more claims by hand: {claim_ids, status, note}, where status is one of ALL_STATUSES or "auto" (hand back to the computed status). The note is optional (max 2000). All claims must exist (404) and be the actor's team (403), or nothing changes. Writes one claim_status_changes row per changed claim and an activity entry, and returns the updated claims as ClaimListItems. | get_actor, team-scoped |
GET /api/claims/{id}/capture-arrivals | ContentsCapture media on its way into this claim, still waiting for its room to settle before it imports (automatic processing): {arrivals: [{assignment_id, location_id, claim_id, room_id, room_name, photos, videos, audios, settles_at}], settle_seconds}, settles_at in UTC with a Z. Drives the countdown notice on the claim page. | get_actor, 403 on other team |
GET /api/claims/{id}/status-history | Every hand-made status change on the claim, newest first: {id, created_at, from_status, to_status, note, user_name}. to_status is "" for a hand-back to automatic. | get_actor, 403 on other team |
PATCH /api/claims/{id} | Inline-edit claim fields. Writes activity. | get_actor, 403 on other team |
POST /api/claims/{id}/archive | Archive a claim (soft-hide; sets is_archived + archived_at). Reversible and non-destructive. 400 if the claim has been submitted (submitted_at set). Writes activity. | get_actor, 403 on other team |
POST /api/claims/{id}/unarchive | Restore an archived claim (clears archived_at). Writes activity. | get_actor, 403 on other team |
DELETE /api/claims/{id} | Internal/admin hard delete of a claim and everything beneath it (rooms, jobs, items, item/staged photos, files on disk). No longer exposed in the UI: archiving is the only user-facing removal, and the 30-day purge is the only deletion. The endpoint remains for the purge/admin use. | require_admin (allowlist {7, 10}), not team-scoped |
GET /api/claims/{id}/adjust-square-profiles | The team's shopping + depreciation profiles for the submit modal. | get_current_user, 403 on other team |
POST /api/claims/{id}/adjust-square-quote | Credit cost to submit the selected rooms (1 credit per item that would be sent) plus the team's balance, for the consent step. Charges nothing; training claims and enterprise teams are free. | get_actor, 403 on other team |
POST /api/claims/{id}/submit-to-adjust-square | Submit selected rooms' items to Adjust Square. Records a Submission row (date, item/photo counts, claim key, end-to-end processing time; status flips from processing to complete when the background item/photo work finishes). | get_actor + get_current_user, 403/409 |
GET /api/claims/{id}/photo-upload-status | How many submitted items have their photo on Adjust Square and how many are pending. Drives the "N photos still uploading" banner. | get_actor, 403 on other team |
POST /api/claims/{id}/retry-photo-uploads | Re-upload every submitted item photo not yet on Adjust Square, in the background (each item is checked against the portal first, so nothing is duplicated). Returns the count started; poll photo-upload-status. | get_actor, 403 on other team |
GET /api/claims/{id}/contents-estimation-profiles | The claim's team's Contents Estimation depreciation schedules with their shopping profiles nested, for the send modal's two dropdowns. Empty list (not an error) when the team has no key. | get_actor, 403 on other team |
GET /api/claims/{id}/contents-estimation-items | Every active item with whether it has been sent, for the send modal's tick list (sent items included). | get_actor, 403 on other team |
GET /api/claims/{id}/contents-estimation-quote | Exact credit cost to send the claim's unsent items plus the team's balance. Charges nothing; items already sent are free. | get_actor, 403 on other team |
POST /api/claims/{id}/submit-to-contents-estimation | Send the unsent items to Contents Estimation: append to the linked claim, append to target_claim_key (and link it), or create a new claim there. See what sending does. | get_actor, 403 on other team |
POST /api/claims/{id}/contents-estimation-item-lock | Re-open (or re-close) a sent claim's items for editing, for a claim sent by mistake. See the admin unlock. | require_admin |
GET /api/claims/{id}/unprocessed-media | Every upload in the claim's live rooms that has not produced items yet, as {items: [{job_id, room_id, room_name, filename, source_type, status, state, created_at}], processed_count}. state is needs_start (video/audio waiting on the go-ahead), needs_grouping (photos), processing or failed. processed_count is how many uploads in the same live rooms are complete (the Added by hand job, origin="manual", is not media and is left out); both are counted per upload (job), not per photo. The claim page calls it before either send and before the claim's .xlsx export, and shows the unprocessed-media warning when items is non-empty. It also drives the Processed / Unprocessed media counters in the Claim Details card and the yellow per-room flags on the room cards and list. | get_actor, 403 on other team |
GET /api/claims/{id}/duplicate-suggestions | Items anywhere on the claim (any live room) that look like the same kind of thing, as {groups: [{key, items: [{id, item_name, item_number, quantity, room_id, room_name, photo_path, brand, condition, notes}]}]}. Rule based, no AI (services/claim_duplicates.py): names match after lowercasing, dropping punctuation and filler words, folding simple plurals and ignoring word order; differing brand/model numbers are kept apart. Archived items, archived rooms and items already sent (submitted or contents_estimation_sent_at) are left out. The claim page calls it after the unprocessed-media check, before a ContentsEstimation send; merging uses POST /api/inventory/items/merge with the summed quantity. key is stable for the same item set, and "Not duplicates" is remembered per claim in the browser's localStorage. The dialog can merge only ticked items of a group (several merges per group); when a split group is down to one undecided item, continuing remembers the key of what remains (the merged survivors plus the leftover, <name key>#<sorted ids>) the same way, so the next send does not ask about it again. The dialog's Undo (and Ctrl+Z) reverses merges, item edits, room moves and photo removals through POST /api/activity/{id}/restore, using the X-Activity-Id header those endpoints return; a removed item is restored with /unarchive. | get_actor, 404/403 on other team |
GET /api/claims/{id}/submissions | The claim's submission history, newest first, plus total_items / unsubmitted_items (the UI disables Send for Estimation when everything is submitted). | get_actor, team-scoped with the admin exception |
Claim status (status on claim responses) is computed on read by services/claim_status.py (computed_status_map), never stored. The first rule that applies wins: needs_attention (an upload in a live room is error, awaiting_grouping, or awaiting_confirmation), capturing (the claim is fed by a ContentsCapture assignment that is still open there: claims.capture_assignment_status is draft or active), processing (an upload in a live room is in any other non-complete state), sent_to_contents_estimation (at least one item has contents_estimation_sent_at), in_review (live items, at least one approved or reviewed, i.e. edited by hand), ready_for_review (live items, none touched), awaiting_media (no live items). ALL_STATUSES lists them in workflow order; MANUAL_STATUSES is the same list without capturing, which is reported by Capture and never picked by hand (POST /api/claims/status answers 422 for it). A status picked by hand is layered on top in attach_status. A person can override it by hand (POST /api/claims/status): the choice is stored on the claim (manual_status, manual_status_note, manual_status_by, manual_status_at) together with manual_status_basis, the computed status at that moment. attach_status shows the hand choice only while the computed status still equals the basis; once the claim moves on by itself (new items, a failed upload, a send) the override is cleared on read and saved. Responses carry status (what to show), auto_status (computed) and the manual_status* fields.
Claim source (source on claim list and detail responses, services/claim_source.py) is where the claim came from: upload (New Claim, the default), contents_capture (made by a ContentsCapture import, or any claim a Capture import has landed media in since), contents_estimation (POST /api/contents-estimation/claims/import) or training. It is stored on the claim and stamped where each kind is created; the Dashboard shows it in the Source column. Responses also carry capture_assignment_status, the raw Capture assignment status behind the claim ("" when not fed by Capture).
The submit endpoint is the most complex in the system: it authenticates to Adjust Square as the user's team, creates or updates the remote claim, and spawns background tasks for photo upload and AI triggering. It returns 409 if the team has no Adjust Square token. Archived rooms and archived items are excluded from the submission payload. Full detail in the Adjust Square integration.
configuration, access, views, tags, assignment
Three routers: config_settings.py, access.py and views.py (which also carries tags and assignment). The hierarchy config API (/api/config/..., /api/hierarchy, /api/orgs, /api/business-units, /api/teams/{id}/placement), access profiles (/api/access/...), saved views and pins (/api/views...), tags (/api/tags, POST /api/claims/tags) and assignment (GET /api/claims/assignable-users, POST /api/claims/assign, GET /api/claims/{id}/assignment-history) are listed with their rules in configuration and access.
rooms
| Method & path | Purpose | Auth & scope |
|---|---|---|
POST /api/claims/{claim_id}/rooms | Add a room to a claim. Writes activity. | get_actor, 403 on other team |
GET /api/claims/{claim_id}/rooms | List rooms with media and item counts (video/photo/audio/items/submitted), in the claim's room order (sort_order, then newest first). Active rooms by default; ?archived=true lists archived ones. Item counts exclude archived items. Each room also carries its room cover: cover_photos (URLs of its first four scoping photos, fewer when it has fewer, [] when it has none) and room_media_count (scoping photos plus scoping videos). The covers for every room come from two queries in all (room_media.covers_for_rooms), not one per room. | get_current_user, 403 on other team |
PUT /api/claims/{claim_id}/rooms/order | Save the room order from the Reorder rooms dialog. Body {room_ids} (active rooms, top to bottom); every room on the claim is renumbered, unlisted active rooms after the listed ones and archived rooms last. 400 for an id not on the claim. Returns the active rooms in order. Writes activity. | get_actor, 403 on other team |
GET /api/rooms/{room_id} | Get a room with submitted/unsubmitted counts, plus cover_photos and room_media_count (as on the room list). The rename and archive responses carry them too. | none (by id) |
GET /api/rooms/{room_id}/room-media | The room's scoping photos and videos, for its Room photos tab: {room_id, photo_count, video_count, media: [{id, kind: "photo" or "video", url, job_id, filename, duration_seconds, captured_at, captured_by_id, captured_by_name}]}. Photos first, then videos, each oldest upload first and in capture order. url is /api/photos/{job_id}/{filename} for a photo and /api/jobs/{job_id}/video for a video. captured_at and captured_by_id come from the matching uploads.meta (capturedAt, capturedBy); captured_by_name is blank unless that ContentsCapture user also submitted a room on the claim, see Room photos. An ordinary room returns an empty list. | get_actor, 404 on other team (load_room_for_team) |
POST /api/rooms/{room_id}/archive | Archive a room (sets is_archived + archived_at). 400 if the room contains any submitted item. Reversible. Writes activity. | get_actor, 403 on other team (via parent claim) |
POST /api/rooms/{room_id}/unarchive | Restore an archived room (clears archived_at). Writes activity. | get_actor, 403 on other team |
PUT /api/rooms/{room_id} | Rename a room. Writes a non-restorable rename_room activity entry. | get_actor, 403 on other team (checked via the owning claim) |
GET /api/rooms/{room_id}/jobs | List a room's jobs with live item counts (current_item_count excludes archived items, so it tracks deletes and merges; items_found is the snapshot from processing). | none (by id) |
upload
All upload endpoints create a job and write a (non-restorable) activity entry.
| Method & path | Purpose | Behavior |
|---|---|---|
POST /api/upload | Upload a video to a room. | Streams to disk (size-capped), creates a job, starts the video pipeline in the background. |
POST /api/claims/{id}/import-contents-list | Import one or more vendor contents-list PDFs onto a CLAIM, split across rooms. | Parks the files and returns an ImportBatch immediately; the read runs in the background, creating one room and one awaiting_grouping photo job per room the document names. Poll GET /api/integrations/imports/{batch_id} for progress. PDFs only. See PDF import. |
POST /api/upload-photos | Upload the first batch of photos to a room, plus any PDFs. | Normalizes each photo to JPEG, seeds one StagedPhoto per file, leaves the job in awaiting_grouping. Does not auto-start AI. Also accepts .pdf: the job is created at importing_pdf instead and the worker (run_pdf_import, a background task without REDIS_URL) reads the item photos out of the document (see PDF import). Optional photo_count_hint form field is the total number of loose photos in the whole selection, so the PDF's group indices can be taken past the range the appends will claim. |
POST /api/upload-photos/{id}/append | Add more photos to an existing photo job. | Continues the orig_####.jpg numbering and group indices, adds more StagedPhoto rows, and updates total_frames / file_size_bytes. Only while the job is awaiting_grouping or importing_pdf. Refuses PDFs (400): a PDF yields an unknown number of photos, so it cannot fit the client-assigned index range this endpoint relies on, and the frontend sends every PDF with the first request. |
POST /api/upload-audio | Upload an audio file to a room. | Streams to disk, creates a job, starts the audio pipeline in the background. |
Each takes room_id as form data and the file(s) as multipart, validates the extension, and enforces its size cap (returns 413 if exceeded): MAX_UPLOAD_SIZE_MB for video/audio, MAX_PHOTO_UPLOAD_MB (running total across the whole job) for photos. Auth: get_actor.
Batched photo upload
Production traffic runs through a Cloudflare Tunnel that caps a single request body at roughly 100MB, so the frontend never sends a whole photo selection in one request. It greedy-fills the files into batches up to an 80MB budget (headroom for multipart boundaries and the encoded body), sends the first batch to POST /api/upload-photos, then sends each remaining batch to POST /api/upload-photos/{id}/append. The result is one room equals one job with one grouping pile, just delivered over several requests. The append endpoint rejects anything but an awaiting_grouping or importing_pdf photo job (409/400), and MAX_PHOTO_UPLOAD_MB is enforced as a running total across the whole job, not per request. A single photo over the 100MB hard limit is caught in the browser up front with a clear message, since it can never succeed batched or not.
Parallelism (speed). Two things make a large (hundreds of photos) upload fast rather than crawl:
- Parallel batches. Batch 0 creates the job and must land first; every remaining batch is an append and the client uploads up to 4 at a time (
PHOTO_UPLOAD_CONCURRENCYinlib/api.ts). To keep parallel appends from racing on theorig_####numbering, the client assigns each batch astart_index(its non-overlapping slice of the ordered selection) and the server writesorig_{start_index+i}.jpg. A skipped (unreadable) file just leaves a gap in the index range, which grouping tolerates. The job'stotal_frames/file_size_bytesare bumped with an atomic in-DB increment so concurrent appends can't clobber each other's counts. Clients that omitstart_indexfall back to appending after the current row count (serial-only). - Reply first, re-encode after. The request only moves bytes: each photo is streamed to disk exactly as it arrived (1 MB reads, never the whole batch in memory), its header is checked with Pillow to confirm it is an image (milliseconds, no decode;
looks_like_imageinservices/image_encode.py), and the response goes out. Normalising each file to an upright RGB JPEG runs afterwards as a FastAPI background task (reencode_photos_in_background, a few files at a time on the thread pool, replacing each file atomically under its finalorig_####.jpgname). Until that runs the file is the upload as sent, which the browser, imgproxy, the pipeline (_prepare_image_for_model) and the Segment endpoint all open upright themselves, so nothing waits on it. The size ceiling is enforced on the running byte total as the files land, and a batch that trips it is removed from disk before the413goes out.
Both endpoints return skipped_photos (the unreadable files they dropped); the frontend aggregates it across every batch and shows it in the uploader's "files skipped" notice, and also renders live per-photo tiles (queued → uploading → done/skipped) plus elapsed time and a byte-rate ETA.
Chunked, resumable uploads
The single-shot POST /api/upload (and /api/upload-audio) sends the whole file in one request, which fails when a CDN or tunnel caps the request body (Cloudflare's tunnel rejects bodies over ~100 MB on Free/Pro, well below the app's 2 GB). The chunked endpoints split a large file into small parts so each request stays under that cap, while the app still accepts the full size. The frontend uses these by default for video and audio (uploadVideo/uploadAudio in lib/api.ts); the one-shot endpoints remain for compatibility.
| Method & path | Purpose |
|---|---|
POST /api/uploads/init | Open a session. JSON body { kind: "video"|"audio", filename, room_id, total_size }. Validates the room and extension up front and returns { upload_id, chunk_size, received }. |
PUT /api/uploads/{id}/chunks/{index} | Store one chunk (raw body). Idempotent: re-sending an index overwrites it, which makes retries safe. |
GET /api/uploads/{id} | Report received chunk indices so a client can resume by sending only the missing ones. |
POST /api/uploads/{id}/complete | Join the chunks in order into the final file and hand it to the pipeline, exactly like a one-shot upload. Returns the Job. |
DELETE /api/uploads/{id} | Abort and discard the partial upload. |
Auth: get_actor on every endpoint. Chunks are written to a per-upload scratch dir (uploads/.chunks/{id}/) with an atomic rename per part, so a crash mid-write never leaves a half-written part. complete verifies the parts form a gap-free 0..n-1 run and (if total_size was given) that the assembled size matches, returning 400 otherwise. Per-chunk size is hard-capped (MAX_CHUNK_BYTES, 32 MB) and the total still honours MAX_UPLOAD_SIZE_MB. The upload_id is validated as a UUID, so it cannot traverse the filesystem.
Speed. init recommends 16 MB chunks (RECOMMENDED_CHUNK_BYTES), and the browser keeps four in flight at once (UPLOAD_CHUNK_CONCURRENCY in lib/uploadChunks.mjs, shared with the insured link's uploader). One chunk at a time moved at the speed of a single connection and paid a full round trip (browser, Cloudflare, tunnel, server and back) per chunk, which on a high-latency link left most of the upstream idle. Each chunk goes up over XMLHttpRequest, whose upload progress events let the bar move as bytes leave the browser rather than in whole-chunk jumps. The chunk planning and retry policy (planChunks, uploadPercent, runWithConcurrency, sendChunkWithRetry: three attempts on a network drop, timeout, rate limit, or 5xx, never on another 4xx) are pure and unit-tested with node --test, and shared with the insured link's uploader so the two paths cannot drift. Because chunks arrive in any order, the per-chunk running-total check in put_chunk is approximate under parallelism; the real guards are init (rejects total_size over the cap) and complete (rejects an assembled size that differs from total_size).
complete joins the parts through services/chunk_assembly.py on the thread pool: a single part is renamed into place (no copy) and several are streamed together with an 8 MB buffer. The old code copied 1 MB at a time through aiofiles (two thousand thread hops for a 1 GB video).
jobs
The jobs router carries job reads, media serving, photo staging, and the progress stream.
| Method & path | Purpose |
|---|---|
GET /api/jobs | List the 50 most recent jobs. |
GET /api/jobs/{id} | Get one job. |
GET /api/jobs/{id}/video | Stream the original video (HTTP range support for seeking). |
GET /api/jobs/{id}/audio | Stream the original audio (range support). |
GET /api/jobs/{id}/frames | List extracted frame URLs. |
GET /api/jobs/{id}/frames/{name} | Serve one frame image. |
GET /api/jobs/{id}/photos | List uploaded source photo URLs. |
GET /api/jobs/{id}/staged-photos | List staged photos with their groupings. Each photo includes its original_filename (the real upload name behind the synthetic orig_####.jpg) and captured_at (EXIF date taken), which the grouping UI's "Sort by name" / "Sort by date" use. POST /upload-photos and .../append accept an optional captured_ats form field (JSON array of dates aligned to files). For a PDF import each photo also carries source_description (the note printed beside it in the document, passed to the AI as a hint), source_item_key (its printed label) and source_room (the room heading it was printed under). For a ContentsCapture import each photo also carries intent (items, or scoping for a room photo that is never itemized and costs nothing) and marks (JSON text of what the specialist drew on it, blank for none). |
PUT /api/jobs/{id}/staged-photos/regroup | Replace all group assignments (enforces MAX_PHOTOS_PER_ITEM; leaves manual segments untouched). |
PUT /api/jobs/{id}/staged-photos/delete | Soft-delete staged photos. |
PUT /api/jobs/{id}/staged-photos/restore | Restore soft-deleted staged photos. |
PUT /api/jobs/{id}/staged-photos/segment | Crop user-drawn boxes from one photo into known items (AS-705); hides the original. Each item has a name (blank = AI names it), a quantity, and one or more boxes. |
PUT /api/jobs/{id}/staged-photos/clear-segments | Remove a photo's segment crops and restore the original whole photo. |
PUT /api/jobs/{id}/staged-photos/details | Set a user-written name + quantity for one item (its staged-photo ids). A non-empty name marks it user-described, so the AI is skipped and it costs no credit; an empty name hands it back to the AI. |
POST /api/rooms/{room_id}/upload-quote | Price a batch of videos / audio files BEFORE upload. Body {files: [{name, kind, duration_seconds}]} with lengths read by the browser; returns {billing_enabled, files: [{name, kind, credits}], total, credits_balance, sufficient, buy_credits_url}. Same block rounding as the job quote; charges nothing. Training claims and billing-off instances report billing_enabled: false. |
GET /api/jobs/{id}/quote | Exact credit cost to process the job plus the team's balance, for the confirmation modal (charges nothing). Scoping photos are not counted, and a scoping video quotes 0. |
POST /api/jobs/{id}/process | Confirm and start processing an uploaded job (photo after grouping, or video/audio after the credit confirmation). Spends the credits up front (402 if short), then starts the matching pipeline. Accepts awaiting_grouping / awaiting_confirmation / error. The logic lives in services/job_start.py:start_job_processing, shared with ContentsCapture automatic processing. |
GET /api/jobs/{id}/read-the-rest/quote | Cost of another AI pass over the photos in a finished job whose answer ran out of room: one credit per photo re-read, plus groups (how many that is) and the team's balance. Charges nothing. Priced per pass, never per item: we know only THAT items remain. |
POST /api/jobs/{id}/read-the-rest | Run that extra pass. Photo jobs in complete only, and only while a group has a pass left (photo_max_passes, 3, counting the pipeline's own call). Spends the credits up front (402 if short) and refunds them if the pass fails. |
POST /api/jobs/{id}/cancel | Discard a not-yet-started job (e.g. a cancelled confirmation), deleting its file. |
GET /api/jobs/{id}/logs | The job's log lines: the in-memory buffer while it runs, the job_log_archives copy once finished. |
GET /api/jobs/{id}/metrics | Timing, token, and cost summary. |
GET /api/jobs/{id}/stream | Server-Sent Events stream of progress, logs, and final metrics. |
These endpoints are id-addressed and not team-checked; they back the processing and review UI.
The SSE progress stream
GET /api/jobs/{id}/stream polls the job every ~1.5 seconds (up to ~10 minutes) and emits three event types: progress (status, percent, current stage), log (new log lines), and a final metrics event when the job reaches complete or error. Caching and buffering are disabled so events arrive immediately through nginx and the Next dev proxy.
inventory
The largest router: item CRUD, approval, bulk edits, multi-photo management, merging, and exports.
| Method & path | Purpose |
|---|---|
GET /api/inventory/{job_id} | List a job's items (with photos), ordered by item number. Active items by default; ?archived=true lists archived ones. |
PUT /api/inventory/item/{item_id} | Edit an item; marks it reviewed. Writes activity. Setting photo_path (Guided Review's frame pick and crop) also makes that path the primary item_photos row: an existing row with that path is promoted, otherwise one is added, and a previous primary that was itself a frame pick (/frames/ or crop_*) is dropped. |
POST /api/inventory/item/{item_id}/archive | Archive an item (sets is_archived + archived_at; item_number untouched). Rejected with 400 for submitted items. Writes activity. |
POST /api/inventory/item/{item_id}/unarchive | Restore an archived item (clears archived_at). Writes activity. |
POST /api/inventory/{job_id}/approve | Approve or unapprove one item. Writes activity. |
POST /api/inventory/{job_id}/auto-approve | Apply saved auto-approval rules to unapproved items. |
POST /api/inventory/{job_id}/bulk | Apply one field patch to many items (skips submitted items). |
POST /api/inventory/{job_id}/item | Manually add an item to one upload (supports insert-between numbering via insert_after_number; otherwise appended at the claim's max number + 1). Without a room in the body the item takes its upload's room name. Used by a single upload's table, Review Mode and the video player. |
POST /api/rooms/{room_id}/items | Add a hand-typed item to a room, from the room or claim table's Add item window. Same body as the route above. The item goes into the room's Added by hand job (origin="manual", filename="Added by hand"), created on first use by _manual_job_for_room and reused after: complete, no file, every cost field 0, so nothing processes, bills, or warns about it. So it works on a room with no uploads and never rides on a video that could be deleted or reprocessed. room defaults to the room's name. Archived room is a 409. Writes activity. |
DELETE /api/inventory/item/{item_id} | Internal hard delete of an item (snapshot stored for restore). No longer exposed in the UI: archiving replaced it. Retained for the undo-of-add path and the 30-day purge. |
PUT /api/inventory/item/{item_id}/photo | Replace an item's primary photo. |
POST /api/inventory/item/{item_id}/photos | Attach a photo to an item. |
POST /api/inventory/item/{item_id}/photo-crop | Guided Review's frame crop. Body {source_url, box: [x, y, w, h]} (fractions). Cuts the box out of a frame (/api/jobs/<job>/frames/...) or photo (/api/photos/<job>/...) of the item's own job, saves it under <storage>/<job_id>/photos/crop_*.jpg, and returns {url}. Does not change the item; the app then sets photo_path with PUT /api/inventory/item/{id} so undo works as usual. Edit lock applies. |
GET /api/inventory/item/{item_id} | One item with its photos. |
PUT /api/inventory/item/{item_id}/room | Move an item to another room of the same claim, body {room_id}. Re-attaches it to the room's most recent upload (an item's room comes from its upload); a room with no uploads, an archived room, another claim's room, or a submitted item is a 400. Keeps the item number. Restorable. |
DELETE /api/inventory/item/{item_id}/photos/{photo_id} | Remove a photo (promotes the next if primary). Restorable: the snapshot keeps the photo row. |
PUT /api/inventory/item/{item_id}/photos/{photo_id} | Set primary / reorder a photo. is_primary: true demotes every other photo on the item and copies the photo onto the item's photo_path, which is what the inventory table thumbnail and the export read. |
PUT /api/inventory/item/{item_id}/photos/{photo_id}/move | Move a photo to another item. |
POST /api/inventory/item/{item_id}/photos/{photo_id}/new-item | Create a new item ("New Item", same job and room, claim max item number + 1) whose primary photo is this photo, tagged source_type="form". Optional body {box: [x, y, w, h]} (fractions of the photo as shown): that region is cut out and saved as <job>/photos/crop_<source item id>_<hex>.jpg and the whole photo becomes its context_path. Without a box the new photo row points at the same stored file; nothing is copied. Not blocked by the ContentsEstimation lock (it creates, it does not edit). Logged as add_item, so restoring it deletes the new item. When the source item came from a photo marked in ContentsCapture (marked_photo_path set), the new item is saved with outside_marks = true and the same marked_photo_path. The photo viewer's Add item from this photo (and N) calls it. |
POST /api/inventory/items/merge | Merge several items into one (reassigns photos, deletes losers). Restorable: the snapshot keeps each loser's row and where each moved photo came from, and restore recreates the losers back in their old place in the claim order. |
GET /api/inventory/{job_id}/export/excel | Excel export (summary + per-room sheets + a Photos sheet); ?approved_only=true. Archived items are always excluded. Item names are hyperlinked to their primary photo. |
GET /api/inventory/{job_id}/export/csv | CSV export; ?approved_only=true. Archived items are always excluded. |
GET /api/claims/{claim_id}/inventory | Every item across the claim's non-archived rooms, in item-number order, as {items, uploads}; uploads maps each job_id to its filename, room_id, room_name and room_position (its place in the claim's room order, which the table sorts by). Active items by default; ?archived=true lists archived ones. Feeds the claim page's items table. |
GET /api/rooms/{room_id}/inventory | All items across every job in a room. Active items by default; ?archived=true lists archived ones. |
GET /api/claims/{claim_id}/export/excel | The whole claim's inventory as one Inventory sheet whose columns mirror the claim items table. The Photo column is a "View photo" link to the item's primary photo, blank when there is none. Active items in live rooms, in room order then item number. |
GET /api/rooms/{room_id}/export/excel | Room-level Excel export, with the same photo links as the job export. |
GET /api/rooms/{room_id}/export/csv | Room-level CSV export. |
GET /api/photos/{job_id}/{filename} | Serve a stored photo file. |
Mutating endpoints use get_actor and write activity entries (most with a before snapshot enabling restore).
The archive lifecycle and the 30-day purge
Claims, rooms, and items are never deleted by hand. The only removal action in the UI is archive (is_archived + archived_at), which hides the thing from the default lists, counts, exports, and Adjust Square submission while keeping every row and file. Archiving is blocked once something is submitted (a claim with submitted_at, a room holding any submitted item, or a submitted item). Restoring clears archived_at.
A background job (app.services.archive_cleanup.purge_expired_archived, started from app.main.lifespan) runs on startup and then once a day. It permanently deletes anything whose archived_at is more than 30 days old, cascading to everything beneath it and removing its files on disk. This is the only automatic deletion in the system.
settings
| Method & path | Purpose |
|---|---|
GET /api/settings/automation | Get the auto-approval rules. |
PUT /api/settings/automation | Save auto-approval rules. Writes activity with a before snapshot. |
GET /api/settings/prompts | Get the AI prompt settings bundle (presets, the team's edge_items setting, built-in defaults, char cap). While edge_items is flag or drop, the defaults for photo_unmerged and photo_group_multi are the edge variants and carry edge_items: true. |
PUT /api/settings/prompts | Validate and save prompt settings, including edge_items (off, flag or drop; omitted means off); logs exactly what changed. |
Settings are stored as JSON files on disk (not in the database). See automation and prompts.
activity
| Method & path | Purpose |
|---|---|
GET /api/activity | The activity log feed. |
POST /api/activity/{log_id}/restore | Undo a restorable action from its snapshot. PUT /api/inventory/item/{id}, PUT .../room, DELETE .../photos/{photo_id}, POST .../photos/{photo_id}/new-item and POST /api/inventory/items/merge return the new entry's id in an X-Activity-Id response header (exposed through CORS) so the UI can undo on the spot. |
billing
| Method & path | Purpose | Auth |
|---|---|---|
GET /api/billing/summary | The team's spend total (total_spend_usd) and the flat credit rates (video/photo/audio). When ENABLE_BILLING is on it also returns billing_enabled, the team's prepaid credits_balance, and a buy_credits_url, which drive the persistent credits widget (the team's available balance + a Buy credits button). When billing is off those are false/null and the widget is hidden. | get_current_user, team-scoped |
When prepaid billing is enabled, an upload does not process immediately: video/audio jobs park in awaiting_confirmation (photos in awaiting_grouping) and the client first calls GET /api/jobs/{id}/quote for the exact cost + balance to show a confirmation modal. Credits are spent at confirm: POST /api/jobs/{id}/process spends up front (the gate) and returns 402 with { error: "insufficient_credits", credits_balance, required_amount, buy_url } when the team cannot cover it, otherwise it starts the pipeline. The spend fails open if the billing service is unreachable, a cancelled job is discarded via POST /api/jobs/{id}/cancel, and a job that later fails processing is refunded. See billing.
dashboard
| Method & path | Purpose | Auth |
|---|---|---|
GET /api/dashboard/metrics | Team-scoped headline numbers for the Dashboard stat cards. Returns the processing-speed metric: items_cataloged (items the pipeline produced across the team's completed jobs), processing_seconds (their total wall-clock completed_at - created_at), and seconds_per_item (the average, or null when there are none yet). Jobs still running, or completed but with no items, are excluded so they cannot distort the per-item average. | get_current_user, team-scoped |
integrations
ContentsCapture (routes/integrations.py). Team-scoped through get_actor (a connection of another team is a 404); a revoked Capture token comes back as 409 asking for a reconnect. Every endpoint refuses while the training gate locks the user. Full detail, including the webhook event handling, in Contents Capture.
| Method & path | Purpose |
|---|---|
GET /api/integrations/connections | The team's connections plus contents_capture_available. |
POST /api/integrations/contents-capture/connect | Validate a pasted Capture org token and store (or replace) the team's one connection. |
POST /api/integrations/contents-capture/provision | Machine-to-machine: Contents Estimation connects a team to its Capture company. No JWT; Authorization: Bearer <CONTENTS_CAPTURE_PROVISIONING_SECRET>. Idempotent; 409 for a different Capture org. |
DELETE /api/integrations/connections/{id} | Disconnect. |
GET /api/integrations/product-access/capabilities | Machine-to-machine: what this app accepts from the product access push. No JWT; the same Authorization: Bearer <CONTENTS_CAPTURE_PROVISIONING_SECRET>. An older ContentsVision answers 404. |
POST /api/integrations/product-access | Machine-to-machine: store one person's product access record. 200 stored or ignored_older, 422 rejected. |
POST /api/integrations/product-access/batch | Machine-to-machine: up to 500 records, each answered on its own (stored, ignored_older, rejected). |
GET /api/integrations/connections/{id}/teams, .../teams/{team_id}/assignments, .../assignments/{assignment_id}/tree, .../assignments/{assignment_id}/media | Browse proxy over the Capture read API. The media page passes Capture's short-lived presigned thumbnail URLs straight through. |
POST /api/integrations/connections/{id}/import | Save a selection manifest on an ImportBatch and start the import in the background. |
GET /api/integrations/imports/{batch_id} | Poll an import batch (Capture imports and contents-list PDF imports). |
GET /api/integrations/contents-capture/arrivals | Capture media waiting for its room to settle before it imports, one entry per Capture room (the claim page uses GET /api/claims/{id}/capture-arrivals). |
POST /api/integrations/contents-capture/webhook | Public: Capture webhook deliveries, authenticated by the per-delivery HMAC signature. Answers 202. |
telemetry
| Method & path | Purpose |
|---|---|
POST /api/telemetry/v1/{signal} | Same-origin OTLP passthrough for browser telemetry (signal is traces, metrics or logs; anything else is 404). Forwards the raw body to the configured collector with the server-side OTEL_EXPORTER_OTLP_HEADERS, so no ingest credentials ship in the JS bundle. When telemetry is off it answers 204 and drops the body. No auth. See browser telemetry. |
training
The training program (see Training and certification).
| Endpoint | Purpose |
|---|---|
GET /api/training/overview | Missions with the caller's progress, points, badges, training claim id, certificate state. Quiz answers are never included. |
POST /api/training/start | Create (or return) the caller's sandbox training claim. Idempotent. |
POST /api/training/missions/{key}/quiz | Grade a quiz submission; stores the best score; returns per-question results and explanations. |
GET /api/training/missions/{key}/checks | Side-effect-free grading of the mission's doing-checks, safe to poll. Powers the on-screen task tracker. |
POST /api/training/missions/{key}/check | Grade the mission's doing-checks against the training claim's real state; completes the mission and banks points when everything passes. |
GET /api/training/leaderboard | Team-scoped points standings. |
POST /api/training/certificate | Issue the caller's certificate once all missions are complete (409 before that). |
GET /api/training/certificates/{code} | Public, no auth: verify a shared certificate code. Returns {valid: false} for unknown or revoked codes. |
GET /api/training/me | The caller's required-training state: locked, reminder, next_due, exempt, and each assigned module with due date, progress, days_left, overdue. |
GET /api/training/modules/{key} | A module as the learner sees it: lessons (quiz answers removed), steps with {claim} routes resolved to their own sandbox claims, check labels and hints (rules stay server side), progress, sandbox claim ids by ref. |
POST /api/training/modules/{key}/start | Seed the module's fixture claims for the caller. Idempotent. |
POST /api/training/modules/{key}/lessons/{lesson}/quiz | Grade a lesson quiz (same rules as missions). |
GET /api/training/modules/{key}/lessons/{lesson}/checks | Side-effect-free lesson grading, safe to poll. |
POST /api/training/modules/{key}/lessons/{lesson}/check | Grade the lesson and complete it when every check and the quiz pass. |
Training admin (routes/training_admin.py; library changes require_admin, settings, exemptions and compliance by scope_auth):
| Endpoint | Purpose |
|---|---|
GET /api/admin/training/modules | The library: one entry per key with live version and source. Readable by internal admins and anyone holding settings.manage_team or settings.manage_org, so managers can pick modules to assign. |
GET /api/admin/training/modules/{key} | The full document (answers and rules included); ?version= for an older one. |
GET /api/admin/training/modules/{key}/export | Download the document as <key>-v<version>.training.json. |
POST /api/admin/training/modules/import | Multipart file. Validates and stores as the next version; 422 {code: invalid_module, problems: [...]} when invalid. |
POST /api/admin/training/modules | Save a document from the builder as a new version. |
POST /api/admin/training/validate | Dry-run validation for the builder; never stores. |
DELETE /api/admin/training/modules/{key} | Archive a custom module, or revert a builtin's edits. |
GET/PUT /api/admin/training/settings/{scope_type}/{scope_id} | Read or set the training.* keys at one level (org, bu, team, user) through the shared resolver; clear: [...] removes keys; 409 when a level above locked the key. |
PUT /api/admin/training/users/{id}/exemption | Exempt a user (reason required), lift it, or set a per-user due date. |
GET /api/admin/training/compliance | Every active user (optionally ?team_id=) with lock, exemption, and per-module status. |
The required-training gate. When overdue required training locks a user, claim, room, job, and item endpoints answer 403 with detail.code = "training_required" for real claims, claim and job listings return only training claims, POST /api/claims refuses unless training_module_key is sent (a lesson's sandbox claim), and every /api/integrations/... endpoint refuses. See the gate.
Training claims also change the behavior of three existing endpoints: uploads into them complete instantly with fixture items (no pipeline, no credits), GET /api/jobs/{id}/quote returns 0 credits, and POST /api/claims/{id}/submit-to-adjust-square performs a dry run that never contacts Adjust Square.
insured
The insured's own inventory link (see Insured inventory link). Two routers, deliberately in separate files so nothing authenticated is added to the public one by accident.
Adjuster-facing, behind get_actor and team-scoped like everything else. Never returns a token: only the token's hash is stored.
| Method & path | Purpose |
|---|---|
GET /api/claims/{claim_id}/insured-links | Every invitation on this claim, newest first, with how far each recipient got. |
POST /api/claims/{claim_id}/insured-links | Invite the insured by email address. Re-inviting an address that already has a live link resends that one, so their existing work is kept. |
POST /api/insured-links/{link_id}/resend | Send again. Rotates the token: their drafts survive, but the URL in the earlier email stops working, because the raw token was never stored and cannot be recovered. |
POST /api/insured-links/{link_id}/revoke | Shut a link immediately. Work already submitted stays on the claim. |
Public, no auth, token in the path. Failures are 404, 409, 413, 415, 422, or 429, never 401.
| Method & path | Purpose |
|---|---|
GET /api/public/insured/{token} | Everything the wizard renders, including on resume. Records that the link was opened. Also carries the address the link was sent to (insured_email), which is the homeowner's own and is what the submission history shows as who added each row. |
POST /api/public/insured/{token}/identify | Record the homeowner's name. Never a gate. |
POST /api/public/insured/{token}/rooms | Add a room to the claim. An existing name returns that room rather than duplicating it. |
POST /api/public/insured/{token}/rooms/{room_id}/files | Upload ONE photo with its note. One file per request, so a dropped connection costs one file rather than a batch. |
POST /api/public/insured/{token}/uploads/init, GET .../uploads/{id}, PUT .../uploads/{id}/chunks/{n}, POST .../uploads/{id}/complete, DELETE .../uploads/{id} | The chunked path for a video or voice recording, mirroring /api/uploads above with the scope changed to the link. GET reports the parts received so a Retry resumes with only the missing ones; init sweeps uploads abandoned for over a day. Details in Insured inventory link. |
POST /api/public/insured/{token}/rooms/{room_id}/items | Add a typed row. |
PATCH /api/public/insured/{token}/items/{item_id} | Save one field as they leave it. Only the fields sent are written. |
DELETE /api/public/insured/{token}/items/{item_id} | Remove a row and its photos, on disk too. |
POST /api/public/insured/{token}/items/{item_id}/photos | A photo for the table's Photo column. Never goes to the AI. |
PATCH /api/public/insured/{token}/files/{file_id} | Edit a file's note. |
DELETE /api/public/insured/{token}/files/{file_id} | Remove a file. Does not credit back the link's byte ceiling. |
GET /api/public/insured/{token}/files/{file_id}/content | Serve one of their own uploads back at full size, so a resumed session shows what they sent and the lightbox has a real photo to show. Scoped to the link. |
POST /api/public/insured/{token}/files/group | Mark several photos as angles of ONE item, so they become one AI call and one item. Refused for photos already sent and across rooms. |
POST /api/public/insured/{token}/files/ungroup | Put grouped photos back on their own. |
GET /api/public/insured/{token}/files/{file_id}/poster | The still frame taken from a video at upload, so the grid can show a clip without downloading it. 404 when there is none. |
GET /api/public/insured/{token}/files/{file_id}/thumb | A small copy of one photo (longest edge 640px) for the media grid, made on first request and cached beside the original. Uploads are kept at their original size, and a camera photo is routinely 16 megapixels, so pointing the grid at /content meant decoding hundreds of megabytes of bitmap to fill tiles a couple of hundred pixels wide. 404 for video and audio. |
POST /api/public/insured/{token}/submit | Turn the drafts into work on the claim. Photo jobs park at awaiting_grouping, videos at awaiting_confirmation, typed rows become inventory items directly. Spends no credits and starts no AI. |
POST /api/public/insured/mailgun-events | Mailgun delivery webhook. Public because Mailgun calls it, but HMAC-verified against MAILGUN_WEBHOOK_SIGNING_KEY; with no key set every call is rejected. |
Admin dashboard (/api/admin)
The internal operator dashboard. Unlike every other router, these endpoints aggregate across all teams (no team scoping) and are gated by require_admin, so only the Adjust Square user IDs in ADMIN_EXTERNAL_USER_IDS (default {7, 10}) can reach them. A non-admin gets 403 "This page is restricted."; an unauthenticated request gets 401.
| Method & path | Purpose | Auth |
|---|---|---|
GET /api/admin/overview?range=<range> | One aggregate payload for the whole dashboard: headline credit spend, system counts (claims, items, videos, audios, photo requests), credit spend by media type, a per-team usage leaderboard (claims / videos / audios / photo requests / items / credits), the latest claims, the last 10 jobs (any status), jobs processing now, recently failed jobs (with error messages), the recent activity feed, recent Adjust Square submissions, and aggregate quality metrics (avg items/claim, avg credits/claim, avg processing time per request). The stats include ai_cost_usd (our OpenRouter spend in dollars within the range, from the persisted per-job ai_cost_usd) and two live figures that ignore the range: active_users (users seen in the last 5 minutes via users.last_seen_at) and active_jobs. All customer spend is in credits, always whole numbers. | require_admin |
GET /api/admin/users?search=<q> | List users (id, external id, name, email, team, is_admin) for the impersonation picker, optionally filtered by name or email. Capped at 200. Reads only those columns, and a row that cannot be serialized is skipped and logged (admin.users.row_skipped) rather than failing the list. | require_admin |
POST /api/admin/impersonate/{user_id} | Mint a short-lived token that authenticates as that user so an admin can see the app exactly as they do. Returns {token, user}; the frontend swaps tokens and can switch back. Carries an impersonated_by audit claim and writes a non-restorable impersonate_user activity entry. Returns 400 if the user has no Adjust Square id. | require_admin |
GET /api/admin/active-jobs | Just the live count of jobs processing right now: { "active_jobs": <int> }. The same number as the overview's active_jobs stat (it shares one query), but cheap enough to poll on a short interval. The dashboard polls it to drive a favicon job-count badge, so an operator with /admin pinned can see at a glance when jobs suddenly start running. | require_admin |
GET /api/admin/logs | Every processing job system-wide, newest first, each tagged with its claim, team, and creating user, and carrying its log entries (live in-memory buffer while running, the job_log_archives copy once finished). Filters: team_id, user_id, status (a job status or active for anything still processing), q (substring on filename or claim number). Paginates with limit/offset and returns total plus the full teams and users lists for the filter dropdowns. Backs the Logs page (/logs). | require_admin |
GET /api/admin/activity | The activity log across all teams, newest first, each row tagged with its team (the customer GET /api/activity scopes to the caller's team). Filters: team_id, q (substring on user, action, or target); paginates with limit/offset. Restore stays team-scoped through the existing POST /api/activity/{id}/restore, so the dashboard only offers Restore on rows from the admin's own team. | require_admin |
GET /api/admin/media | Browse every uploaded media item system-wide (one row per processing job), newest first, tagged with team, user, and claim. Each item carries directly renderable URLs: the video/audio capability stream, a thumbnail (first extracted frame or first photo), and photo jobs list their uploaded photos (capped at 12, photo_count has the total). file_exists flips to false once the original file was cleaned off disk. Filters: type (video/photo/audio), team_id, q (filename or claim number); paginates with limit/offset. Backs the admin Media tab. | require_admin |
GET /api/admin/components | Every toggleable UI component (the registry in services/component_visibility.py) with its per-component default, global state, and per-team overrides. Resolution: team override > global override > registry default. Training's default is HIDDEN: it is enabled from the admin Teams tab. | require_admin |
PUT /api/admin/components | Set or clear one visibility override: {component, team_id, visible}. team_id: "" targets the global row; visible: null clears the override so the level above applies. Returns the updated table. What a user's team resolves to is delivered as features on GET /api/auth/me. | require_admin |
GET /api/admin/api-requests | Outbound AI API calls (OpenRouter) grouped by job, newest activity first. Each group carries per-job totals (request count, cost, time, tokens), the owning claim/team/user, and its full request list (request JSON with base64 images redacted, full response JSON, attempts, duration, real cost from usage accounting). Filters: q (job id / claim number / filename), team_id, user_id; limit/offset paginate the groups. Backs the "API Requests" tab on the Logs page. | require_admin |
GET /api/admin/model-examples/export | Zip of photo examples for the self-hosted model: examples.jsonl, manifest.json, and photos/. on=YYYY-MM-DD is one UTC day. pending=true is rows not yet exported. With neither, the export is the pending set. mark=false does not stamp the rows. See model_examples. The same file is produced by backend/scripts/export_model_examples.py. | require_admin |
GET /api/admin/item-trace/claims | Claim picker for the Logs page's Item lookup tab, system-wide: q matches an exact claim id, or a claim number / insured name substring. Newest 20, each with team, creating user, and live (non-archived) item count. Archived and training claims are included and tagged. | require_admin |
GET /api/admin/item-trace/claims/{claim_id}/items | Every item on one claim (archived included), in item-number order, with all searchable attributes (name, number, room, brand, model, serial, SKU, condition, damage, notes, AI evidence) and the upload (job) each came from. Not paginated: the page filters in the browser. No price fields. | require_admin |
GET /api/admin/item-trace/items/{item_id} | How one item was processed: the item, its job with the full pipeline log, log_matches (indexes of log lines naming the item), and every AI call from that job. AI calls are only recorded per job, so a call counts as the item's when its response or request text contains the item's name, model number, or serial number (case and spacing ignored; match_terms lists them). Matched calls come first with match_in = response / request / both, then the rest. An item renamed after processing matches nothing, but every call is still returned. | require_admin |
POST /api/admin/jobs/{id}/dismiss | Mark a hung/abandoned job as failed so it stops counting as active: sets a retryable error message, refunds any up-front charge (idempotent), archives its in-memory logs. 409 for jobs already finished. | require_admin |
DELETE /api/admin/jobs/{id} | Hard-delete a job and everything beneath it: items (and their photos), staged photos, archived logs, and files on disk. The AI API request log rows are kept as the cost accounting record. Cannot be undone. | require_admin |
Impersonation lets an operator debug a customer's exact view. The endpoint signs a valid AdjustSquare-format token for the target user with the shared ADJUSTSQUARE_JWT_SECRET, so it authenticates as them on every subsequent request; the token is short-lived and carries an impersonated_by claim for audit. The admin's own token is kept client-side so they can switch back, and an app-wide banner makes the impersonation obvious. Every impersonation is recorded in the activity log.
The optional range query param scopes every time-bounded figure to one window: today, 24h, week, 30d, year, or all (the default; an unrecognized value falls back to all). Two figures intentionally ignore the range because they describe current state: active_jobs and the "jobs processing now" list are always live. Both also exclude photo jobs in awaiting_grouping (those wait on a user action, not on our processing). "Photo requests" counts billed photo requests (the sum of photo_request_count), not raw photos, and the per-request job time normalizes each photo batch's wall-clock by its request count so batches of different sizes are comparable.
See authentication for the allowlist and gating, and billing for what "credits" means.
health
| Method & path | Purpose |
|---|---|
GET /health | Liveness check (no /api prefix). Returns {status, model}; used by the Docker healthcheck. nginx does not proxy this path, so it is not reachable on the public host. |
GET /api/health | Public liveness check. No auth, no database. Returns {status: "ok", commit} where commit is COMMIT_SHA (dev when unset). nginx's location /api/ and the frontend rewrite /api/:path* both send it to the backend. |
GET /api/health/pipeline | Public: whether the separate pipeline worker is running or jobs are silently falling back to running inside the web server (queue_health in core/queue.py). Reachable through the tunnel, so a deploy can be checked without server access. |
Next
- Authentication: how the JWT becomes a user and team.
- Adjust Square: the submit endpoint in depth.
- Frontend: how the client calls all of this.