# AmanahLens > AmanahLens helps parents decide whether a book is right for their child. Upload an EPUB, MOBI, or PDF; AmanahLens reads the whole book, flags passages that touch themes the parent cares about (for example violence, ideology, romance, or language), quotes each one, and rates the book. This file explains how an AI agent can run that upload → analyze → report flow over the HTTP API with a user's API token. Base URL: `https://api-production-4afb.up.railway.app`. Routes sit at the root (no `/api` prefix). Requests and responses are JSON, except the upload, which is `multipart/form-data`. Auth: every call below needs `Authorization: Bearer `. The user creates a token on the website (https://www.amanahlens.com → Account → API tokens → create). The token is shown once; it acts as that user, uses that user's analysis quota (per rolling 30 days), and stays valid until the user revokes it. Tokens cannot create or revoke tokens, change billing, or reach admin routes; those need a signed-in browser session. The examples use bash, curl, and jq: ```bash API=https://api-production-4afb.up.railway.app TOKEN=atk_... # the user's API token AUTH="Authorization: Bearer $TOKEN" ``` **1. Upload the book.** Send the file in the multipart field `file` (EPUB, MOBI, or PDF, up to 100 MB). An EPUB or MOBI is read during the request and returns `201` with the new book; keep `book.id`. ```bash BOOK_ID=$(curl -sS -X POST "$API/books/upload" -H "$AUTH" -F "file=@book.epub" | jq -r .book.id) ``` A PDF returns `202` with `{"extraction": {"id", "status", "createdAt"}}` instead, because it is read in the background. Poll `GET /books/extractions/{extraction.id}` until `extraction.status` is `ready` (then `extraction.bookId` is the book) or `error` (then see `extraction.errorMessage`). Statuses: `pending`, `processing`, `ready`, `error`. **2. Pick a profile.** A profile is the set of themes the parent wants flagged. Each account gets a default profile (`isDefault: true`) on first sign-in; the user may have made others on the website. ```bash curl -sS "$API/profiles" -H "$AUTH" | jq '.profiles[] | {id, name, isDefault, themes: (.themeIds | length)}' PROFILE_ID=$(curl -sS "$API/profiles" -H "$AUTH" | jq -r '(first(.profiles[] | select(.isDefault)) // .profiles[0]).id') ``` **3. Start the analysis.** `bookId` is required; `profileId` is optional and sets which themes the report shows by default. ```bash START=$(curl -sS -X POST "$API/analyses" -H "$AUTH" -H "Content-Type: application/json" \ -d "{\"bookId\": \"$BOOK_ID\", \"profileId\": \"$PROFILE_ID\"}") echo "$START" | jq '{cached, status: .analysis.status}' ID=$(echo "$START" | jq -r .userRequest.id) ``` The response is `{"userRequest": {...}, "analysis": {"id", "status", "contentHash"}, "cached": bool}`. Use `userRequest.id` (or `analysis.id`; both work) as `{id}` in every `/analyses/{id}` route. Caching: a book is analyzed once per content and analysis settings, whoever uploaded it. If the same file has been analyzed before, the call returns `200` with `cached: true` and the report is ready at once. If that analysis is still running, the call returns `202` and joins it. Otherwise it returns `202` and queues a new run. Quota: each plan allows a number of analyses per rolling 30 days. - A POST /analyses counts toward the limit, with one exception: it joins a completed or still-running analysis that the user already requested and has not deleted. So a cache hit on a book this user never analyzed before, such as a copy another user already ran, counts like a new run even though the report is ready at once. Deleting a request does not give back its count. - A POST that counts is checked against the quota. If the user's counted analyses in the last 30 days are at the plan's limit, the POST uses one of the user's analysis-pack credits, or fails with `403 QUOTA_EXCEEDED` if they have none. - Asking again for an analysis the user already requested is never checked against the quota: it never uses a pack credit and never fails with `403 QUOTA_EXCEEDED`, even at the limit. - A run that fails stops counting for everyone who requested it, but a pack credit used to get past the check is not returned. Retrying a failed run with POST /analyses counts like a new run. - Reading a report with GET /analyses/{id}, or polling its status, never counts. To see a report again, call GET /analyses/{id} rather than POSTing again. **4. Wait for it to finish.** A new run works in the background; a long book can take minutes. Poll the status every 10-30 seconds until `status` is `completed` or `failed`. ```bash while :; do S=$(curl -sS "$API/analyses/$ID/status" -H "$AUTH") echo "$S" | jq -c '{status, step: .progress.step, percent: .progress.percent}' case $(echo "$S" | jq -r .status) in completed|failed) break ;; esac sleep 15 done ``` `status` is `pending`, `processing`, `completed`, or `failed`. `progress.step` moves through `queued`, `scoring`, `locating`, `writing`, `checking`, `describing`, `finalizing`, then `complete` (or `failed`); `progress.percent` is 0-100. A failed run has `errorMessage`; POST /analyses again with the same book to retry. `requestedAt` is when this user asked; `completedAt` is when the analysis itself finished, so on a cache hit `completedAt` is earlier than `requestedAt`. **5. Read the report.** ```bash curl -sS "$API/analyses/$ID" -H "$AUTH" | jq '.result | {bookRating, totalHits, uncheckedThemeKeys}' curl -sS "$API/analyses/$ID" -H "$AUTH" | jq '.result.concerns[] | {themeLabel, categoryLabel, overall, overallReason, brief}' curl -sS "$API/analyses/$ID" -H "$AUTH" | jq '.result.scenes[] | {id, title, chapterName, percentageThroughBook, summary, findings: [.findings[] | {themeLabel, sameActThemeKeys, severity, treatment, note, quote, hitIds}]}' ``` Until the analysis completes, this returns only `analysis` (id, status, requestedAt). Once complete it also has `result`, `book` (title, author), the user's `feedback` keyed by hit id, and their `annotations` (reading notes) keyed by scene id. Add `?profileId=` to see the same analysis through another of the user's profiles; it is not re-run. How to read the report: - `result.scenes` is the report itself, in book order. A scene is a part of the book where confirmed findings sit close together: `title` and `summary` say what happens there (both null when the scene has no write-up), with `chapterName`, `percentageThroughBook`, and line numbers. - Each scene has one `findings[]` entry per theme of the profile found in it: `note` (what in the scene raises the theme), `quote` (the book's own words), `severity` (how strongly the scene shows it: `mild`, `moderate`, or `severe`), and `treatment` (how the scene treats it, as a child would see it: `approving`, `matter_of_fact`, or `disapproving` when the book disapproves of it, whether through regret, correction or punishment). A finding is reported however the book treats it; treatment never lowers its severity. Tell the user about the scene as a whole, then why each theme matters in it. - One act is one finding. When the scene shows a single act under several of the profile's themes (an insult to a parent that is both disrespect and meanness), it is reported under the most serious of them, and `sameActThemeKeys` names the others. Those themes are found in the book, not clean: they are in `result.concerns`, but the hits of that act count only in the reported theme's `rating`, so another theme's rating can read `No concerns found` though the book shows it. Dating and LGBT themes always have their own finding. - `result.concerns` lists the profile's themes that were found. `brief` says how the theme shows up across the whole book, and `overall` grades the theme for the book as a whole (`mild`, `moderate`, or `severe`: its worst scene weighed with how central it is to the story), with `overallReason`. All three are null when the analysis did not write them. Lead with the concerns, then the scenes. - Every finding was confirmed by a second model. `result.categories[].themes[]` lists every theme in the profile, grouped by category, with its `rating` and the hits behind the findings; `tier: "unchecked"` hits (flagged but not confirmed) appear there for admin accounts only and are in no scene. - `rating` (per theme) and `bookRating` (whole book) have `label` (for example "2 moderate and 1 mild concerns"), `severity` (the worst checked hit: `none`, `mild`, `moderate`, or `severe`), and `count` (`none`; `some` for 1-4 checked hits; `many` for 5 or more). - Rating labels with no checked hits: "No concerns found"; "Unconfirmed flags only" (admin accounts only: only unchecked hits); "Not checked" (the analysis could not check this theme and found nothing). - A theme with `checked: false`, also listed in `result.uncheckedThemeKeys`, could not be checked across the whole book, so its findings may be incomplete; its label ends with "(not fully checked)" when it has checked hits. Do not report such a theme as clean. - `categories[].allClean` is true when every theme in the category was fully checked, has no hits of either tier, and is not reported as part of another theme's finding. To quote the book around a scene, fetch its passage: the lines from the scene's first to last finding with 8 lines of the book on each side (`?radius=40` for more). `firstLine` is the line number of `lines[0]`; a finding's `lineStart` and `lineEnd` index into the same numbering. ```bash SCENE_ID=$(curl -sS "$API/analyses/$ID" -H "$AUTH" | jq -r 'first(.result.scenes[].id)') curl -sS "$API/analyses/$ID/scenes/$SCENE_ID/passage" -H "$AUTH" | jq '{chapterName, firstLine, lines}' ``` **6. Optional: take a finding off the report when the user disagrees with it.** Vote `down` on each of the finding's `hitIds` (like `x012.lying_deception`); they include the hits of the themes in its `sameActThemeKeys`, so the vote covers the whole act. The finding then leaves the user's ratings, `totalHits`, and library summary; it stays in `result.scenes`, and `feedback` shows which hits are voted down, so leave out findings whose hits are all voted `down`. Deleting the vote restores the finding. A vote replaces any earlier vote on that hit. ```bash HIT_ID=$(curl -sS "$API/analyses/$ID" -H "$AUTH" | jq -r 'first(.result.scenes[].findings[].hitIds[])') curl -sS -X PUT "$API/analyses/$ID/hits/$HIT_ID/feedback" -H "$AUTH" -H "Content-Type: application/json" \ -d '{"vote": "down", "comment": "The story shows this lie as wrong"}' curl -sS -X DELETE "$API/analyses/$ID/hits/$HIT_ID/feedback" -H "$AUTH" ``` `vote` is `up` (the flag is right) or `down` (it is wrong, or not a concern for this family); `comment` is optional, up to 500 characters. Errors: every error is `{"error": {"code", "message", "details"}}`. - `401 UNAUTHORIZED`: missing, invalid, or revoked token. - `400 VALIDATION_ERROR`: a missing or malformed field, a wrong file type, or a file that is not a readable book. - `403 QUOTA_EXCEEDED`: the user is at their plan's limit for the rolling 30 days and has no analysis-pack credits left; the message names the limit. They can upgrade or buy an analysis pack on the website. - `403 FORBIDDEN`: the route needs a browser session, or the profile belongs to someone else. - `404 NOT_FOUND`: no such book, profile, analysis, scene, or hit for this user. - `413 PAYLOAD_TOO_LARGE`: the file is over 100 MB. - `500 INTERNAL_ERROR`: retry later. ## API reference - [OpenAPI spec](https://api-production-4afb.up.railway.app/docs/openapi.json): every route this token can call, with request and response schemas; send the same `Authorization: Bearer` header - [AmanahLens](https://www.amanahlens.com): sign in here to create an API token and to see the reports in a browser ## Optional - [Your books](https://api-production-4afb.up.railway.app/books): `GET /books` lists the user's uploaded books, to reuse a `book.id` instead of uploading again - [Your analyses](https://api-production-4afb.up.railway.app/analyses): `GET /analyses?bookId=` lists the user's analyses, newest first, to find an earlier `{id}`