Skip to content

Mobile API

The mobile API is a read-only JSON API, added in 0.7.0. It runs on port 8502, next to the web app, and reads the same saved history as the web Dashboard.

What it does and doesn’t do:

  • Reads only. It never starts an analysis, changes a schedule or calls Sonarr. The data comes from analyses that already ran, from the web app or the scheduler.
  • Never returns secrets. No Sonarr URLs, API keys, password hashes or token hashes appear in any response. The test suite checks every endpoint for this.
  • Per user. Each token belongs to one user and sees only that user’s instances. Another user’s instance or series answers 404, as if it didn’t exist.
Base URL http://<server>:8502, or https:// with HTTPS
Prefix Every path starts with /api/v1
Format JSON in and out (Content-Type: application/json)
Schema OpenAPI at /api/v1/openapi.json (no interactive docs page)
Version api_version in /health; currently 1

A quick check from the server:

Terminal window
curl http://localhost:8502/api/v1/health
# {"server_version":"0.7.0","api_version":1,"tls":"none"}
  • Numbers are raw. Sizes are in GB, except where the field name says MB (avg_size_mb, mb_per_min); durations are in seconds and runway in days. Clients format them.
  • Missing values are null, never NaN or omitted keys.
  • Dates are ISO 8601 with the server’s UTC offset, taken from its TZ, e.g. 2026-10-01T03:00:00-04:00.
  • Text values that Sonarr didn’t provide come as the defaults the app stores: year as "N/A", and status, codec and quality as "Unknown".

Errors use FastAPI’s format, a JSON object with a detail message:

{ "detail": "Instance not found" }
Status When Client should
401 Missing, invalid or revoked token ("Not signed in", with WWW-Authenticate: Bearer); wrong credentials or pairing code Forget the token and ask to sign in or pair again
404 The instance or series doesn’t exist, or isn’t yours Show “not found”
422 A malformed request: missing field, a non-numeric series_id, a field over 200 characters. detail is a list describing each problem Fix the request
429 Too many failed sign-ins or pairing codes from this IP (rate limit) Wait and try later
500 A server problem, e.g. the database is unavailable (plain-text body) Treat it like “server unreachable” and keep the token. Only 401 means signed out

Every endpoint except health, auth/token and auth/pair needs a device token in the Authorization header:

Authorization: Bearer sa_Hyx2…
  • Tokens are sa_ followed by 32 random bytes (43 URL-safe characters). Each device gets its own.
  • The server stores only their SHA-256 hash, so a token is shown once, in the sign-in response.
  • Tokens don’t expire. They stop working when you revoke them in My profile → Mobile devices, when you sign out with DELETE /auth/token, when you change your password, or when your account is disabled or deleted.
  • Tokens are never read from the URL (?token= is ignored), so they don’t end up in proxy logs.

There are two ways to get a token: your username and password, or a one-time pairing code from a QR code.

POST /auth/token and POST /auth/pair share one budget: 10 failures per client IP in 10 minutes. After that, both answer 429 {"detail": "Too many failed attempts. Try again later"} for that IP until the oldest failure is 10 minutes old. Successful requests don’t count.

The usual account lockout applies on top: 5 wrong passwords in a row lock the account for 5 minutes, however many IPs they come from.

Behind a reverse proxy, set FORWARDED_ALLOW_IPS to the proxy’s IP or network. Otherwise every client appears to come from the proxy and shares a single budget.

Method Path Auth Purpose
GET /api/v1/health no Server and API version, TLS mode
POST /api/v1/auth/token no Sign in with username and password
POST /api/v1/auth/pair no Sign in with a one-time pairing code
DELETE /api/v1/auth/token yes Sign out this device
GET /api/v1/me yes Who the token belongs to
GET /api/v1/instances yes Your Sonarr instances
GET /api/v1/instances/{name}/dashboard yes Everything the Dashboard shows
GET /api/v1/instances/{name}/series/{series_id} yes One series and its size history

No authentication. Clients call it first, to check the server is a compatible Sonarr Analyzer.

{ "server_version": "0.7.0", "api_version": 1, "tls": "none" }

tls is "self-signed" when the server runs with SONARR_ANALYZER_TLS=self-signed, otherwise "none": plain HTTP, possibly behind a reverse proxy that adds HTTPS. A server without this endpoint is older than 0.7.0.

Sign in with a web-app account. device_name is shown in My profile → Mobile devices (trimmed to 100 characters; "Unknown device" if empty).

Terminal window
curl -X POST http://localhost:8502/api/v1/auth/token \
-H 'Content-Type: application/json' \
-d '{"username": "alice", "password": "…", "device_name": "Alice’s iPhone"}'

201 Created:

{ "token": "sa_Hyx2…", "user": { "id": 1, "username": "alice" } }

401 with one of these detail messages:

  • "Invalid username or password", also for unknown users, so names can’t be probed;
  • "Too many failed attempts. Try again in N minute(s)", while the account is locked;
  • "User account is disabled", only once the password was right;
  • "Sign-in failed", a server-side problem (the details go to the server log).

Sign in with the one-time code from My profile → Add mobile device. It’s what the apps do after scanning the QR code.

Terminal window
curl -X POST http://localhost:8502/api/v1/auth/pair \
-H 'Content-Type: application/json' \
-d '{"code": "Xy_9-ABC…", "device_name": "Alice’s iPhone"}'

201 Created, with the same body as /auth/token. 401 {"detail": "Invalid or expired pairing code"} if the code is unknown, already used, more than 5 minutes old, or its user is disabled.

A code works once, even if two devices send it at the same moment. The server stores only its SHA-256 hash.

The QR in the web app holds a URI the apps parse:

sonarranalyzer://pair?v=1&url=https%3A%2F%2F192.168.1.10%3A8502&code=Xy_9-ABC…&fp=3517…3ff0
Parameter Meaning
v Format version, currently 1. Apps reject versions they don’t know
url The API address the phone should use (URL-encoded). It defaults to SONARR_ANALYZER_PUBLIC_URL, or to the browser’s host on port 8502, and can be edited in the dialog
code The one-time code for POST /auth/pair
fp Only with SONARR_ANALYZER_TLS=self-signed: the certificate’s SHA-256 fingerprint, which the app pins. See HTTPS and certificate pinning

Revokes the token used for the request, signing this device out. 204 No Content. Other devices of the same user keep working.

{ "id": 1, "username": "alice" }

The user’s Sonarr instances, in name order:

[
{ "name": "empty", "last_status": null, "last_checked_at": null },
{ "name": "home", "last_status": "ok", "last_checked_at": "2026-10-01T03:05:00+00:00" }
]

last_status is the result of the last Test in Settings → Instances: "ok", "error", or null if never tested. The Sonarr URL and API key are never included.

Everything the web Dashboard shows for one instance, in one call, so clients can cache it for offline use. {name} is the instance name, URL-encoded if it has spaces. The response, shortened:

{
"instance": "home",
"generated_at": "2026-11-27T22:15:04+00:00",
"latest_analysis": {
"date": "2026-10-01T03:00:00+00:00",
"mode": "full",
"source": "scheduled",
"triggered_by": null,
"duration_s": 42.5
},
"metrics": {
"series": 3, "series_delta": 0,
"episodes": 25, "episodes_delta": 1,
"storage_gb": 118.0, "storage_delta_gb": 9.0,
"disk_free_gb": 2040.0, "disk_total_gb": 13000.0,
"runway": {
"status": "ok",
"days": 3405.04,
"date": "2036-01-27T03:53:19+00:00",
"earliest": "2036-01-25T12:40:04+00:00",
"latest": "2036-01-28T19:06:35+00:00"
},
"runway_with_reencode_days": 3450.1,
"recoverable_gb": 27.0, "candidate_count": 2,
"outliers": 1, "outliers_delta": 0
},
"forecast": {
"points": [{ "date": "2026-09-01T03:00:00+00:00", "storage_gb": 100.0 }, "…"],
"gb_per_month": 18.24,
"r_squared": 0.9985,
"capacity_gb": 2158.0,
"projection": [
{ "date": "2026-10-01T03:00:00+00:00", "storage_gb": 118.19 },
{ "date": "2036-01-27T03:53:19+00:00", "storage_gb": 2158.19 }
]
},
"candidates": [
{ "series_id": 1, "title": "Alpha", "codec": "H.264", "quality": "Bluray-1080p",
"size_gb": 70.0, "mb_per_min": 80.0, "target_mb_per_min": 40.0, "saving_gb": 25.0 }
],
"outliers": [
{ "series_id": 1, "title": "Alpha", "codec": "H.264", "metric": "mb_per_min",
"value": 80.0, "times_avg": 1.6, "z_score": 2.5,
"kind": "Old codec", "why": "Re-encode to HEVC frees ~25 GB" }
],
"changes": [
{ "series_id": 1, "title": "Alpha", "status": "Grown", "size_change_gb": 10.0, "episodes_change": 0 }
],
"schedule": {
"enabled": true, "frequency_hours": 24, "mode": "full",
"last_run": "2026-10-01T03:00:00+00:00", "next_run": "2026-10-02T03:00:00+00:00",
"last_status": "ok", "last_error": null
}
}

How to read it:

Field Meaning
generated_at When the server built the response. The apps show it in the Offline banner
latest_analysis The newest analysis: mode is full or fast, source is manual or scheduled, triggered_by is the username for manual runs. null with no analysis yet
metrics.*_delta Change since the previous analysis, null with only one
metrics.runway.status "ok" (the other runway fields are set: days left, best date and likely range), "not_growing" (storage isn’t growing) or "unknown" (fewer than 3 analyses over more than a day, or no disk data)
metrics.runway_with_reencode_days Days left if the candidates were re-encoded
metrics.recoverable_gb, candidate_count From the newest full analysis (fast analyses can’t estimate savings)
forecast.points Storage at each analysis, oldest first
forecast.projection Two points of the trend line: the last analysis and the runway date (or 6 months later if there’s no runway). [] without a trend
forecast.capacity_gb The capacity line of the web chart: storage now plus the free space left
candidates, outliers, changes Top 5 each, the same series in the same order as the web Dashboard. Candidates and outliers come from the newest full analysis; changes compare the last two analyses. status is New, Removed, Grown or Shrunk. metric says which unit value is in (mb_per_min or avg_size_mb); kind is Old codec or High bitrate
schedule The instance’s schedule, null if it has none. last_status is "ok", "error" or null

With no analyses yet, the response is still 200. In that case latest_analysis and schedule are null, every metric is null, runway.status is "unknown", and the lists are empty.

One series: its row in the newest analysis that includes it (a series removed from Sonarr keeps its last data), and its size at every analysis. series_id is the Sonarr series ID, as in the Dashboard lists.

{
"series_id": 3,
"title": "Gamma",
"year": "2015",
"status": "ended",
"latest": {
"date": "2026-10-01T03:00:00+00:00",
"episode_count": 10,
"size_gb": 28.0,
"avg_size_mb": 3840.0,
"mb_per_min": null,
"codec": "H.264",
"quality": "HDTV-720p",
"saving_gb": 2.0,
"target_mb_per_min": 7.5,
"z_score": -1.0,
"is_outlier": false
},
"history": [
{ "date": "2026-09-01T03:00:00+00:00", "size_gb": 30.0 },
{ "date": "2026-09-15T03:00:00+00:00", "size_gb": 29.0 },
{ "date": "2026-10-01T03:00:00+00:00", "size_gb": 28.0 }
]
}

404 if the series has no history in that instance; 422 if series_id isn’t a number. mb_per_min is null when Sonarr didn’t report runtimes. If the newest analysis that includes the series was a fast one, saving_gb is 0 and target_mb_per_min is null: estimates need a full analysis.

Complete, current examples of every response live in the app repo, in tests/fixtures/api/. The test suite checks the API against them on every change.

The apps only connect over HTTPS. The API itself also serves plain HTTP when there’s a reverse proxy in front adding HTTPS. Two setups are supported (details in Security → HTTPS):

  • Reverse proxy with a public certificate. Clients verify it as usual; no pinning.
  • SONARR_ANALYZER_TLS=self-signed. The API (and the web app) serve the app’s own certificate, which no authority vouches for. Clients pin it instead. The fingerprint is the SHA-256 of the certificate in DER form, written as 64 lowercase hex characters, the same value as openssl x509 -noout -fingerprint -sha256 without the colons. People see it in groups of four (3517 52c1 …) in My profile → Mobile devices and in the container logs. After pairing, a client should accept that exact certificate and nothing else, and ask to pair again if it changes.

Set SONARR_ANALYZER_API=0 and the container doesn’t start the API at all. Not mapping port 8502 also keeps it unreachable from outside the container.

Sonarr Analyzer v0.7.0 · GitHub · Docker Hub ·Report an issue

No trackers · MIT License · © Carlos Medina · Not affiliated with Sonarr