2023-10-28 13:51:20 +01:00
# cobalt api documentation
2024-09-04 17:28:39 +01:00
this document provides info about methods and acceptable variables for all cobalt api requests.
2023-06-05 07:43:04 +01:00
2024-09-04 17:28:39 +01:00
<!-- TODO: authorization -->
2023-10-28 13:51:20 +01:00
2024-09-04 17:28:39 +01:00
## POST: `/`
cobalt's main processing endpoint.
2023-10-28 13:51:20 +01:00
2024-09-04 17:28:39 +01:00
request body type: `application/json`
response body type: `application/json`
2023-06-05 07:43:04 +01:00
```
2024-09-04 17:28:39 +01:00
⚠️ you must include Accept and Content-Type headers with every `POST /` request.
2023-06-05 07:43:04 +01:00
2023-10-28 13:51:20 +01:00
Accept: application/json
Content-Type: application/json
```
2022-11-12 16:40:11 +00:00
2024-09-04 17:28:39 +01:00
### request body
| key | type | expected value(s) | default | description |
|:-----------------------------|:----------|:-----------------------------------|:----------|:--------------------------------------------------------------------------------|
2024-09-04 17:30:02 +01:00
| `url` | `string` | URL to download | -- | **must** be included in every request. |
2024-09-04 17:28:39 +01:00
| `videoQuality` | `string` | `144 / ... / 2160 / 4320 / max` | `1080` | `720` quality is recommended for phones. |
| `audioFormat` | `string` | `best / mp3 / ogg / wav / opus` | `mp3` | |
| `audioBitrate` | `string` | `320 / 256 / 128 / 96 / 64 / 8` | `128` | specifies the bitrate to use for the audio. applies only to audio conversion. |
| `filenameStyle` | `string` | `classic / pretty / basic / nerdy` | `classic` | changes the way files are named. previews can be seen in the web app. |
| `downloadMode` | `string` | `auto / audio / mute` | `auto` | `audio` downloads only the audio, `mute` skips the audio track in videos. |
| `youtubeVideoCodec` | `string` | `h264 / av1 / vp9` | `h264` | `h264` is recommended for phones. |
| `youtubeDubLang` | `string` | `en / ru / cs / ja / ...` | -- | specifies the language of audio to download, when the youtube video is dubbed |
| `youtubeDubBrowserLang` | `boolean` | `true / false` | `false` | uses value from the Accept-Language header for `youtubeDubLang` . |
| `alwaysProxy` | `boolean` | `true / false` | `false` | tunnels all downloads through the processing server, even when not necessary. |
| `disableMetadata` | `boolean` | `true / false` | `false` | disables file metadata when set to `true` . |
| `tiktokFullAudio` | `boolean` | `true / false` | `false` | enables download of original sound used in a tiktok video. |
| `tiktokH265` | `boolean` | `true / false` | `false` | changes whether 1080p h265 videos are preferred or not. |
| `twitterGif` | `boolean` | `true / false` | `true` | changes whether twitter gifs are converted to .gif |
### response
the response will always be a JSON object containing the `status` key, which will be one of:
- `error` - something went wrong
- `picker` - we have multiple items to choose from
- `redirect` - you are being redirected to the direct service URL
2024-09-04 19:26:48 +01:00
- `tunnel` - cobalt is proxying the download for you
2024-09-04 17:28:39 +01:00
2024-09-04 19:26:48 +01:00
### tunnel/redirect response
2024-09-04 17:28:39 +01:00
| key | type | values |
|:-------------|:---------|:------------------------------------------------------------|
2024-09-04 19:26:48 +01:00
| `status` | `string` | `tunnel / redirect` |
| `url` | `string` | url for the cobalt tunnel, or redirect to an external link |
2024-09-07 13:26:40 +01:00
| `filename` | `string` | cobalt-generated filename for the file being downloaded |
2024-09-04 17:28:39 +01:00
### picker response
2024-09-07 13:26:40 +01:00
| key | type | values |
|:----------------|:---------|:-------------------------------------------------------------------------------------------------|
| `status` | `string` | `picker` |
| `audio` | `string` | **optional** returned when an image slideshow (such as on tiktok) has a general background audio |
| `audioFilename` | `string` | **optional** cobalt-generated filename, returned if `audio` exists |
| `picker` | `array` | array of objects containing the individual media |
2024-09-04 17:28:39 +01:00
#### picker object
| key | type | values |
|:-------------|:----------|:------------------------------------------------------------|
| `type` | `string` | `photo` / `video` / `gif` |
| `url` | `string` | |
| `thumb` | `string` | **optional** thumbnail url |
### error response
| key | type | values |
|:-------------|:---------|:------------------------------------------------------------|
| `status` | `string` | `error` |
| `error` | `object` | contains more context about the error |
#### error object
| key | type | values |
2023-10-28 13:51:20 +01:00
|:-------------|:---------|:------------------------------------------------------------|
2024-09-04 17:28:39 +01:00
| `code` | `string` | machine-readable error code explaining the failure reason |
| `context` | `object` | **optional** container for providing more context |
#### error.context object
| key | type | values |
|:-------------|:---------|:---------------------------------------------------------------------------------------------------------------|
| `service` | `string` | **optional** , stating which service was being downloaded from |
| `limit` | `number` | **optional** number providing the ratelimit maximum number of requests, or maximum downloadable video duration |
## GET: `/`
returns current basic server info.
2023-10-28 13:51:20 +01:00
response body type: `application/json`
2023-06-07 16:41:06 +01:00
2024-09-04 17:28:39 +01:00
### response body
| key | type | variables |
|:------------|:---------|:---------------------------------------------------------|
| `cobalt` | `object` | information about the cobalt instance |
| `git` | `object` | information about the codebase that is currently running |
#### cobalt object
| key | type | description |
|:----------------|:-----------|:-----------------------------------------------|
| `version` | `string` | current version |
| `url` | `string` | server url |
| `startTime` | `string` | server start time in unix milliseconds |
| `durationLimit` | `number` | maximum downloadable video length in seconds |
| `services` | `string[]` | array of services which this instance supports |
#### git object
2023-10-28 13:51:20 +01:00
| key | type | variables |
|:------------|:---------|:------------------|
2024-09-04 17:28:39 +01:00
| `commit` | `string` | commit hash |
2023-10-28 13:51:20 +01:00
| `branch` | `string` | git branch |
2024-09-04 17:28:39 +01:00
| `remote` | `string` | git remote |