Developers

Self-hosting

Architecture, local development setup, Kubernetes deployment, OIDC auth, checkpoint storage, and optional integrations for running your own Cohub instance.

This page is for operators running Cohub on their own infrastructure. It covers the service architecture, local development startup, Kubernetes deployment layout, OIDC authentication, S3 checkpoint storage, optional modules (billing, notifications, WebRTC, OpenTelemetry, workspace storage scanning), and how to point the CLI and SDK at your deployment.

The open-source default runs without hosted billing. Core Spaces, Chats, Saves, and Apps work without enabling billing or commerce.

Architecture

A full production deployment consists of six application services and five backing dependencies:

Component Role
Web (apps/web) SvelteKit frontend, deployed on Cloudflare Workers or Node
API (apps/api) Hono HTTP API service
Worker (apps/worker) BullMQ background workers (notifications, checkpoint backfill, workspace usage scans, RTC sweeps)
Agent (apps/agent) Agent control service
Sandbox (apps/sandbox) Per-Space runtime running on Kubernetes
Gateway (apps/gateway) Realtime WebSocket server and external channel bridges (Discord, Feishu/Lark, WeChat, QQ)

Backing infrastructure:

  • PostgreSQL for users, Spaces, Chats, checkpoint metadata, and usage tables.
  • Redis for pub/sub, caching, and BullMQ queues (REDIS_URL and BULLMQ_REDIS_URL).
  • Shared filesystem for Space workspaces (SPACE_STORAGE_ROOT) and refillable checkpoint cache repositories (SPACE_SYSTEM_ROOT, CHECKPOINT_CACHE_ROOT).
  • S3-compatible object storage for turn objects, chat/Space uploads, and checkpoint history.
  • OIDC provider (Logto or compatible) for user authentication.

Local development quick start

Prerequisites: Node.js ≥ 24 and pnpm ≥ 12.

pnpm install
cp apps/api/.env.example apps/api/.env
cp apps/web/.env.example apps/web/.env
# Fill DATABASE_URL, REDIS_URL, BULLMQ_REDIS_URL, APP_ENCRYPTION_KEY, WORKER_SECRET, and OIDC settings
pnpm dev

Reference templates for the other services live at apps/gateway/.env.example and apps/sandbox/.env.example.

At startup, the API and Worker assert their core runtime variables and exit immediately if any are missing:

  • API required: REDIS_URL, BULLMQ_REDIS_URL, APP_ENCRYPTION_KEY, WORKER_SECRET (plus DATABASE_URL, WEB_ORIGIN, and OIDC settings for normal operation).
  • Worker required: REDIS_URL, BULLMQ_REDIS_URL, DATABASE_URL, WORKER_SECRET, APP_ENCRYPTION_KEY, SPACE_STORAGE_ROOT, SPACE_SYSTEM_ROOT, CHECKPOINT_CACHE_ROOT.
  • Gateway: WORKER_SECRET in apps/gateway must match the API's WORKER_SECRET, and API_BASE_URL must reach the API.

Kubernetes deployment templates and images

Kubernetes templates live under deploy/, organized by component (agent, api, fs-api, gateway, preview, sls, storage, web, worker). Each component contains manifests/ templates and environment directories.

Typical per-component rollout:

  1. Copy values.example.yaml to values.yaml in the target environment directory and point image repositories and hostnames at your own registry and domains.
  2. Copy secrets.template.yaml to secrets.yaml and fill in secrets locally (keep real values.yaml and secrets.yaml out of Git).
  3. Run ./run-migration.sh for database migrations where provided.
  4. Run ./deploy.sh to render and apply manifests.

Sandbox image pull secret

SANDBOX_IMAGE_PULL_SECRET on the API controls which Kubernetes Secret Sandbox pods use to pull images:

  • Unset: falls back to gitea-registry.
  • Non-empty string: uses that Secret in the Sandbox namespace.
  • Empty (SANDBOX_IMAGE_PULL_SECRET=) or whitespace-only: omits imagePullSecrets, which is required when pulling from a public registry without pull credentials.

Authentication (OIDC / Logto)

Official defaults point to Cohub's hosted Logto tenant. Self-hosted instances override both build-time Web settings and runtime API/CLI settings:

# Web (build-time)
PUBLIC_LOGTO_ENDPOINT=https://auth.example.com/
PUBLIC_LOGTO_APP_ID=<your-logto-app-id>
PUBLIC_LOGTO_API_RESOURCE=https://api.example.com

# API (runtime)
LOGTO_ENDPOINT=https://auth.example.com
AUTH_RESOURCE=https://api.example.com

# CLI (runtime)
COHUB_AUTH_ISSUER=https://auth.example.com/oidc
COHUB_AUTH_RESOURCE=https://api.example.com
COHUB_AUTH_CLIENT_ID=<your-cli-client-id>

PUBLIC_LOGTO_API_RESOURCE (Web), AUTH_RESOURCE (API), and COHUB_AUTH_RESOURCE (CLI) must match the OIDC API resource / audience configured in your provider.

Object storage and checkpoint history

Cohub uses S3-compatible buckets across three roles:

Role Environment variables
Turn objects & model archives TURN_OBJECT_S3_ENDPOINT, TURN_OBJECT_S3_REGION, TURN_OBJECT_S3_BUCKET, TURN_OBJECT_S3_ACCESS_KEY_ID, TURN_OBJECT_S3_SECRET_ACCESS_KEY (optional TURN_OBJECT_S3_PUBLIC_ENDPOINT)
User & Space uploads USER_UPLOAD_S3_ENDPOINT, USER_UPLOAD_S3_REGION, USER_UPLOAD_S3_ACCESS_KEY_ID, USER_UPLOAD_S3_SECRET_ACCESS_KEY, CHAT_ATTACHMENT_S3_BUCKET, SPACE_UPLOAD_S3_BUCKET
Checkpoint history CHECKPOINT_ASSET_OSS_ENDPOINT, CHECKPOINT_ASSET_OSS_REGION, CHECKPOINT_ASSET_OSS_BUCKET, CHECKPOINT_ASSET_OSS_ACCESS_KEY_ID, CHECKPOINT_ASSET_OSS_SECRET_ACCESS_KEY (each falls back to the corresponding TURN_OBJECT_S3_* variable when unset)

Saves are stored as immutable, content-addressed Git packs and manifests in object storage (checkpoint-packs/<spaceId>/, checkpoint-manifests/<commit>.json, checkpoint-covers/, checkpoint-assets/). Postgres holds checkpoint rows and commit hashes, and repositories under SPACE_SYSTEM_ROOT act as refillable read caches. No external Git host is required.

To backfill older Spaces into checkpoint object storage, enqueue the idempotent checkpoint.storage_backfill job:

tsx scripts/enqueue-checkpoint-storage-backfill.ts
tsx scripts/enqueue-checkpoint-storage-backfill.ts --space-id <space-id>

Orphan packs left behind by deleted checkpoints are not automatically garbage-collected.

Optional integrations

Billing (disabled by default)

Without billing configuration, API and Worker run with the disabled billing provider and commerce features stay off.

To enable the hosted Talesofai Billing adapter:

  1. Set GITEA_NPM_TOKEN before pnpm install so it can install the private @talesofai-billing/sdk package.
  2. Configure TALESOFAI_BILLING_BASE_URL, TALESOFAI_BILLING_BUSINESS_KEY, and TALESOFAI_BILLING_ADMIN_API_KEY (plus TALESOFAI_BILLING_SPACE_WALLET_BUSINESS_KEY for Space Wallets and TALESOFAI_BILLING_WEBHOOK_SECRET for webhooks).

If billing variables are set without @talesofai-billing/sdk present, API and Worker refuse to start.

Notifications (email and push)

Configure on API and Worker as needed:

Channel Environment variables
Email EMAIL_URL (resend://, smtp://, or log://), EMAIL_FROM, PUBLIC_API_ORIGIN (used with APP_ENCRYPTION_KEY to sign one-click unsubscribe links)
Web Push WEB_PUSH_VAPID_PUBLIC_KEY, WEB_PUSH_VAPID_PRIVATE_KEY, WEB_PUSH_VAPID_SUBJECT (generate keys with npx web-push generate-vapid-keys)
Android / FCM FCM_SERVICE_ACCOUNT (raw JSON or base64-encoded service account JSON)

Displays and App room WebRTC

  • Displays: peer-to-peer WebRTC uses a public STUN server by default. For restrictive networks, set RTC_TURN_KEY_ID and RTC_TURN_KEY_API_TOKEN (Cloudflare Realtime TURN) on the API.
  • App room RTC: set RTC_SFU_APP_ID and RTC_SFU_APP_SECRET on both the API and the Worker to enable Cloudflare Realtime SFU data channels and media tracks. The Worker sweeps idle SFU sessions when their owner leaves. Without these variables, room.rtc() reports unavailable and rooms keep working over WebSocket events.

OpenTelemetry

Remote span export is off by default. To export traces to your own collector:

# Prefer the traces-specific endpoint
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://otel.example.com/v1/traces

# Or set a base endpoint (Cohub appends /v1/traces)
OTEL_EXPORTER_OTLP_ENDPOINT=https://otel.example.com

# Optional tuning
OTEL_TRACE_SAMPLE_RATIO=0.1
OTEL_SDK_DISABLED=false
OTEL_CONSOLE_EXPORTER=false

Workspace storage usage scanning

The system worker measures cloud workspaces with pdu 0.24.0 under GNU coreutils timeout and writes totals to Postgres (space_workspace_usage).

  • Stopped workspaces are scanned 2 minutes after stopping or after a direct file write; unchanged workspaces are not re-scanned.
  • Running workspaces are re-measured at most every 15 minutes after sandbox activity, and every 2 hours otherwise. Stopped workspaces take priority.
  • Failed scans back off exponentially up to 7 days.
  • To bound NAS load, at most 2 scans run at once across all workers, with 8 pdu threads per scan and a 40-minute timeout.

The amd64 worker image bundles pdu. On other architectures, install pdu 0.24.0, ensure GNU timeout is on PATH, and set WORKSPACE_USAGE_PDU_PATH; otherwise the worker skips workspace usage scanning at startup.

Connecting the CLI and SDK

Point the CLI at your self-hosted endpoints with flags or environment variables, then sign in:

export COHUB_BASE_URL=https://api.example.com
export COHUB_WS_URL=wss://gateway.example.com/ws
export COHUB_WEB_URL=https://cohub.example.com
export COHUB_AUTH_ISSUER=https://auth.example.com/oidc
export COHUB_AUTH_RESOURCE=https://api.example.com
export COHUB_AUTH_CLIENT_ID=<your-cli-client-id>

cohub auth login
cohub spaces ls

For one-off commands, --base-url <url> overrides COHUB_BASE_URL (cohub --base-url https://api.example.com spaces ls).

In the TypeScript SDK (@neta-art/cohub), pass endpoints explicitly or set COHUB_BASE_URL, COHUB_WS_URL, COHUB_WEB_URL, and COHUB_VOICE_WS_URL in Node.js:

import { createCohubClient } from "@neta-art/cohub";

const client = createCohubClient({
  baseUrl: "https://api.example.com",
  webBaseUrl: "https://cohub.example.com",
  websocket: { url: "wss://gateway.example.com/ws" },
  getAccessToken: async () => token,
});

Security reports

Report security vulnerabilities through GitHub Private Vulnerability Reporting or email dev@talesof.ai with a [SECURITY] subject prefix (see SECURITY.md in the repository).

Boundaries and common errors

  • Kubernetes required for cloud sandboxes: full production relies on Kubernetes for per-Space sandboxes.
  • Model adapters and keys: multimodal generation and hosted model routing require configured provider adapters/keys (or user BYOK keys).
Symptom or error Cause and fix
Missing required env: ... at startup API or Worker is missing one of its required runtime variables (REDIS_URL, BULLMQ_REDIS_URL, APP_ENCRYPTION_KEY, WORKER_SECRET, or Worker's DATABASE_URL / storage roots). Set it and restart.
API or Worker refuses to start after setting billing env vars TALESOFAI_BILLING_* is configured without @talesofai-billing/sdk installed. Either clear the billing variables or reinstall with GITEA_NPM_TOKEN set.
Every API request returns 401 after OIDC login PUBLIC_LOGTO_API_RESOURCE (Web), AUTH_RESOURCE (API), or COHUB_AUTH_RESOURCE (CLI) do not match the token audience configured in Logto. Align all three and rebuild Web.
Gateway calls or internal jobs fail authentication WORKER_SECRET does not match between API, Worker, and Gateway. Synchronize the shared secret across services.
Sandbox pods fail with ImagePullBackOff on public images SANDBOX_IMAGE_PULL_SECRET defaults to gitea-registry when unset. Set SANDBOX_IMAGE_PULL_SECRET= explicitly to omit imagePullSecrets.
Workspace storage usage stays empty on non-amd64 workers pdu 0.24.0 or GNU timeout is missing. Install both and set WORKSPACE_USAGE_PDU_PATH.
room.rtc() reports unavailable in published Apps RTC_SFU_APP_ID and RTC_SFU_APP_SECRET are not configured on both API and Worker. Rooms continue over WebSocket events until SFU credentials are set.
Unsubscribe links or email digests do not send Verify EMAIL_URL, EMAIL_FROM, PUBLIC_API_ORIGIN, and APP_ENCRYPTION_KEY are set on the Worker and API.

Next steps

  • CLI — endpoint overrides, authentication, and command reference
  • SDK — connecting custom clients to your self-hosted API and Gateway
  • Files & Sandbox — how cloud sandboxes and workspace files work
  • Saves — checkpoint lifecycle backed by Git packs and manifests
  • Displays — WebRTC screen sharing and TURN configuration
  • Inbox & Notifications — email, Web Push, and FCM delivery behavior