Skip to content

Brain Environment Variables

Brain reads configuration from process.env via @nestjs/config and a few direct lookups (apps/brain/src/main.ts, apps/brain/src/common/runtime/stage.ts, apps/brain/src/config/queue.config.ts). The BRAIN_*-prefixed variables in .env.example are mapped onto the unprefixed names that the service actually reads in docker-compose.yml. On Railway the same mapping happens via the service env config.

The canonical .env.example is at the repo root.

Stage and runtime

VarRequiredDefaultSourcePurpose
BRAIN_STAGEyesdevelopment.env.example, RailwayResolved by getBrainStage() to production/staging/sandbox/development; PR previews containing -pr- map to sandbox.
RAILWAY_ENVIRONMENT_NAMEplatformRailway runtimeStage fallback when BRAIN_STAGE is unset.
NODE_ENVyesproduction (compose)docker-compose.yml, RailwayFinal stage fallback.
PORTyes3000docker-compose.yml, main.tsHTTP listen port; main.ts binds to IPv6 dual-stack ::.
BRAIN_HTTP_PORTdev3000.env.exampleLocal override only; service still reads PORT.

Database (Prisma / PostgreSQL)

VarRequiredDefaultSourcePurpose
DATABASE_URLyesprisma/schema.prisma, RailwayPooled Prisma connection (Neon pgbouncer in prod).
DIRECT_DATABASE_URLyes (migrations)falls back to DATABASE_URLprisma/schema.prisma, docker-compose.ymlDirect (non-pooled) connection for prisma migrate deploy.
BRAIN_DATABASE_URLdev.env.exampleMapped onto DATABASE_URL in compose.
BRAIN_DIRECT_DATABASE_URLoptional locally, required with pooled Neonfalls back to BRAIN_DATABASE_URL.env.example, docker-compose.ymlMapped onto DIRECT_DATABASE_URL in compose. Set it when BRAIN_DATABASE_URL uses a pooler.

Brain owns the fennec schema in the shared sirloin DB. See Data Model.

Queue (Redis / BullMQ)

VarRequiredDefaultSourcePurpose
REDIS_HOSTyeslocalhostapps/brain/src/config/queue.config.tsBullMQ connection host.
REDIS_PORTyes6379queue.config.tsBullMQ connection port.
REDIS_PASSWORDoptionalqueue.config.tsAuth where Redis is password-protected.

family: 0 is set so dual-stack IPv4/IPv6 resolution works on Railway’s private network.

Auth (Clerk + API key)

VarRequiredDefaultSourcePurpose
CLERK_PUBLISHABLE_KEYyesClerk dashboardFrontend Clerk identifier.
CLERK_SECRET_KEYyesClerk dashboardServer-side token verification (@clerk/backend).
AUTHORIZED_KEYSyesGenerated; rotated per-stageComma-separated list of API keys accepted by @ApiKeyRoute() endpoints. See Auth Model “API key scopes”.
BRAIN_CLERK_PUBLISHABLE_KEY / BRAIN_CLERK_SECRET_KEY / BRAIN_AUTHORIZED_KEYSdev.env.exampleMapped onto the unprefixed names by compose.
FRONTEND_URLyesapp.module.tsUsed for CORS / redirect validation.
BRAIN_API_PUBLIC_URLoptionalhttp://localhost:9970.env.exampleLocal docs; clients consume the Railway URL in non-dev.

Storage (S3 / R2)

VarRequiredDefaultPurpose
S3_BUCKET_NAMEyesTenderloin bucket (R2) for media.
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEYyesR2 credentials.
AWS_S3_APIREGIONyesautoR2 region.
AWS_S3_APIURLyesR2 endpoint (e.g. https://<accountid>.r2.cloudflarestorage.com).
BRAIN_PUBLIC_BUCKET_URLyesPublic CDN domain for downloads.

Service dependencies

VarRequiredDefaultPurpose
ROUND_HOSTyesround:8080gRPC target for round (embeddings, face).
BRAIN_ROUND_HOSTdevround:8080Mapped onto ROUND_HOST.

AI / generation providers

All optional individually but at least the providers used by enabled flows must be set.

VarProvider
BRAIN_RUNPOD_TOKENRunPod inference.
BRAIN_FAL_AI_KEY, BRAIN_FAL_ADMIN_KEYFAL AI.
BRAIN_GOOGLE_AI_API_KEYGoogle AI Studio.
BRAIN_GOOGLE_CLOUD_SERVICE_ACCOUNT_KEYGoogle Vertex AI service account JSON.
BRAIN_GOOGLE_CLOUD_PROJECT_ID, BRAIN_GOOGLE_CLOUD_LOCATIONVertex region.
BRAIN_KLING_AI_API_KEY, BRAIN_KLING_AI_API_SECRETKling AI.
BRAIN_WAVESPEED_API_KEYWavespeed video.
BRAIN_ATLASCLOUD_API_KEYAtlasCloud inference (Seedream, Seedance).
BRAIN_HF_TOKENHugging Face.
BRAIN_XAI_API_KEYxAI / Grok.
BRAIN_OPENROUTER_API_KEYOpenRouter (language extraction).

Moderation

VarPurpose
BRAIN_HIVE_CELEBRITY_RECOGNITION_API_KEYHive celebrity check.
BRAIN_HIVE_VISUAL_MODERATION_API_KEYHive visual moderation.
BRAIN_HIVE_DEMOGRAPHICS_API_KEYHive demographics.

VI Generator

VarPurpose
BRAIN_VI_GENERATOR_URLOutbound base URL.
BRAIN_VI_GENERATOR_API_KEYAPI key.
BRAIN_VI_GENERATOR_CF_ACCESS_CLIENT_ID / _SECRETCloudflare Access service token.

Image signature secrets

VarPurpose
BRAIN_GEMINI_IMAGE_SIGNATURE_KEYHMAC for signed Gemini outputs.
BRAIN_FENNEC_IMAGE_SIGNATURE_KEYHMAC for signed fennec image URLs.

Observability

VarRequiredPurpose
BRAIN_SENTRY_AUTH_TOKENbuild-timeUsed by Dockerfile to upload sourcemaps.
BRAIN_SENTRY_RELEASEbuild-timeRelease tag; defaults to RAILWAY_GIT_COMMIT_SHA.
BRAIN_OTEL_URLyes (prod)Axiom OTEL endpoint.
BRAIN_OTEL_METRICS_HEADERSyes (prod)authorization=Bearer xaat-...,x-axiom-dataset=....
BRAIN_OTEL_TRACES_LOGS_HEADERSyes (prod)Same shape, traces+logs dataset.

See Observability.

TODO

  • TODO(@pawel): Validate which of the AI provider keys are required per stage vs. lazily resolved at first use.
  • TODO(@pawel): Confirm family: 0 Redis behavior on Upstash vs. self-hosted Redis (set in apps/brain/src/config/queue.config.ts:11).