# REST API Endpoints This is the full endpoint reference for the unshackle REST API. It covers every route: its method and path, the request body it accepts, the response shape it returns, and the status codes it can give. This page groups the routes into general, download jobs, server management, remote sessions, and the remote services relay. Start the server with [`unshackle serve`](../../guide/cli-reference.md). By default it binds to `127.0.0.1:8786`, and every route lives under the `/api/` prefix. The [Authentication](authentication.md) page gives authentication, server modes, and the `X-Secret-Key` header in detail. Read that first if you have not already. For an end-to-end walkthrough, see the [Quickstart](quickstart.md). !!! note "Base URL" All examples below assume a base URL of `http://127.0.0.1:8786`. Replace the host and port so that they match your own `unshackle serve -h -p ` invocation. !!! tip "Interactive docs" The server mounts a live Swagger UI at **`/api/docs/`** whenever it does not operate in `--remote-only` mode. Its title is "Unshackle REST API" and its version tracks the installed package version. In API-only mode with an API key configured, the Swagger UI itself sits behind `X-Secret-Key`, like every other route. ## Conventions - **Authentication.** Every request, `GET /api/health` included, requires the `X-Secret-Key` header when you configure an API key. `--no-key` disables the check entirely. See [Authentication](authentication.md). - **Content type.** Request bodies are JSON (`Content-Type: application/json`). All success responses are JSON unless this page documents a `204 No Content`. - **CORS.** Every response carries permissive CORS headers, and the server answers `OPTIONS` preflight requests automatically. - **Compression.** JSON responses of 256 bytes or more are gzip-compressed when the client sends `Accept-Encoding: gzip`. A [slow response](remote-sessions.md#slow-responses) is not compressed. - **Service allowlist.** The effective allowlist for your API key filters the service-facing endpoints (the intersection of the global `serve.services` list and your per-key list). The server treats services you cannot use as unknown. - **Remote services.** A full-mode server can run a service through one of its own `remote_services` servers. See [Remote services relay](#remote-services-relay). !!! warning "Error responses have two shapes" Structured application errors (raised inside a handler) return `{"status": "error", "error_code": "...", "message": "...", "timestamp": "..."}`. The authentication middleware, however, returns a **different** shape: `{"status": 401, "message": "..."}` with an integer `status` and no `error_code`. The same middleware answers `429` in that shape when an API key goes over its rate limit. Clients must accept both shapes. The [Error responses](#error-responses) section at the bottom of this page gives the full error model. --- ## General endpoints These endpoints report server state and enumerate what is available. `GET /api/health`, `GET /api/services`, and `POST /api/search` are also exposed in `--remote-only` mode. ### `GET /api/health` Health check. It reports the running version and commit and a best-effort update check, so it needs the `X-Secret-Key` header like every other route. A request without an API key gets a `401`, which still shows the server is up. === "Request" ```bash curl -H "X-Secret-Key: $SECRET" http://127.0.0.1:8786/api/health ``` === "Response `200`" ```json { "status": "ok", "version": "5.3.0", "code_hash": "1d22a1e", "draining": false, "update_check": { "update_available": false, "current_version": "5.3.0", "latest_version": "5.3.0" } } ``` `code_hash` fingerprints the framework source the server operates, so it names the code itself rather than the release. It is the same value for a git checkout and for an installed package built from that checkout. It changes when you edit anything under `unshackle/core`, `unshackle/commands`, `unshackle/utils`, or `unshackle/vaults`. Service modules are not included. unshackle sets the value to `null` only when it cannot read the source files. `draining` is `true` while the server refuses new remote sessions and jobs before a restart. The server asks GitHub for the latest release at most once per [`update_check_interval`](../../reference/configuration/misc.md#caching-updates) hours and answers from its cache between checks. If the update check fails (for example, no network), `update_available` and `latest_version` are `null` while `current_version` still reports the installed version. | Status | Meaning | | --- | --- | | `200` | Server is healthy. | ### `GET /api/services` Show the streaming services available on this server, filtered by your allowlist. Each entry gives the service's tag, matching rules, capability flags, and its CLI parameters (useful when you make a UI that accepts service-specific options). For the admin key, `load_errors` lists the services the server skipped because they failed to import, at startup or after a service repository refresh; the server also writes each one to its log. Any other key gets an empty list; with `--no-key` every caller is the admin. An entry marked `pending_update` has newer code staged: it keeps its current code until its running or queued jobs and its live remote sessions finish. === "Request" ```bash curl -H "X-Secret-Key: $KEY" http://127.0.0.1:8786/api/services ``` === "Response `200`" ```json { "services": [ { "tag": "EXAMPLE", "aliases": ["EX"], "geofence": ["US"], "geoblock": [], "title_regex": "^https?://example\\.com/.+", "url": "https://example.com", "help": "EXAMPLE\nAuthorization: Cookies\nSecurity: FHD@L3", "cli_params": [ {"name": "title", "kind": "argument", "required": true}, { "name": "movie", "kind": "option", "opts": ["-m", "--movie"], "secondary_opts": [], "is_flag": true, "default": false, "help": "Title is a movie.", "type": "boolean", "multiple": false } ], "needs_auth": true, "has_search": true, "anonymous_search": false, "has_drm": true, "auth_methods": ["cookies"] } ], "load_errors": [] } ``` Field notes: | Field | Description | | --- | --- | | `tag` | Canonical service tag; use this as the `service` value on other endpoints. | | `aliases` | Alternate tags the service also answers to. | | `geofence` | Region codes the service is geofenced to (may be empty). | | `geoblock` | Region codes where the service refuses to work (may be empty). | | `title_regex` | URL/ID pattern the service matches, as a string or list of strings (or `null`). | | `url` | Service URL, taken from the service's CLI short help. | | `help` | The service module's docstring. | | `cli_params` | Array of parameter descriptors. Arguments have `{name, kind: "argument", required}`; options have `{name, kind: "option", opts, secondary_opts, is_flag, default, help, type, multiple}` and, for choice options, a `choices` list. `secondary_opts` holds the off names of a boolean flag such as `--x/--no-x`, and is empty for other options. | | `needs_auth` | Whether the service overrides `authenticate()`. | | `has_search` | Whether the service supports `POST /api/search`. | | `anonymous_search` | Whether `POST /api/search` operates with no login for this service. The server then ignores `credentials` and `cookies` on a search. | | `has_drm` | Whether the service overrides a Widevine or PlayReady license hook. | | `pending_update` | Set to `true` while a service repository refresh waits for this service's jobs to finish before it swaps in the new code. Absent otherwise. | | `server_accounts` | Present when the server lends its own accounts for this service: `{regions: ["ca", "gb"], global: bool}`, the regions those accounts cover. A client sends no credentials, cookies, or cache for such a service. | | `auth_methods` | Declared or inferred auth methods, e.g. `["cookies"]`, `["credentials"]`. | | Status | Meaning | | --- | --- | | `200` | Service list returned. | | `422` | Unexpected server error (`INTERNAL_ERROR`). | ### `POST /api/search` Find titles in a service by query string. The service must have a `search()` method (see `has_search` above). For a service with `anonymous_search`, the server does not log in and ignores `credentials` and `cookies`. The server account check still applies. **Request body** | Field | Type | Required | Default | Description | | --- | --- | --- | --- | --- | | `service` | string | yes | - | Service tag. | | `query` | string | yes | - | Search query. | | `profile` | string | no | `null` | Credential/cookie profile to use. | | `proxy` | string | no | `null` | Full proxy URI on a public host, a Control D resolver as `controld://@dns.controld.com`, or a country code when the API key has `server_proxy`. | | `no_proxy` | boolean | no | `false` | Force-disable all proxy use. | | `credentials`, `cookies`, `cache` | - | no | `null` | Your own login material, on a `--remote-only` server only. See [Client cache on a remote-only server](#client-cache-on-a-remote-only-server). | | `dl_params` | object | no | `null` | The `dl` track selection, as on [`POST /api/session/create`](remote-sessions.md#post-apisessioncreate). | === "Request" ```bash curl -X POST http://127.0.0.1:8786/api/search \ -H "X-Secret-Key: $KEY" \ -H "Content-Type: application/json" \ -d '{"service": "EXAMPLE", "query": "planet earth"}' ``` === "Response `200`" ```json { "results": [ { "id": "12345", "title": "Planet Earth", "description": "A nature documentary series.", "label": "Available", "url": "https://example.com/title/12345" } ], "count": 1 } ``` | Status | Error code | Meaning | | --- | --- | --- | | `200` | - | Search completed. | | `400` | `INVALID_PARAMETERS` | Missing `query`. | | `400` | `INVALID_SERVICE` | Unknown or disallowed service. | | `400` | `INVALID_PROXY` | Proxy could not be resolved. | | `422` | `SERVICE_ERROR` | Service failed to initialise, or does not support search. | ### `POST /api/list-titles` Get the list of titles behind a title ID, for example episodes or a movie, without downloading anything. **Request body** | Field | Type | Required | Description | | --- | --- | --- | --- | | `service` | string | yes | Service tag. | | `title_id` | string | yes | Title identifier. | | `profile` | string | no | Credential/cookie profile. | | `proxy` | string | no | Full proxy URI on a public host, a Control D resolver as `controld://@dns.controld.com`, or a country code when the API key has `server_proxy`. | | `no_proxy` | boolean | no | Force-disable proxy. | | `cdm_type` | string | no | Preferred CDM type. A request that sets one of the service's `SERVER_DEVICE_OPTIONS` ignores it: the server loads the first-listed device of its `cdm` entry. | | `credentials`, `cookies`, `cache` | - | no | Your own login material, on a `--remote-only` server only. See [Client cache on a remote-only server](#client-cache-on-a-remote-only-server). | You can also pass a service's own CLI options, in a nested `service_params` object or as additional keys. When the body has `service_params`, the server reads service options only from it. To turn off a flag such as `--x/--no-x`, send `false` under its name (`"x": false`), not under its off name. #### Logins that need the user `search`, `list-titles` and `list-tracks` have no channel to the user. A login that asks for input or waits for an approval on another device fails at once with `AUTH_FAILED` on these endpoints. Complete that login in a download job or a remote session, then send the saved login with the request. #### Client cache on a remote-only server A `--remote-only` server keeps nothing that a client sends. When the request does not use a server account, the server runs `search`, `list-titles` and `list-tracks` on a new service cache directory for that request only, and removes the directory when the request ends, on success and on error. A `--remote-only` server exposes only `search` of these three endpoints, so the rule applies to `list-titles` and `list-tracks` only if a later release exposes them in that mode. `credentials` (`{username, password, extra?}`) and `cookies` (base64 of a zlib-compressed Netscape cookie file) are the same as on [`POST /api/session/create`](remote-sessions.md#post-apisessioncreate). `cache` is a map of cache files in the same form: each cache key is the file path relative to the service cache directory, with `/` separators and no `.json` suffix, and each value is base64 of the zlib-compressed file. The server writes these files into the request cache directory before the service authenticates. When you send `credentials`, `cookies` or `cache`, a successful response also has a `cache` field in the same form, with the updated files (for example a refreshed token), but no `titles_` files. Save them to send with the next request. A request that uses a server account, or a request to a full-mode server, uses the server's own cache and returns no `cache` field. === "Request" ```bash curl -X POST http://127.0.0.1:8786/api/list-titles \ -H "X-Secret-Key: $KEY" \ -H "Content-Type: application/json" \ -d '{"service": "EXAMPLE", "title_id": "12345"}' ``` === "Response `200`" ```json { "titles": [ { "type": "episode", "name": "Pilot", "id": "ep-1", "language": "en", "description": "The first episode.", "date": "2020-01-01", "cover_url": "https://example.com/cover.jpg", "year": 2020, "series_title": "Example Show", "season": 1, "number": 1 } ] } ``` Each serialized title carries `type` (`"episode"`, `"movie"`, `"song"`, or `"other"`), `name`, `id`, `language`, `description`, `date`, and `cover_url`. Episodes and movies add `year`. Episodes also add `series_title`, `season`, and `number`. !!! info "The number that `wanted` takes for a song" A song adds `year` and its music fields, such as `artist`, `album`, `disc`, `track` and `position`. `wanted` takes `position` when it is not `null`, else `disc` and `track` as in `"2x3"`. These keys are sent only when the title carries them, so a title without them serializes exactly as before: | Key | Type | On | Meaning | | --- | --- | --- | --- | | `availability` | object | all | Optional account-scoped metadata: `paid` is a boolean describing the catalogue offer; `access` is `"granted"`, `"denied"`, or `"unknown"`. Both fields are optional; missing or unknown access is not denial. Only these allowlisted fields are forwarded, including through remote services. | | `part` | integer | episode | Part index of a [split episode](../creating-a-service.md#split-episodes), counting from 1. | | `air_date` | string | episode | ISO air date of [daily and date-based content](../../guide/downloading.md#daily-and-date-based-content). unshackle names the episode by date instead of `SxxExx`. | | `absolute` | integer | episode | Absolute episode number across all seasons. | | `daily` | boolean | episode | The episode is daily/date-based. Set from the title, or from the service's `DAILY` class attribute. | | `sport` | boolean | episode | The episode is a sports event, so it uses the `sports` output template when one is set. Sent only when true. | | `anime` | boolean | episode, movie | The title is anime, so metadata lookups prefer AniList. Set from the title, or from the service's `ANIME` class attribute. | | `metadata_provider` | string | episode, movie | The metadata provider that lookups for this title try first. Set from the title, or from the service's `METADATA_PROVIDER` class attribute. Sent only when set. | !!! info "`part` on a split episode" A service that splits one episode into several separately playable videos reports each one as its own episode. Those titles share a `season` and `number` and add a `part` integer counting from 1. No other title carries the `part` field, so a client can ignore it safely. See [Split episodes](../creating-a-service.md#split-episodes). | Status | Error code | Meaning | | --- | --- | --- | | `200` | - | Titles returned. | | `400` | `INVALID_INPUT` | Missing `service` or `title_id`. | | `400` | `INVALID_PARAMETERS` | Invalid `dl` value, such as an unknown codec in `dl_params`. | | `400` | `INVALID_SERVICE` | Unknown or disallowed service. | | `401` | `AUTH_FAILED` | Authentication with the service failed. | | `404` | `NOT_FOUND` | Title not found. | | `422` | `INTERNAL_ERROR` | Unexpected error. | ### `POST /api/list-tracks` Show the video, audio, and subtitle tracks for a title. For series, you can scope to specific episodes. Each `title` in the response has the form of a [`list-titles`](#post-apilist-titles) title, with the same service flags (`anime`, `daily`, `metadata_provider`). !!! tip "Spotting the original-language audio" Each audio track carries `is_original`, which marks the track the default `lang` of `orig` selects. unshackle finds it with the same language matcher the downloader uses. Thus it stays correct for regional variants a client cannot separate from tag text alone (`pt` marks `pt-BR` rather than `pt-PT`). Services need not report a title's language, so every track can legitimately come back `false`. **Request body** | Field | Type | Required | Description | | --- | --- | --- | --- | | `service` | string | yes | Service tag. | | `title_id` | string | yes | Title identifier. | | `wanted` | string / string[] | no | Episode/season range (e.g. `"S01E01-S01E03"`), or a song by its number in the track list (e.g. `"1-5"`, `"1,3,7"`, or `"2x3"` for disc 2 track 3). A list of selectors is accepted too. | | `season` | int/string | no | Season number (combined with `episode`). | | `episode` | int/string | no | Episode number (combined with `season`). | | `part` | int/string | no | Part index of a split episode (combined with `season` and `episode`). | | `profile`, `proxy`, `no_proxy`, `cdm_type` | - | no | As on `list-titles`. | | `credentials`, `cookies`, `cache` | - | no | As on `list-titles`. | | `dl_params` | object | no | The `dl` track selection that the service reads from `ctx.parent.params`: `lang`, `v_lang`, `a_lang`, `s_lang`, `acodec`, `forced_subs` and `exact_lang`, as on [`POST /api/session/create`](remote-sessions.md#post-apisessioncreate). Some services select the manifests they fetch from these values. | When you give both `season` and `episode`, the server combines them into a `"{season}x{episode}"` selector. `part` narrows that to `"{season}x{episode}.{part}"`, one part of a [split episode](../creating-a-service.md#split-episodes). Without `part` you get every part of the episode. The server reads `part` only when you give both `season` and `episode`, and `wanted` takes precedence over all three. To scope a part by range, put it in `wanted` instead (`"S01E01.2"`). === "Single title / movie: Response `200`" ```json { "title": { "type": "movie", "name": "Example Movie", "id": "12345", "year": 2021 }, "video": [ { "id": "v-1", "codec": "HEVC", "codec_display": "H.265", "bitrate": 8000, "bitrate_bps": 8000000, "width": 3840, "height": 2160, "resolution": "2160p", "fps": "24", "range": "HDR10", "range_display": "HDR", "scan_type": null, "closed_captions": [], "dv_compatible_bitstream": false, "hdr10plus": false, "hdr10_base": false, "hlg_base": false, "stereo": false, "language": "en", "is_original_lang": true, "name": null, "track_name": "English", "needs_repack": false, "edition": [], "note": null, "data": null, "drm": [], "descriptor": "DASH" } ], "audio": [ { "id": "a-1", "codec": "EC3", "codec_display": "DDP", "bitrate": 640, "bitrate_bps": 640000, "channels": "5.1", "language": "en", "is_original": true, "is_original_lang": true, "atmos": false, "joc": 0, "descriptive": false, "bit_depth": null, "sample_rate": 48000, "name": null, "track_name": "English", "needs_repack": false, "edition": [], "note": null, "data": null, "drm": [], "descriptor": "DASH" } ], "subtitles": [ { "id": "s-1", "codec": "vtt", "language": "en", "forced": false, "sdh": false, "cc": false, "is_original_lang": false, "name": null, "track_name": "English", "needs_repack": false, "edition": [], "note": null, "data": null, "drm": [], "descriptor": "DASH" } ] } ``` === "Multiple episodes: Response `200`" ```json { "episodes": [ { "title": { "type": "episode", "name": "Pilot", "id": "ep-1", "season": 1, "number": 1 }, "video": [ ... ], "audio": [ ... ], "subtitles": [ ... ] } ], "unavailable_episodes": [ { "title": { "id": "ep-2" }, "error": "..." } ] } ``` The server sorts tracks by bitrate, descending. Episodes the server cannot get go into `unavailable_episodes`, rather than failing the whole request. Track objects here do **not** include a download `url`. Only the remote session endpoints give segment URLs. The `drm` array on a track is a list of `{type, pssh?, kids?, content_keys?, license_url?}` objects. Only a `widevine`, `playready` or `clearkeycenc` entry carries `content_keys`. Every track carries the same fields as a local track: `is_original_lang`, `name`, `needs_repack`, `edition`, `note`, and `data`. `name` is the name the service set, or null. `note` is display text the service set, such as an encoding profile, or null: `--list` shows it, but the filename and the mux do not use it. `track_name` is the name `--list` shows and the mux writes to an audio or subtitle track: `name` when the service set one, else the name of the language (English, or in the language itself when the server sets `muxing.track_names: native`, or no name when it sets `none`), then the server's `muxing.original_label` on an original-language track, then the SDH, CC, Forced or Descriptive label. `bitrate` is in kb/s, and `bitrate_bps` gives the exact bits/s. `data` holds the part of the service-set `track.data` that fits in JSON, without the `hls`, `dash`, and `ism` parser keys. Audio keeps `is_original` and `atmos` for clients that read them, and adds the exact `joc` object count. Audio `bit_depth` and `sample_rate` (Hz) are integers, or null when the manifest and the service do not give them. | Status | Error code | Meaning | | --- | --- | --- | | `200` | - | Tracks returned. | | `400` | `INVALID_INPUT` | Missing `service` or `title_id`. | | `400` | `INVALID_PARAMETERS` | Invalid `wanted` range, or an invalid `dl` value. | | `400` | `INVALID_SERVICE` | Unknown or disallowed service. | | `404` | `NO_CONTENT` | No matching episodes, or all matches failed. | --- ## Download jobs Downloads are asynchronous. `POST /api/download` enqueues a job and returns immediately with a `job_id`. The server runs each job in a background job worker subprocess. You then poll the job endpoints for progress and results. !!! info "Job states" A job moves through `queued` → `downloading` → one of the terminal states `completed`, `failed`, or `cancelled`. You can prioritise only queued jobs. You can retry or remove only terminal jobs. When the server stops, it cancels each queued and downloading job and refuses a new job with `SERVER_DRAINING` (409). ### `POST /api/download` Make a download job. It requires `service` and `title_id`. Every other field is an optional download parameter with a server-side default. On success this returns **`202 Accepted`**, not `200`. === "Request" ```bash curl -X POST http://127.0.0.1:8786/api/download \ -H "X-Secret-Key: $KEY" \ -H "Content-Type: application/json" \ -d '{ "service": "EXAMPLE", "title_id": "12345", "quality": [2160], "vcodec": "HEVC", "range": ["HDR10"], "wanted": ["S01E01"] }' ``` === "Response `202`" ```json { "job_id": "b0f7c8e2-4a1d-4e9c-9b7e-2f3a1c0d5e6f", "status": "queued", "created_time": "2026-07-03T12:00:00+00:00" } ``` **Request body.** Every field except `service` and `title_id` is optional. The `dl` fields mirror the flags of the [`dl` command](../../guide/cli-reference.md#dl). This table comes from the OpenAPI description that `/api/docs/` of a running server also shows. **Validation.** Invalid values return `400 INVALID_PARAMETERS`. `vcodec`, `acodec` and `sub_format` take the same spellings as the CLI options of the same name (`unshackle dl --help` prints each list). The API and the CLI read one list, so they cannot disagree. `range` must be one of SDR/HDR10/HDR10P/VIVID/DV/HLG/HYBRID, and `HDR10+` and `HDR Vivid` are also valid. The bitrate, download worker, and download counts must be positive integers. You cannot combine `no_subs` with `subs_only`, or `no_audio` with `audio_only`. The server runs the same option checks as `unshackle dl`, so a request that `dl` would refuse returns `400` when you submit it, and the message names the `dl` option. The language fields (`lang`, `v_lang`, `a_lang`, `s_lang`, `forced_s_lang` and the `require_*` fields) must be arrays of strings: a single string such as `"en"` returns `400`. The server checks every other field with the type of its `dl` option. A `null` or an empty string gets the default from the table. **Service options.** A service's own CLI options travel in the same body. Send them in a nested `service_params` object, or as flat top-level keys. When the body has `service_params`, the server reads service options only from it, and every flat key is a `dl` value. A name in `service_params` can be the option's flag, such as `zone` for `--zone`, or its parameter name. Without `service_params`, a flat key that is also a `dl` option, such as `quality` or `lang`, stays a `dl` value, and the server logs a warning when the service has an option of the same name. An option you leave out takes the default declared on the service's `cli` command, so the job matches the equivalent `dl` run. The server checks each service option against that option's type, and a value it refuses gets `400 INVALID_PARAMETERS`. `profile` at the top level always means the credential profile, never a service's own `--profile` option. === "Request" ```bash curl -X POST http://127.0.0.1:8786/api/download \ -H "X-Secret-Key: $KEY" \ -H "Content-Type: application/json" \ -d '{ "service": "EXAMPLE", "title_id": "12345", "quality": [2160], "service_params": {"device": "chrome", "movie": true} }' ``` !!! danger "Rejected parameters" `postscript`, `post_script` and `post_scripts` are never accepted. A body containing any of them gets `400 INVALID_PARAMETERS`, because a command string that arrives from an HTTP caller would be remote code execution. You configure post-scripts only in `unshackle.yaml`, where they still operate for API jobs. See [Post-scripts](../../reference/configuration/post-scripts.md). !!! warning "Gated parameters (developer)" The server accepts a few keys, but permits them only when the server config opts in. Otherwise the server rejects the request with `403 FORBIDDEN`: - `cdm` (per-request CDM device name): allowed only if `serve.cdm_overrides` is `true` or a list containing that device name. - `credential` (`"user:pass"`) and `credentials` (a map): allowed only if `serve.allow_job_credentials` is truthy (off by default). On the server, unshackle merges the effective parameters in this order: defaults → `serve:` config overrides → service-specific defaults → your request body. The server checks each `serve:` and `services..dl` value that a job uses with the rules of a request body. A bad value refuses the job with `400 INVALID_PARAMETERS`, and the message starts with the config block, for example `serve: workers must be a positive integer`. A value that your request body replaces is not checked. | Status | Error code | Meaning | | --- | --- | --- | | `202` | - | Job queued. | | `400` | `INVALID_INPUT` | Missing `service`/`title_id` or malformed JSON. | | `400` | `INVALID_PARAMETERS` | A parameter failed validation. | | `400` | `INVALID_SERVICE` | Unknown or disallowed service. | | `403` | `FORBIDDEN` | A gated parameter is not permitted. | | `403` | `SERVER_CDM_CAPPED` | The API key has a `server_cdm_max_height` for the service, and the job has no `quality` at or under it, sets `best_available`, or has `HYBRID` in `range`. | ### `GET /api/download/jobs` Show download jobs, with optional filtering and sorting. **Query parameters** | Param | Values | Default | Description | | --- | --- | --- | --- | | `status` | `queued`, `downloading`, `completed`, `failed`, `cancelled` | - | Filter by status. | | `service` | service tag | - | Filter by service. | | `sort_by` | `created_time`, `started_time`, `completed_time`, `progress`, `status`, `service` | `created_time` | Sort field. | | `sort_order` | `asc`, `desc` | `desc` | Sort direction. | | `full` | `true`, `false` | `false` | Include full per-job details. | === "Request" ```bash curl -H "X-Secret-Key: $KEY" \ "http://127.0.0.1:8786/api/download/jobs?status=downloading&sort_by=progress&sort_order=desc" ``` === "Response `200`" ```json { "jobs": [ { "job_id": "b0f7c8e2-...", "status": "downloading", "created_time": "2026-07-03T12:00:00+00:00", "service": "EXAMPLE", "title_id": "12345", "title": "Example Show S01E01", "progress": 42.5, "phase": "downloading", "current_title": "Episode 1", "completed_tracks": 1, "total_tracks": 3, "active_tracks": ["v-1"], "track_progress": [{"label": "Video", "progress": 42.5, "speed": "5.2 MB/s"}], "segments_done": 120, "segments_total": 300, "speed": "5.2 MB/s", "skipped_subtitles": [], "skipped_titles": [], "already_present": [], "input_prompt": null, "notice": null, "qr": null } ] } ``` With `full=true`, each job additionally includes `parameters` (with secrets redacted), `started_time`, `completed_time`, `output_files`, `error_message`, `error_details`, and `error_code`. When you start the server with `--debug-api`, each job also includes `error_traceback` and `worker_stderr`. | Status | Error code | Meaning | | --- | --- | --- | | `200` | - | Jobs returned. | | `400` | `INVALID_PARAMETERS` | Invalid `sort_by` or `sort_order`. | ### `GET /api/download/jobs/{job_id}` Fetch a single job with full details (equivalent to a `full=true` list entry). | Status | Error code | Meaning | | --- | --- | --- | | `200` | - | Job returned. | | `404` | `JOB_NOT_FOUND` | No such job. | ### `GET /api/download/jobs/{job_id}/events` Stream the job's progress as [Server-Sent Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events). Use this instead of polling `GET /api/download/jobs/{job_id}`. The response has the content type `text/event-stream`. Each event has this format: ``` event: data: ``` The `data` field of every event is the same job object that `GET /api/download/jobs/{job_id}` returns. | Event | When it is sent | | --- | --- | | `snapshot` | Immediately, as the first event. Gives the job's current state. | | `status` | The job leaves the queue and starts to download. | | `progress` | The worker's progress record changed. The server reads that record every 0.5 seconds, so you get at most two of these events each second, and none while the record stays the same. | | `completed` | The job finished. The server then closes the event stream. | | `failed` | The job failed. The server then closes the event stream. | | `cancelled` | The job was cancelled. The server then closes the event stream. | The server sends a `: keep-alive` comment each 15 seconds while the job is quiet, to keep proxies from closing an idle connection. Ignore these lines. If the job is already in a terminal state, the server sends the `snapshot` event, then the terminal event, and closes the event stream immediately. !!! tip "Authentication from a browser" `EventSource` cannot set headers. For this endpoint only, the server also accepts the API key in the `secret_key` query parameter. This works in both server modes, the default integrated server and `--api-only`: ```javascript const events = new EventSource( `http://127.0.0.1:8786/api/download/jobs/${jobId}/events?secret_key=${key}` ); events.addEventListener("progress", (e) => console.log(JSON.parse(e.data).progress)); events.addEventListener("completed", () => events.close()); ``` The header always wins. Send the API key in the query parameter *or* in the header, not both. If an `X-Secret-Key` header is present, the server examines that header and ignores the query parameter. See [Authentication](authentication.md#how-clients-present-credentials). === "Request" ```bash curl -N -H "X-Secret-Key: $KEY" \ "http://127.0.0.1:8786/api/download/jobs/b0f7c8e2-.../events" ``` === "Response `200`" ``` event: snapshot data: {"job_id":"b0f7c8e2-...","status":"downloading","progress":42.5,...} event: progress data: {"job_id":"b0f7c8e2-...","status":"downloading","progress":48.0,...} : keep-alive event: completed data: {"job_id":"b0f7c8e2-...","status":"completed","progress":100.0,...} ``` | Status | Error code | Meaning | | --- | --- | --- | | `200` | - | Event stream started. | | `404` | `JOB_NOT_FOUND` | No such job. | ### `DELETE /api/download/jobs/{job_id}` Cancel or remove a job. The behaviour depends on the job's current state: - **Terminal job** (completed/failed/cancelled): removed from the manager, returning **`204 No Content`** with an empty body. - **Queued or downloading job**: cancelled, returning `200` `{"status": "success", "message": "Job cancelled"}`. !!! warning A `204` response has no body. Do not try to parse JSON from it. | Status | Error code | Meaning | | --- | --- | --- | | `200` | - | Job cancelled. | | `204` | - | Terminal job removed (empty body). | | `400` | `INVALID_PARAMETERS` | Job is in a state that cannot be cancelled. | | `404` | `JOB_NOT_FOUND` | No such job. | ### `POST /api/download/jobs/clear-finished` Remove every terminal (completed/failed/cancelled) job from the manager. No request body. === "Response `200`" ```json { "removed": 3 } ``` ### `POST /api/download/jobs/{job_id}/retry` Enqueue a **new** job from the request that made a terminal job. The request goes through the same checks as a new submission: the service allowlist, the parameter checks and the download gates. A parameter that the request did not send takes the server default of the time of the retry. Returns `202` with the new job's ID. !!! warning "Retry reuses the original, unredacted parameters" A retry sends again the parameters that the original client submitted, including any secrets such as `credential`/`credentials`. It does not use the redacted `parameters` view that `GET /api/download/jobs` and `GET /api/history` give. This is deliberate: it lets a retried job reproduce a credentialed download that the redacted job record alone never could. The API masks those credentials everywhere else. But anyone who can retry a job can operate it again with the original credentials. === "Response `202`" ```json { "job_id": "9c1e2f3a-...", "status": "queued", "created_time": "2026-07-03T12:05:00+00:00" } ``` | Status | Error code | Meaning | | --- | --- | --- | | `202` | - | New job queued. | | `404` | `JOB_NOT_FOUND` | No such job. | | `409` | `CONFLICT` | Job is not in a terminal state. | | `400` | `INVALID_SERVICE` | Service is no longer allowed. | | `400` | `INVALID_PARAMETERS` | A parameter no longer passes the checks, for example an `output_dir` outside a moved downloads directory. | | `403` | `FORBIDDEN` | A gated parameter is no longer permitted. | | `403` | `SERVER_CDM_CAPPED` | The job is no longer inside the `server_cdm_max_height` of the API key. | ### `POST /api/download/jobs/{job_id}/priority` Move a queued job to the front of the download queue. === "Response `200`" ```json { "job_id": "b0f7c8e2-...", "position": "front" } ``` | Status | Error code | Meaning | | --- | --- | --- | | `200` | - | Job moved to front. | | `404` | `JOB_NOT_FOUND` | No such job. | | `409` | `CONFLICT` | Job is not queued. | ### `POST /api/download/jobs/{job_id}/input` Answer the prompt that a running job waits on. A service can ask for input during a job, for example an OTP code, a PIN, or a device-code confirmation. The job then shows the prompt in its `input_prompt` field and in its `progress` events. Show the prompt to the user and send the answer here. A job that waits for an approval on another device, such as a pair code login, shows the message in its `notice` field instead. A notice needs no answer: show it to the user and keep polling. When the login is a QR code to scan, the job also sets `qr` to the text of the code: draw it as a QR code beside the prompt or notice. === "Request" ```json { "response": "123456" } ``` === "Response `200`" ```json { "status": "accepted" } ``` | Status | Error code | Meaning | | --- | --- | --- | | `200` | - | Answer sent to the job. The `input_prompt` field goes back to `null`. | | `400` | `INVALID_INPUT` | The body is not JSON, or it has no `response`. | | `404` | `JOB_NOT_FOUND` | No such job. | | `409` | `CONFLICT` | The job does not wait on a prompt. | !!! warning The job keeps its download slot while it waits. It fails with `AUTH_FAILED` if nobody answers the prompt within 10 minutes. --- ## Server management Endpoints for profiles, effective configuration, download history, environment checks, and maintenance actions. ### `GET /api/profiles` Show the named credential profiles configured per service (usable as the `profile` parameter elsewhere). The response holds only services whose credentials are a mapping of profile name to credential. It leaves out services with a single unnamed credential. Your allowlist filters the response. === "Response `200`" ```json { "profiles": { "EXAMPLE": ["default", "premium"], "OTHER": ["us-account"] } } ``` ### `GET /api/config` Return a read-only, redacted view of the effective server configuration, suitable for a settings page in a UI. The server never sends secrets: it masks every config key whose name looks like a secret (`secret`, `password`, `passwd`, `token`, `api_key`, `credential`, `auth`, `cookie`, `bearer`, `private`) and any userinfo in proxy URLs. The `directories` block holds the server's absolute paths and reaches only an admin key (`admin: true` or the `api_secret`); a plain key gets the response without it. === "Response `200`" ```json { "config": { "dl": { "...": "redacted default dl parameters" }, "serve": { "max_concurrent_downloads": 2, "job_retention_hours": 24, "history_limit": 100, "services": null, "remote_only": false, "cdm_overrides": null, "allow_job_credentials": false }, "directories": { "downloads": "/home/user/Downloads/unshackle", "temp": "/home/user/.unshackle/temp", "cache": "/home/user/.unshackle/cache" }, "services": ["EXAMPLE", "OTHER"] } } ``` ### `GET /api/history` Read the persisted history of jobs that reached a terminal state, newest first. Each API key sees only the jobs it submitted, plus entries written before the history recorded an owner. The same rule applies to `DELETE /api/history/{job_id}` and `POST /api/download/jobs/clear-finished`. unshackle stores the history in `api_history.jsonl` in the cache directory. It skips corrupt lines, and a missing file yields an empty list. **Query parameters** | Param | Type | Default | Description | | --- | --- | --- | --- | | `limit` | int (≥ 1) | `100` | Maximum entries to return. | | `service` | string | - | Case-insensitive service filter. | === "Response `200`" ```json { "history": [ { "job_id": "b0f7c8e2-...", "service": "EXAMPLE", "title_id": "12345", "title": "Example Show S01E01", "status": "completed", "created_time": "2026-07-03T12:00:00+00:00", "completed_time": "2026-07-03T12:08:00+00:00", "output_files": ["/downloads/Example.S01E01.mkv"], "skipped_titles": [], "already_present": [], "error_message": null, "parameters": { "...": "redacted" } } ], "count": 1 } ``` | Status | Error code | Meaning | | --- | --- | --- | | `200` | - | History returned. | | `400` | `INVALID_PARAMETERS` | Invalid `limit`. | `already_present` lists completion-archive skips separately from newly produced `output_files` and missing-track `skipped_titles`. Each entry contains `service`, `title_id`, `title`, `reason: "already_present"`, and `variants` (objects with `quality`, `range`, `codec`). The same field is present in job progress/details. A job with only archive matches completes successfully. The archive is independent of history retention, isolated per API key, and has no inventory endpoint. ### `DELETE /api/history/{job_id}` Remove a single persisted history entry. Returns **`204 No Content`** (empty body) on success. | Status | Error code | Meaning | | --- | --- | --- | | `204` | - | Entry removed (empty body). | | `404` | `NOT_FOUND` | No such entry (or outside your allowlist). | ### `POST /api/maintenance/clear-cache` and `POST /api/maintenance/clear-temp` Delete and recreate the cache or temp directory. Both, and refresh-services, need `admin: true` on the API key or the `api_secret` itself; any other key gets `403 FORBIDDEN`. Neither takes a request body. The server blocks both with `409 CONFLICT` if any job is currently `downloading` (the `details` include the offending `active_jobs`). The `409` guard is about active file I/O, not an arbitrary lock. An in-flight job may still be *reading* cached title data under the cache directory, and active download workers are *writing* segment files under temp. The removal of either directory mid-download would corrupt those jobs, so the endpoints refuse while a download is in progress. !!! warning "clear-cache also wipes download history" The persistent history read by [`GET /api/history`](#get-apihistory) lives in `api_history.jsonl` **inside the cache directory**. Because clear-cache deletes and recreates that whole directory, calling it also erases your entire download history, not only cached title data. If you want to keep history, do not clear the cache. Remove individual entries with [`DELETE /api/history/{job_id}`](#delete-apihistoryjob_id) instead. === "Response `200`" ```json { "cleared": true, "freed_bytes": 1048576 } ``` | Status | Error code | Meaning | | --- | --- | --- | | `200` | - | Directory cleared. | | `409` | `CONFLICT` | A download is currently active. | ### `POST /api/maintenance/refresh-services` git-pull every service repository configured under `directories.services` and re-import the services that changed, without a restart. `refreshed` becomes `true` when all repos updated successfully, or when you configure no repository. `deferred` lists the services that have a running or queued job: they keep their current code until that job finishes, then swap. `load_errors` lists the services whose new code failed to import; the server drops them until the next successful refresh. === "Response `200`" ```json { "refreshed": true, "repos": [ { "spec": "github.com/example/services", "updated": true, "changes": ["~EXAMPLE", "+EXAMPLE2"], "deferred": ["EXAMPLE"], "load_errors": [] } ] } ``` ### `GET /api/env/check` Report the install status of the external binaries unshackle depends on (the same set `unshackle env check` inspects), with best-effort version detection. === "Response `200`" ```json { "checks": [ { "name": "ffmpeg", "installed": true, "version": "6.1.1", "required": true }, { "name": "ccextractor", "installed": false, "version": null, "required": false } ] } ``` --- ## Remote sessions The `/api/session/*` and `/api/tunnel` routes carry the remote sessions of `dl --remote`. The [remote session protocol](remote-sessions.md) page is their reference: each route, its request and response, the login states, the licensing modes and the error codes. ## Remote services relay A full-mode server can run a service through one of its own `remote_services` servers. `GET /api/config` lists their names in `remote_services`, and `GET /api/services?remote=` lists the services of that server, each with `remote` set to the name. Add `"remote": ""` to `POST /api/search`, `/api/list-titles`, `/api/list-tracks` or `/api/download`, and the server opens a remote session with its own API key for that server: the remote server logs in and resolves titles, tracks and licences, and a download still runs, decrypts and muxes here. The tag may be any case or an alias, and your allowlist applies to it. A `--remote-only` server does not relay. - An unknown name is `400 INVALID_PARAMETERS`, a server that does not answer is `SERVICE_UNAVAILABLE`, a server that rejects the API key of this server is `AUTH_FAILED` (424), and a tag that it does not offer is `INVALID_SERVICE`. - List calls from the same API key for the same title, profile, proxy, client region and service options share one remote session, which closes after 120 seconds unused. - When the server stops, a list call that waits on the login of a new remote session, or starts one, gets `SERVER_DRAINING` (409). A call that opens a lost remote session again can be cut too: `list-titles` then gets `SERVER_DRAINING`, and `list-tracks` that or `SERVICE_ERROR` (422). - An optional `client_name` names your client on the dashboard of the remote server as `serve ()`. - A relayed search opens no remote session. The server sends its own credentials, cookies and cache for the `profile` with the search. A service that searches with no login gets none of them. A remote login that waits on you (a pair code or URL to approve on another device, or a question such as an OTP) cannot answer through a list call. Poll `GET /api/remote/logins` beside it. A remote download job shows the same text as its own `notice`, and asks a question through `input_prompt` as a local job does. ### `GET /api/remote/logins` The logins of your list calls that wait on a remote server. An admin key sees the logins of every API key. === "Response `200`" ```json { "logins": [ { "id": "3f2a9c...", "remote": "my_server", "service": "EXAMPLE", "title_id": "0ABCDEF", "prompt": null, "notice": "Open https://example.com/activate and enter ABCD-1234", "qr": "https://example.com/activate?code=ABCD-1234" } ] } ``` | Field | Description | | --- | --- | | `id` | The ID to answer the prompt with. | | `remote`, `service`, `title_id` | The remote server, the service and the title of the list call. | | `prompt` | What the login asks you (an OTP, a PIN), or `null`. | | `notice` | What the login shows you while it waits, such as a URL and a pair code, or `null`. | | `qr` | The text of a QR code to scan with the prompt or notice, or `null`. | ### `POST /api/remote/logins/{login_id}/input` Answer the prompt of a remote login. Body: `{ "response": "..." }` (required). === "Response `200`" ```json { "status": "accepted" } ``` | Status | Error code | Meaning | | --- | --- | --- | | `200` | - | Answer accepted. | | `400` | `INVALID_INPUT` | No `response`. | | `404` | `NOT_FOUND` | No such remote login for this API key. | | `409` | `CONFLICT` | The login asks nothing now. | --- ## Error responses The server serialises every structured error raised inside a handler to the same JSON envelope: ```json { "status": "error", "error_code": "INVALID_PARAMETERS", "message": "Invalid video codec: XYZ", "timestamp": "2026-07-03T12:00:00+00:00", "details": { "field": "vcodec" }, "retryable": true, "debug_info": { "exception_type": "APIError", "traceback": "..." } } ``` - `details` appears only when non-empty. - `retryable` appears only when the error is retryable (e.g. network errors, rate limiting). - `debug_info` appears only when you start the server with `--debug-api`. !!! warning "Authentication errors differ" Errors raised by the API-key middleware use a distinct shape (`{"status": 401, "message": "Secret Key is Empty."}`, `{"status": 401, "message": "Secret Key is Invalid."}`, or `{"status": 429, "message": "Rate limit exceeded."}` with a `Retry-After` header) with an integer `status` and no `error_code`, `timestamp`, or `details`. A `429` from the middleware therefore carries no `error_code`, unlike the `RATE_LIMITED` code below, which a handler raises for a rate limit the *service* imposed. A malformed JSON body on any POST, by contrast, returns the standard envelope with `error_code: "INVALID_INPUT"`. ### Error codes and default status The [error code catalogue](errors.md#error-code-catalogue) gives the default HTTP status of each error code. When a generic (uncategorized) exception reaches a handler, unshackle inspects its message and type to pick a code. For example, messages mentioning "connection" or "timeout" become `NETWORK_ERROR` (424, retryable), "rate limit" or "429" become `RATE_LIMITED` (429, retryable), and anything unrecognized collapses to `INTERNAL_ERROR` (422). --- ## See also - [REST API overview](index.md). What the server is and when to use it. - [Authentication](authentication.md). Keys, server modes, and the `X-Secret-Key` header. - [Quickstart](quickstart.md). A first end-to-end request walkthrough. - [CLI reference: `dl`](../../guide/cli-reference.md#dl). The `dl` flags mirrored by `POST /api/download`.