Skip to content
Self-hosting & Ops

Configuration

apps/core-api runs on Cloudflare Workers and is configured through bindings and environment values. This page covers the full set and the deploy targets.

The distinction matters more than it looks:

  • Bindings — the database, the R2 bucket, the queue, the KV namespace, the rate-limit Durable Object — are declared in apps/core-api/wrangler.jsonc and authorised by being bound. There is no R2 key or service-account credential anywhere in that file, and a binding a deployment doesn’t attach is a missing capability rather than a broken credential.
  • Values are either non-secret vars in the same file, or Worker secrets set out of band with wrangler secret put. Everything below marked “store as a secret” is the second kind. Locally, both live in apps/core-api/.dev.vars (gitignored) — see the quick start.

Workers is the only supported host: there is no Node entry point. The values are plain strings, though, so nothing here is Workers-only syntax.

Variable Purpose
DATABASE_URL Postgres connection string for records, transcripts, processing state, and idempotency keys. Required — the composition root throws rather than falling back. The SQL client runs @neondatabase/serverless over HTTP, so this must be a host that serves Neon’s HTTP SQL endpoint; Neon’s pooled (-pooler) host is the right one, since the driver is stateless per query. Store as a secret.
ANTIPHONY_PUBLIC_BASE_URL Required. The absolute base URL this deployment answers on, e.g. https://api.antiphony.dev. The audio proxy streams bytes rather than redirecting, so AudioEmbedView.url is an absolute URL pointing back here — without this, a post with audio hydrates with no embed at all. Validated at startup.
ANTIPHONY_PLAYBACK_SECRET Optional. Signs the playback URLs for audio in a space: an HMAC key, at least 32 characters (openssl rand -base64 48). Without it, creating a space is a 503 and spaced audio gets no URL, so a deployment can never store private audio it can’t keep private. Rotating it invalidates every outstanding signed URL, which expire within the hour anyway. Store as a secret.
ANTIPHONY_SERVICE_SIGNING_KEY Optional. A P-256 private key (64 hex characters) that lets this deployment publish its own DID document at /.well-known/did.json. Generate it with npm run generate:service-key -w @antiphony/core-api, which prints this value and the matching ANTIPHONY_SERVICE_PUBLIC_KEY and writes nothing to disk. Store as a secret, and set it before the public key.
ANTIPHONY_SERVICE_PUBLIC_KEY Optional. The matching public key as a multibase Multikey (z…), a plain var. The document is served only when this equals the key derived from ANTIPHONY_SERVICE_SIGNING_KEY and ANTIPHONY_SERVICE_DID (default did:web: plus the host of ANTIPHONY_PUBLIC_BASE_URL) is this host’s did:web; otherwise /.well-known/did.json is a 404. A mismatch is logged as an error.
ANTIPHONY_PDS_HOST Required. The host an app DID’s custody service endpoint (#atproto_pds or #atproto_space_host) must point to (e.g. api.antiphony.dev). Validated at startup. The DID registry (/api/v1/dids) and writes under a registered DID depend on it, and on migrations 0004 and 0005.
ANTIPHONY_R2_BUCKET Name of the bucket behind the BLOBS binding. Used for logging and for the rendition service’s own addressing, not for authorisation.
TRUSTED_PROXY_HOPS Number of proxy hops to trust when deriving the client IP from X-Forwarded-For. Used for aggregate IP limits when running behind a proxy.
CLIENT_IP_SOURCE Source for resolving the client IP: 'cf' (reads CF-Connecting-IP on Workers) or 'forwarded' (reads X-Forwarded-For). Defaults to 'forwarded' if unset.
LOG_LEVEL One of debug, info, warn, error, silent. Defaults to info in production, debug otherwise.
NODE_ENV Standard environment flag (production in deploys).

Every tenant needs two registry entries, and they’re keyed on the same originAppId: a credential to authenticate with (ANTIPHONY_APP_TOKENS, below) and an app DID to write records under. A tenant present in only one is config drift — core-api logs a warning naming it.

Variable Purpose
ANTIPHONY_APP_DIDS Comma-separated appId:did pairs pinning each tenant’s at:// authority, e.g. voxpop:did:web:did.voxpop.audio. Split on the first colon, so the DID’s own colons are safe. Required for any tenant that reads or writes posts — see the custody note below.
ANTIPHONY_APP_DID_DOC_HASHES Comma-separated appId:sha256:<hex> pairs: the acknowledged hash of each tenant’s DID document. npm run validate:pins fails the deploy when a resolved document doesn’t match, and prints the document and the value to set — read it before committing, because for did:web a changed document can’t be told apart from a hijack. The hourly cron only logs a mismatch.
ANTIPHONY_PDS_HOST Your Antiphony host (e.g. api.antiphony.dev). A pin’s #atproto_pds serviceEndpoint must point at this host — that’s what turns “the DID document exists” into “the DID names us as its PDS”.

Full rationale: specs/atproto-authority-model.md.

Applications (BFFs, workers) are the intended callers of the posts/audio surface. Each authenticates with its own service token and asserts the acting end user per request — the full contract lives in specs/service-auth.md.

Variable Purpose
ANTIPHONY_APP_TOKENS Comma-separated appId:token pairs (tokens ≥32 chars). A caller presenting a matching Authorization: Bearer <token> is that app: its tenancy (originAppId) comes from the credential, and it asserts the acting user via X-Antiphony-Acting-Actor (+ optional X-Antiphony-Acting-Actor-Did). Store as a secret.
SYSTEM_AUTH_TOKEN Shared secret for the /api/v1/system/* routes. The system-auth middleware expects Authorization: Bearer <SYSTEM_AUTH_TOKEN> and fails closed (503) if the variable is unset — these routes are service-to-service plumbing, not public API. Store it as a secret, not in plaintext config.
RENDITION_SERVICE_TOKEN Optional dedicated bearer secret for outbound requests to ANTIPHONY_RENDITION_SERVICE_URL. Decouples the Cloud Run transcode service credential from SYSTEM_AUTH_TOKEN. Falls back to SYSTEM_AUTH_TOKEN if unset. Store as a secret.

Opt-in processing runs five stages over a post’s audio: transcribe (Whisper on Cloudflare Workers AI, or ElevenLabs Scribe), denoise (ElevenLabs), trim and waveform (ffmpeg, in the rendition service), and assess (Clef decision models on Cloudflare Workers AI, reading the transcript in Phase 1). None run unless the relevant variables below are set; a deployment with none of them still serves audio, it just does no enrichment. Stages requested against a deployment that can’t run them settle skipped, not pending.

Variable Purpose
AI binding On a Cloudflare Worker, an "ai": { "binding": "AI" } block in wrangler.jsonc enables the workers-ai transcriber (Whisper, @cf/openai/whisper-large-v3-turbo) and assessor (Clef-flash, @cf/cloudflare/clef-flash). It needs no key: the binding is the credential. When bound it is preferred over ElevenLabs for transcription; denoise has no Workers AI equivalent. Not available under the Node entry.
WORKERS_AI_STT_MODEL Optional. Overrides the Whisper model id.
WORKERS_AI_ASSESS_MODEL Optional. Overrides the Clef model id used by assess (default @cf/cloudflare/clef-flash).
ELEVENLABS_API_KEY Enables the ElevenLabs providers — Scribe (transcription) and Voice Isolator (denoise). Presence alone selects them; there is no separate enable flag. Absent → denoise/transcribe settle skipped. Store as a secret.
ELEVENLABS_STT_MODEL Optional. Overrides the default Scribe model id used for transcription. Not validated against a list of known ids — a typo reaches the provider and fails the stage — so the resolved value is logged on first use.
ANTIPHONY_RENDITION_SERVICE_URL Base URL of the transcode backend (apps/audio-rendition). Enables trim and waveform, and lets GET /api/v1/audio?format=mp3 build a rendition on a miss instead of 404ing. Absent is a supported state: both stages resolve unavailable and settle skipped, and the audio proxy serves only renditions that already exist. Requires SYSTEM_AUTH_TOKEN — the service is system-authed, so a URL without a token is the same failure wearing a 401.

Optional, and rarely needed: with none of these set, each stage takes the first provider it can run, which is the behavior described above.

Variable Purpose
ANTIPHONY_TRANSCRIBER workers-ai | elevenlabs | stub — set elevenlabs to keep Scribe on a Worker that also has the AI binding
ANTIPHONY_DENOISER elevenlabs | stub
ANTIPHONY_TRIMMER service | stub
ANTIPHONY_WAVEFORM service | stub
ANTIPHONY_ASSESSOR workers-ai | stub

Naming a stage’s provider explicitly lets you mix them — a real transcriber next to a stub denoiser while evaluating one of them, say. Two behaviors are worth knowing before you reach for these:

  • A named provider that isn’t configured is a misconfiguration, not an opt-out. ANTIPHONY_TRANSCRIBER=elevenlabs with no API key logs at error and leaves transcribe unavailable; it does not quietly fall back to another provider, on the same fail-closed principle as the webhook variables below.
  • stub is only ever reachable by naming it. A deployment that loses its API key reports the stage as unavailable and settles requests skipped — it never degrades into saving stub transcripts as real records. For stubs across the board, use ANTIPHONY_PROCESSING_STUB (below), which overrides all four of these.

Optional. Pins one tenant (originAppId) to a provider or model of its own, leaving every other tenant on the deployment default. Same appId:value shape as ANTIPHONY_APP_DIDS and the webhook registries.

Variable Purpose
ANTIPHONY_APP_TRANSCRIBERS voxpop:elevenlabs,acme:stub
ANTIPHONY_APP_DENOISERS same shape
ANTIPHONY_APP_TRIMMERS same shape
ANTIPHONY_APP_WAVEFORMS same shape
ANTIPHONY_APP_ASSESSORS same shape (voxpop:workers-ai,acme:stub)
ANTIPHONY_APP_STT_MODELS voxpop:scribe_v2,acme:scribe_v1 — the transcription model per tenant
ANTIPHONY_APP_ASSESS_MODELS voxpop:@cf/cloudflare/clef — the assess model per tenant
ANTIPHONY_APP_ASSESS_SETS voxpop:quality+relevance — named question sets evaluated by assess per tenant (default quality; relevance always includes quality and applies its questions to replies only)

Selection resolves in three layers, narrowest first: tenant pin → deployment default → first available provider. A tenant with no entry is unaffected by these existing at all.

  • This is ops config, not a tenant-facing feature. A tenant cannot name its own provider or model over the API, so it can never invoke an arbitrary expensive model on your key. Changing a pin is a deploy, not a request.
  • A bad pin is scoped to its tenant. An unknown or unconfigured provider name logs at error and leaves that stage unavailable for that tenant only — its neighbours keep working, and it does not fall back to the deployment default (which would silently overrule the pin). A malformed entry drops with a log without taking out the rest of the variable.
  • Capabilities are per tenant. processing opt-ins settle skipped for a tenant whose pinned provider can’t run, while the same request succeeds for a tenant on a working one.
  • A model pin aimed at a provider with no model is reported and ignored. denoise, trim, and waveform have no model to set — only ANTIPHONY_APP_STT_MODELS exists for that reason. The stage still runs, on the provider’s own default.

Processing runs out of band, never inside the create/patch request.

On Workers this is a binding, not a variable. PROCESSING_QUEUE in wrangler.jsonc names a Cloudflare Queue whose consumer is the same Worker’s queue() handler — so there is no worker URL to configure and no token stored per task. Batch size is deliberately 1: one message is one full processing pass (a denoise call over a multi-megabyte upload, then transcription), the whole batch shares one 15-minute invocation, and blowing that budget retries every message in the batch including the ones that already succeeded. Concurrency belongs between invocations, where Cloudflare scales consumers on its own. Three attempts, then the dead-letter queue.

The queue is the only durable dispatcher. Without the binding, processing runs inline only when ANTIPHONY_PROCESSING_INLINE is set (below); otherwise dispatch is a no-op. The Cloud Tasks adapter that served Node hosts was removed with the Cloud Run deployment.

Optional. When configured, the core POSTs a small signed webhook to a tenant’s BFF each time an enrichment stage reaches a terminal state (ready / failed / skipped), so the BFF learns a result landed without polling. The webhook is a latency accelerator over the authoritative post state, not a second source of truth — a dropped delivery is a latency regression the next read reconciles, never lost data.

Variable Purpose
ANTIPHONY_APP_WEBHOOK_URLS Comma-separated appId:url pairs — where to POST each tenant’s stage-settled events, e.g. voxpop:https://bff.voxpop/hooks. Split on the first colon, so a URL with a port is fine. Must be https unless the host is loopback (localhost, 127.0.0.1, ::1), which stays plaintext-friendly for developing a receiver locally.
ANTIPHONY_APP_WEBHOOK_SECRETS Comma-separated appId:secret pairs, secrets ≥32 chars. The key for the X-Antiphony-Signature: sha256=<hex> header, an HMAC-SHA256 of the raw request body. Store as a secret.

Deliveries also carry X-Antiphony-Timestamp, the event’s occurredAt as an ISO 8601 string, and X-Antiphony-Event-Id, which is {postId or uri}:{stage}:{status} for a stage event (the post’s uri for a remote post, which has no postId), {postId}:deleted for a deletion, and {uri}:remote.gone, {uri}:remote.changed:{cid} or {uri}:remote.recheck_requested:{occurredAt} for the remote events. Neither header is signed: only the body is. Receivers verify the signature over the exact bytes received, and judge staleness from occurredAt inside the signed body, not from the header. The event id is not unique per delivery, because a recompute legitimately re-fires the same {postId}:{stage}:ready, so don’t treat a repeated id as a replay to drop. @antiphony/shared exports verifyWebhookSignature and WebhookEventSchema for the receiving side, and the receiver guide shows them in a handler: verifying and ordering events. Outbound delivery enforces redirect: 'manual' so signed payloads are never reposted across redirects.

A tenant present in both vars gets webhooks; a tenant in neither is a silent opt-out (the pull paths still work). A tenant in exactly one is a misconfiguration — logged at error and sent no webhooks, so it never pushes unsigned. An entry that fails validation — a secret under the length floor, or a plaintext http: target off loopback — is dropped with an error log for that tenant alone, on the same fail-closed principle: the signature is the receiver’s entire basis for trusting an event, so a key short enough to brute-force offline, or a hop where the payload and its signature both travel in the clear, makes it decorative. Delivery is best-effort: up to 3 attempts per event, each with a 3 second timeout and a fixed 200 ms pause between them. A network error, a timeout, a 5xx, a 429 or a 408 is retried; any other non-2xx, a redirect included (redirects are not followed), is not. A POST that still fails is logged and dropped, never failing the enrichment pass. The payload carries {type, postId, uri, originAppId, stage, status, occurredAt}, with type: "stage.settled" (postId is absent for a remote post) — enough to act on without a follow-up request; the artifact itself is fetched from the post view when wanted. Receivers should treat each event as “latest wins for (uri, stage)” (a recompute legitimately re-fires ready), using occurredAt as the tiebreaker. The same URL and secret also receive a post.deleted event for each deleted post, and remote.gone, remote.changed and remote.recheck_requested for remote posts.

Variable Purpose
ANTIPHONY_PROCESSING_INLINE When true, runs processing synchronously inside the request — the local/test trigger, no queue needed. Wins over every durable dispatcher in development/test, so a developer with queue config in their shell can’t enqueue against a real queue by accident.
ANTIPHONY_PROCESSING_STUB When true, wires pass-through stub providers instead of ElevenLabs — exercises the full create → process → hydrate loop with no key and no billing. Wins over ELEVENLABS_API_KEY, so a real key in the shell can’t accidentally bill from a test run.

With no queue binding and no ANTIPHONY_PROCESSING_INLINE, dispatch is a no-op (logged and dropped) — enrichment is effectively off. Note the two flags govern different axes and neither implies the other: _STUB decides which providers can do the work, _INLINE decides who runs it.

The hosted reference deploy at api.antiphony.dev runs on Cloudflare Workers against Neon and R2, configured by apps/core-api/wrangler.jsonc and shipped by .github/workflows/deploy.yml. See deploy/README.md for the one-time setup: the KV namespace and queues to create, the four Worker secrets, and the schema to apply.

The service layer is portable by construction — packages/core has zero backend imports and every backend touch goes through a port — so the reference deploy’s choice of runtime is not a constraint on yours. What each target has to supply is a Postgres and a blob store behind the existing ports:

  • Cloudflare Workers — Neon behind DATABASE_URL, plus an R2 bucket, a queue, a KV namespace and a Durable Object namespace. What the reference deploy runs.
  • A container or VM — any Postgres and any object store. You implement the BlobStore port against it; the Postgres bindings are already in the tree.

The one hard requirement either way is a reachable Postgres. There is no CORS allowlist to configure: core-api runs no CORS middleware, because every caller is a backend holding a service token and the one browser-facing surface — the anonymous audio proxy — is an <audio src=…> no-cors load governed by Cross-Origin-Resource-Policy.