|
| 1 | +# cobalt api instance environment variables |
| 2 | +you can customize your processing instance's behavior using these environment variables. all of them but `API_URL` are optional. |
| 3 | +this document is not final and will expand over time. feel free to improve it! |
| 4 | + |
| 5 | +### general vars |
| 6 | +| name | default | value example | |
| 7 | +|:--------------------|:----------|:--------------------------------------| |
| 8 | +| API_URL | | `https://api.url.example/` | |
| 9 | +| API_PORT | `9000` | `1337` | |
| 10 | +| COOKIE_PATH | | `/cookies.json` | |
| 11 | +| PROCESSING_PRIORITY | | `10` | |
| 12 | +| API_INSTANCE_COUNT | | `6` | |
| 13 | +| API_REDIS_URL | | `redis://localhost:6379` | |
| 14 | +| DISABLED_SERVICES | | `bilibili,youtube` | |
| 15 | + |
| 16 | +[*view details*](#general) |
| 17 | + |
| 18 | +### networking vars |
| 19 | +| name | default | value example | |
| 20 | +|:--------------------|:----------|:--------------------------------------| |
| 21 | +| API_LISTEN_ADDRESS | `0.0.0.0` | `127.0.0.1` | |
| 22 | +| API_EXTERNAL_PROXY | | `http://user:[email protected]:8080` | |
| 23 | +| FREEBIND_CIDR | | `2001:db8::/32` | |
| 24 | + |
| 25 | +[*view details*](#networking) |
| 26 | + |
| 27 | +### limit vars |
| 28 | +| name | default | value example | |
| 29 | +|:-------------------------|:--------|:--------------| |
| 30 | +| DURATION_LIMIT | `10800` | `18000` | |
| 31 | +| TUNNEL_LIFESPAN | `90` | `120` | |
| 32 | +| RATELIMIT_WINDOW | `60` | `120` | |
| 33 | +| RATELIMIT_MAX | `20` | `30` | |
| 34 | +| SESSION_RATELIMIT_WINDOW | `60` | `60` | |
| 35 | +| SESSION_RATELIMIT | `10` | `10` | |
| 36 | + |
| 37 | +[*view details*](#limits) |
| 38 | + |
| 39 | +### security vars |
| 40 | +| name | default | value example | |
| 41 | +|:------------------|:--------|:--------------------------------------| |
| 42 | +| CORS_WILDCARD | `1` | `0` | |
| 43 | +| CORS_URL | | `https://web.url.example` | |
| 44 | +| TURNSTILE_SITEKEY | | `1x00000000000000000000BB` | |
| 45 | +| TURNSTILE_SECRET | | `1x0000000000000000000000000000000AA` | |
| 46 | +| JWT_SECRET | | see [details](#security) | |
| 47 | +| JWT_EXPIRY | `120` | `240` | |
| 48 | +| API_KEY_URL | | `file://keys.json` | |
| 49 | +| API_AUTH_REQUIRED | | `1` | |
| 50 | + |
| 51 | +[*view details*](#security) |
| 52 | + |
| 53 | +### service-specific vars |
| 54 | +| name | value example | |
| 55 | +|:---------------------------------|:-------------------------| |
| 56 | +| CUSTOM_INNERTUBE_CLIENT | `IOS` | |
| 57 | +| YOUTUBE_SESSION_SERVER | `http://localhost:8080/` | |
| 58 | +| YOUTUBE_SESSION_INNERTUBE_CLIENT | `WEB_EMBEDDED` | |
| 59 | + |
| 60 | +[*view details*](#service-specific) |
| 61 | + |
| 62 | +## general |
| 63 | +[*jump to the table*](#general-vars) |
| 64 | + |
| 65 | +### API_URL |
| 66 | +> [!NOTE] |
| 67 | +> API_URL is required to run the API instance. |
| 68 | +
|
| 69 | +the URL from which your instance will be accessible. can be external or internal, but it must be a valid URL or else tunnels will not work. |
| 70 | + |
| 71 | +the value is a URL. |
| 72 | + |
| 73 | +### API_PORT |
| 74 | +port from which the API server will be accessible. |
| 75 | + |
| 76 | +the value is a number from 1024 to 65535. |
| 77 | + |
| 78 | +### COOKIE_PATH |
| 79 | +path to the `cookies.json` file relative to the current working directory of your cobalt instance (usually the main (src/api) folder). |
| 80 | + |
| 81 | +### PROCESSING_PRIORITY |
| 82 | +`nice` value for ffmpeg subprocesses. available only on unix systems. |
| 83 | + |
| 84 | +note: the higher the nice value, the lower the priority. you can [read more about nice here](https://en.wikipedia.org/wiki/Nice_(Unix)). |
| 85 | + |
| 86 | +the value is a number. |
| 87 | + |
| 88 | +### API_INSTANCE_COUNT |
| 89 | +supported only on linux and node.js `>=23.1.0`. when configured, cobalt will spawn multiple sub-instances amongst which requests will be balanced. `API_REDIS_URL` is required to use this option. |
| 90 | + |
| 91 | +the value is a number. |
| 92 | + |
| 93 | +### API_REDIS_URL |
| 94 | +when configured, cobalt will use this redis instance for tunnel cache. required when `API_INSTANCE_COUNT` is more than 1, because else sub-instance wouldn't be able to share cache. |
| 95 | + |
| 96 | +the value is a URL. |
| 97 | + |
| 98 | +### DISABLED_SERVICES |
| 99 | +comma-separated list which disables certain services from being used. |
| 100 | + |
| 101 | +the value is a string of cobalt-supported services. |
| 102 | + |
| 103 | +## networking |
| 104 | +[*jump to the table*](#networking-vars) |
| 105 | + |
| 106 | +### API_LISTEN_ADDRESS |
| 107 | +defines the local address for the api instance. if you are using a docker container, you usually don't need to configure this. |
| 108 | + |
| 109 | +the value is a local IP address. |
| 110 | + |
| 111 | +### API_EXTERNAL_PROXY |
| 112 | +URL of the proxy that will be passed to [`ProxyAgent`](https://undici.nodejs.org/#/docs/api/ProxyAgent) and used for all external requests. HTTP(S) only. |
| 113 | + |
| 114 | +if some feature breaks when using a proxy, please make a new issue about it! |
| 115 | + |
| 116 | +the value is a URL. |
| 117 | + |
| 118 | +### FREEBIND_CIDR |
| 119 | +IPv6 prefix used for randomly assigning addresses to cobalt requests. available only on linux systems. |
| 120 | + |
| 121 | +setting a `FREEBIND_CIDR` allows cobalt to pick a random IP for every download and use it for all requests it makes for that particular download. |
| 122 | + |
| 123 | +to use freebind in cobalt, you need to follow its [setup instructions](https://github.com/imputnet/freebind.js?tab=readme-ov-file#setup) first. |
| 124 | + |
| 125 | +if you want to use this option and run cobalt in a docker container, you also need to set the `API_LISTEN_ADDRESS` env variable to `127.0.0.1` and set `network_mode` for the container to `host`. |
| 126 | + |
| 127 | +the value is an IPv6 range. |
| 128 | + |
| 129 | +## limits |
| 130 | +[*jump to the table*](#limit-vars) |
| 131 | + |
| 132 | +### DURATION_LIMIT |
| 133 | +media duration limit, in **seconds** |
| 134 | + |
| 135 | +the value is a number. |
| 136 | + |
| 137 | +### TUNNEL_LIFESPAN |
| 138 | +the duration for which tunnel info is stored in ram, **in seconds**. |
| 139 | + |
| 140 | +it's recommended to keep this value either default or as low as possible to preserve efficiency and user privacy. |
| 141 | + |
| 142 | +the value is a number. |
| 143 | + |
| 144 | +### RATELIMIT_WINDOW |
| 145 | +rate limit time window for api requests, but not session requests, in **seconds**. |
| 146 | + |
| 147 | +the value is a number. |
| 148 | + |
| 149 | +### RATELIMIT_MAX |
| 150 | +amount of api requests to be allowed within the time window of `RATELIMIT_WINDOW`. |
| 151 | + |
| 152 | +the value is a number. |
| 153 | + |
| 154 | +### SESSION_RATELIMIT_WINDOW |
| 155 | +rate limit time window for session creation requests, in **seconds**. |
| 156 | + |
| 157 | +the value is a number. |
| 158 | + |
| 159 | +### SESSION_RATELIMIT |
| 160 | +amount of session requests to be allowed within the time window of `SESSION_RATELIMIT_WINDOW`. |
| 161 | + |
| 162 | +the value is a number. |
| 163 | + |
| 164 | +## security |
| 165 | +[*jump to the table*](#security-vars) |
| 166 | + |
| 167 | +> [!NOTE] |
| 168 | +> in order to enable turnstile bot protection, `TURNSTILE_SITEKEY`, `TURNSTILE_SECRET`, and `JWT_SECRET` must be set. all three at once. |
| 169 | +
|
| 170 | +### CORS_WILDCARD |
| 171 | +defines whether cross-origin resource sharing is enabled. when enabled, your instance will be accessible from foreign web pages. |
| 172 | + |
| 173 | +the value is a number. 0: disabled. 1: enabled. |
| 174 | + |
| 175 | +### CORS_URL |
| 176 | +configures the [cross-origin resource sharing origin](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Access-Control-Allow-Origin). your instance will be available only from this URL if `CORS_WILDCARD` is set to `0`. |
| 177 | + |
| 178 | +the value is a URL. |
| 179 | + |
| 180 | +### TURNSTILE_SITEKEY |
| 181 | +[cloudflare turnstile](https://www.cloudflare.com/products/turnstile/) sitekey used by the web client to request & solve a challenge to prove that the user is not a bot. |
| 182 | + |
| 183 | +the value is a specific key. |
| 184 | + |
| 185 | +### TURNSTILE_SECRET |
| 186 | +[cloudflare turnstile](https://www.cloudflare.com/products/turnstile/) secret used by the processing instance to verify that the client solved the challenge successfully. |
| 187 | + |
| 188 | +the value is a specific key. |
| 189 | + |
| 190 | +### JWT_SECRET |
| 191 | +the secret used for issuing JWT tokens for request authentication. the value must be a random, secure, and long string (over 16 characters). |
| 192 | + |
| 193 | +the value is a specific key. |
| 194 | + |
| 195 | +### JWT_EXPIRY |
| 196 | +the duration of how long a cobalt-issued JWT token will remain valid, in seconds. |
| 197 | + |
| 198 | +the value is a number. |
| 199 | + |
| 200 | +### API_KEY_URL |
| 201 | +the URL to the the external or local key database. for local files you have to specify a local path using the `file://` protocol. |
| 202 | + |
| 203 | +see [the api key section](/docs/protect-an-instance.md#api-key-file-format) in the "how to protect your cobalt instance" document for more details. |
| 204 | + |
| 205 | +the value is a URL. |
| 206 | + |
| 207 | +### API_AUTH_REQUIRED |
| 208 | +when set to `1`, the user always needs to be authenticated in some way before they can access the API (either via an api key or via turnstile, if enabled). |
| 209 | + |
| 210 | +the value is a number. |
| 211 | + |
| 212 | +## service-specific |
| 213 | +[*jump to the table*](#service-specific-vars) |
| 214 | + |
| 215 | +### CUSTOM_INNERTUBE_CLIENT |
| 216 | +innertube client that will be used instead of the default one. |
| 217 | + |
| 218 | +the value is a string. |
| 219 | + |
| 220 | +### YOUTUBE_SESSION_SERVER |
| 221 | +URL to an instance of [yt-session-generator](https://github.com/imputnet/yt-session-generator). used for automatically pulling `poToken` & `visitor_data` for youtube. can be local or remote. |
| 222 | + |
| 223 | +the value is a URL. |
| 224 | + |
| 225 | +### YOUTUBE_SESSION_INNERTUBE_CLIENT |
| 226 | +innertube client that's compatible with botguard's (web) `poToken` and `visitor_data`. |
| 227 | + |
| 228 | +the value is a string. |
0 commit comments