Skip to content
Margin
Deploy

Configure environment variables

Look up each supported variable, its requirement, and its default before changing deployment settings.

Environment variable configuration applies to self-hosted sites; Manicule-hosted sites set no environment variables.

Configure Margin’s build environment and running server separately. A deployment needs Postgres; outside Vercel, the application also needs an explicit public site URL.

Set variables for the correct deployment stage

Build settings select the server target, compile the display-name override, and pin the content version. Ingest settings select the docs folder, database site, storage, and retention policy. Runtime settings control database access and optional integrations. A CI build uses the same settings as a deployment build; CI does not replace the database or site-origin requirements.

Provide database access to migrations, ingest, and the server. Provide the site origin to the build and server with the same value: the browser receives a build-time copy, while the server reads its environment. Vercel supplies deployment metadata and can derive the origin. For a Node deployment, export settings into both environments rather than assuming the built server loads a local .env file.

The dev, start, db:migrate, and ingest package scripts explicitly load .env. The direct Node server command does not. Set a private database CA before process startup, including for migrations and ingest.

The inventory covers Margin’s deployment and maintenance interfaces, plus the platform variables they consume. Test-only switches and internal debugging switches are not deployment settings. Analytics configured only through docs.json are documented in Configure analytics.

Look up supported variables

Empty strings count as unset in Margin’s validated application, database, and ingest settings. Defaults below apply when a setting is unset. The scope column distinguishes settings you configure from values normally supplied by a platform or tool.

VariablePurposeRequired conditionDefault or unset behaviorRead stage and scope
DATABASE_URL / POSTGRES_URLPostgres connectionRequired for migrations, ingest, and serving database-backed docsFirst non-empty value wins, in the listed order; no built-in connection URLMigrations, ingest, runtime; user or database integration
DATABASE_URL_UNPOOLED / POSTGRES_URL_NON_POOLINGDirect connection for migrations and the ingest advisory lockSupply a direct URL when the main URL uses a transaction-mode poolerFirst non-empty value wins; otherwise uses the main connection URLMigrations, ingest; user or database integration
DATABASE_POOL_MAXMaximum database connections per server instanceOptional2; accepts integers from 1 through 20Database pool creation, including runtime and ingest; user
NODE_EXTRA_CA_CERTSPEM CA bundle for a database signed by a private CANeeded for a private CA not trusted by NodeNode’s built-in CA list; remote database certificates remain verifiedProcess startup for build, migrations, ingest, and server; Node setting
POSTGRES_PORTLocal Compose database’s host portOptional, local Compose only5440; changing it does not update the connection URLCompose startup; user
SITE_ORIGINAbsolute public URL for canonical links, sitemap, and OG images; may include a base pathRequired when no Vercel-derived URL is availableOn Vercel production, https:// plus VERCEL_PROJECT_PRODUCTION_URL; otherwise https:// plus VERCEL_URL. Explicit value overrides inferenceBuild and runtime; user or inferred
SITE_SLUGDatabase site slug and cache tag for the built-in single-site extensionOptional; must match the ingested sitedocs; lowercase letters, digits, and inner hyphens, at most 55 charactersIngest and runtime; user
SITE_NAMEDeployment display-name overrideOptionalContent’s docs.json name, then stored site name or slug; before site resolution, the application fallback is DocsBuild, inlined into client and server; user
SITE_SECRETSalt for hashed visitor identifiers used by feedback and chat rate limitsOptionalResolved database URLRuntime; user
DOCS_DIRFolder containing docs.json and MDXRequired only if neither default folder can be founddocs/ if present, otherwise . if it contains docs.json; CLI --dir takes precedenceIngest; user
DOCS_CONTENT_SHAContent-version key pinned into the deploymentOptional with the deployment build commandVERCEL_GIT_COMMIT_SHA, then git HEAD, then dev-<unix ms> under bun run vercel-build; without a baked key, development follows the current pointerDeployment build and ingest; user or build-generated
DOCS_INGESTControl ingestOptionalon; accepts on, off, force. off skips ingest; force replaces an existing key. CLI --force overrides offIngest, including deployment builds; user
DOCS_KEEP_VERSIONSCount of other production versions retained alongside age-based and protected versionsOptional20; integer of at least 1Ingest garbage collection; user
DOCS_CANONICAL_REDIRECTRedirect production requests to the configured canonical hostOptional1; accepts 0 or 1. 0 disables the redirect. Built-in redirects require VERCEL_ENV=production and no base path; previews do not redirectRuntime; user
DOCS_CHAT_MODELAI Gateway model for Ask AIOptionalopenai/gpt-5.6-terraRuntime; user
AI_GATEWAY_API_KEYAI Gateway credentialRequired for the assistant outside Vercel; Vercel can use deployment OIDC with Gateway accessUnset disables the assistant outside Vercel; static search remains availableRuntime, checked at call time; user
DOCS_LINK_RELATION_BASEBase URI for agent discovery link relationsOptionalhttps://github.com/maniculehq/margin/blob/main/docs/link-relations.md#Runtime; user
BLOB_READ_WRITE_TOKENVercel Blob storage for large assets, search corpus, and safe blob cleanupOptionalAssets and corpus remain in Postgres within ingest size caps; versions with blobs are retained if cleanup cannot safely delete themIngest and garbage collection; user or storage integration
HUGEICONS_PRO_TOKENFetch licensed Pro iconsOptionalFree iconsIcon build; user
HUGEICONS_PRO_STYLESelect Pro icon styleOptional; used with a Pro tokenstroke-roundedIcon build; user
GITHUB_TOKENAuthenticate the repository stars widget’s GitHub API requestsOptionalUnauthenticated requestsRuntime; user
POSTHOG_KEYAgent-journey analytics credentialOptionalAgent-journey analytics offRuntime; user
POSTHOG_HOSTPostHog ingestion hostOptional; used with a keyhttps://us.i.posthog.comRuntime; user
SENTRY_DSNServer error reportingOptionalSentry off; development also stays silent unless SENTRY_ENVIRONMENT is setBuild upload gate and runtime; user
SENTRY_ORG, SENTRY_PROJECT, SENTRY_AUTH_TOKENSentry source-map uploads and release creationAll three plus SENTRY_DSN required for uploadsUpload plugin omitted if any value is missingBuild; user
SENTRY_ENVIRONMENTSentry environment label; explicit opt-in for local development reportingOptionalVERCEL_ENV, otherwise NODE_ENVRuntime; user
SENTRY_RELEASESentry release overrideOptionalNo application-defined fallback; SDK/platform detection may supply a releaseRuntime; user
DOCS_EXTENSIONSModule exporting extensions: DocsExtensionsOptionalBuilt-in single-site extension; relative paths resolve from the repository rootBuild; user
NITRO_PRESETServer build targetSet node-server for the supported self-hosted Node deploymentvercelBuild; user
PORTListening portOptionalVite’s default for dev and start; a configured value must be a positive integer. The generated Node server also accepts PORTDev/preview startup and Node server startup; user
NODE_ENVApplication environmentOptional; normally set by toolingdevelopment; accepts development, test, productionBuild and runtime; tool or user
VERCELIdentify Vercel execution for assistant availabilityNormally platform-providedNo Vercel availability signal when unset; a signal alone does not grant Gateway accessRuntime; Vercel
VERCEL_ENVDeployment environment, preview behavior, and inferred origin selectionNormally platform-providedUnset off Vercel; accepts development, preview, production. Deployment environment otherwise uses NODE_ENVBuild, ingest, runtime; Vercel
VERCEL_URLDeployment hostname for inferred site URLNeeded only when relying on Vercel URL inferenceNo fallback hostnameBuild and runtime; Vercel
VERCEL_PROJECT_PRODUCTION_URLProduction hostname for inferred site URLUsed for production inference when presentFalls back to VERCEL_URLBuild and runtime; Vercel
VERCEL_GIT_COMMIT_SHAFallback content key and agent-surface commit metadataOptionalDeployment build uses git HEAD, then a generated development key if unavailableBuild, ingest, runtime metadata; Vercel
VERCEL_GIT_PULL_REQUEST_IDPreview pull-request metadataOptionalNo PR metadata; when set, a positive integerPreview ingest; Vercel
VERCEL_OIDC_TOKENDeployment identity for AI Gateway authenticationNeeded for Vercel Gateway access without an API keyNo OIDC credentialRuntime; Vercel, refreshed during instance lifetime
CIBuild logging behaviorOptional; normally supplied by CISentry upload plugin is silent when no CI signal is presentBuild; CI runner
AGENT_DOCTOR_URLTarget public URL for the HTTP doctor commandRequired only when invoking the doctor without --urlNo default; --url takes precedenceMaintenance command; user

Apply configuration changes

Rebuild and redeploy after changing a build-time setting. In particular, changing the display-name override requires a new build, not just restarting the server. Keep the origin consistent across build and runtime so browser and server URLs agree.

Restart the server after changing runtime settings. On Vercel, deploy again to apply changed project settings to new functions. Build-only secrets, such as source-map upload credentials and Pro icon tokens, do not need to be installed on a standalone runtime.

Rerun ingest when changing the docs folder, site slug, asset-storage selection, or retention settings. A ready content key is reused unless ingest is forced, so changing ingest inputs alone does not rewrite an existing version. Prefer a new content key for a normal publish. Forced ingest replaces content under the same key and affects every deployment pinned to it. A slug change must be applied to both ingest and runtime. A database URL change requires the destination database to be migrated and populated before the server switches to it.

For a standalone Node deployment, use Node.js 24 or newer and Bun for build commands. With the required settings exported, bun run vercel-build runs icon generation, migrations, the server build, bundle-budget checks, and ingest, in that order. Start the generated Node server with node .output/server/index.mjs from the repository root.

Use Deploy Margin for the Vercel and Node build procedures, migration order, and retention behavior. After deployment, run the HTTP doctor against the public site URL:

bun run doctor --url=https://docs.example.com

The doctor prints a check report and exits with code 0 when every check passes. It exits with code 1 if any check fails; investigate the failed checks before treating the deployment as ready.