Self-hosting and deployment
The services that make up agentic-yt, the environment each one needs, and notes for running your own.
agentic-yt is a Bun workspace with four apps and three shared packages. Nothing is compiled ahead of time except the web app; the packages are consumed as TypeScript source.
The pieces
| Service | What it does | Needs |
|---|---|---|
api (apps/api) | The HTTP API, /openapi.json, and the Scalar reference at /docs. Validates every request against the route table, answers from cache, enqueues jobs. | Postgres, Redis |
worker (apps/worker) | Runs download, clip and frames jobs: fetches from YouTube, transcodes, uploads to storage. This is the only place yt-dlp and ffmpeg are needed. | Postgres, Redis, storage |
web (apps/web) | This site: landing page, docs, dashboard. Reads and writes Postgres directly. | Postgres, Clerk |
cli (apps/cli) | The agentic-yt / ayt program. Not deployed; published to npm and as standalone binaries. | — |
Plus Postgres (accounts, tokens, jobs, the cache index), Redis (job queue, rate limits) and object storage for the files.
Environment
Shared by the server-side apps:
| Variable | Used by | Notes |
|---|---|---|
DATABASE_URL | api, worker, web | Postgres connection string. |
DB_POOL_MAX | api, worker, web | Pool size per process. Default 10. |
REDIS_URL | api, worker | Job queue and rate limits. |
ENCRYPTION_KEY | api, worker, web | 32 bytes as 64 hex characters or base64. Encrypts YouTube cookies at rest. Must be identical everywhere, or cookies saved in the dashboard cannot be read by the worker. |
STORAGE_DRIVER | api, worker, web | uploadx or local. Defaults to uploadx when UPLOADX_TOKEN is set, else local. |
UPLOADX_TOKEN, UPLOADX_URL | api, worker, web | For the uploadx driver. |
LOCAL_STORAGE_DIR | api, worker | For the local driver. Default .data/storage. |
LOCAL_STORAGE_URL | api, worker | Public URL prefix for local files; the API serves the directory there. Unset means file:// URLs, which only work on the same machine. |
API_URL | api, web | Public origin of the API. |
WEB_URL | api, web | Public origin of this site. The API builds the CLI login verification_url from it. |
PORT | api, web | Listen port. |
Generate a key with openssl rand -hex 32. Losing it means every stored cookie is unreadable and
every connected account must be reconnected.
Web app
| Variable | When | Notes |
|---|---|---|
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY | build + run | Clerk publishable key. Inlined into the client bundle, so it must be present at build time. |
CLERK_SECRET_KEY | run | Clerk secret key. |
NEXT_PUBLIC_API_URL | build | Public API origin used in links, examples and the reference link. Default https://api.agentic-yt.crafter.run. |
NEXT_PUBLIC_WEB_URL | build | This site's origin, used for absolute links in llms.txt. Falls back to WEB_URL. |
API_INTERNAL_URL | run | Where the server reaches the API (playground, admin health). Falls back to API_URL, then the public URL. Point it at the private network address. |
DATABASE_URL, ENCRYPTION_KEY | run | As above. Not needed at build time. |
ALLOWED_EMAILS | run | Comma-separated allowlist. An entry starting with @ matches a whole domain: ada@example.com,@crafter.run. Unset means anyone who can sign in gets a dashboard. |
ADMIN_EMAILS | run | Comma-separated, same syntax. These accounts get the admin role, and always pass the allowlist. |
ACCESS_REQUEST_EMAIL | run | Where the request-access button sends mail. Optional. |
UPLOADX_TOKEN, UPLOADX_URL | run | Optional. Lets the dashboard re-sign download links that have expired. |
CLI and SDK
AGENTIC_YT_TOKEN and AGENTIC_YT_URL — point AGENTIC_YT_URL at your own API.
Database
bun install
bun run db:migrate # applies packages/db/drizzle/*.sqlMigrations are plain SQL files generated from packages/db/src/schema.ts with
bun run db:generate. Run db:migrate on every deploy before starting the new api and worker.
Running it
bun run --cwd apps/api start # the API
bun run --cwd apps/worker start # the worker (needs yt-dlp and ffmpeg on PATH)
bun run --cwd apps/web build && bun run --cwd apps/web startThe web app builds with output: "standalone", so a container only needs
apps/web/.next/standalone, .next/static and public. apps/web/Dockerfile does this; build it
from the repository root so the workspace packages are in the build context:
docker build -f apps/web/Dockerfile \
--build-arg NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_… \
--build-arg NEXT_PUBLIC_API_URL=https://api.example.com \
--build-arg NEXT_PUBLIC_WEB_URL=https://example.com \
-t agentic-yt-web .No database is contacted during the build: docs and the landing page are static, and every dashboard route is rendered per request.
Things that bite
- Clerk. Add your site's origin to the Clerk application, and keep sign-in at
/sign-inand sign-up at/sign-up— the app's proxy redirects there. - First admin. Put your own email in
ADMIN_EMAILSbefore you first sign in. Roles are never removed automatically; demote in the database. - System YouTube accounts. Without at least one (Admin → System YouTube accounts), videos that
YouTube blocks for anonymous clients fail with
youtube_blockedfor users who have not connected their own. Use throwaway accounts. - Egress. YouTube blocks datacenter addresses aggressively. Where the worker's traffic comes from matters more than anything else in this list.
- Storage growth. Files are evicted least-recently-used first; watch the cache size on the admin page.
- CORS and the reference. The Scalar reference is served by the API at
/docs; the web app only links to it.