Swayzio Core API v1 — base path /api/swayzio/v1
Internal & ServicesInternal & Service-to-Service

Internal & Service-to-Service

These surfaces are not for end‑user integrators — they connect Swayzio’s own services (Trigger.dev jobs, Vercel Cron, the worker, and the Modal media‑intelligence cluster). They are documented for operators and platform engineers. Every one authenticates with a fail‑closed bearer secret or a signed callback, and none accepts an owner from request input.

Internal HTTP endpoints

Base path /api/swayzio/v1/internal. All nodejs runtime, native‑only (never proxied).

MethodPathAuth (Bearer secret)Purpose
POST/internal/catalog-drain/eligibleSWAYZIO_TRIGGER_CALLBACK_SECRETPage drain‑eligible tracks by owner or plan ids ({ items, nextCursor })
POST/internal/catalog-drain/dispatchSWAYZIO_TRIGGER_CALLBACK_SECRETRe‑check eligibility, then dispatch stems+lyrics backfill for one track
GET / POST/internal/audio-embeddings/drainCRON_SECRETVercel Cron‑facing audio‑embedding backfill drain
POST/internal/workflows/trigger-statusSWAYZIO_TRIGGER_CALLBACK_SECRETRecord a Trigger.dev workflow status into the outbox
POST/observability/self-testenv‑flag gated (404 outside dev/preview)Fire a controlled Sentry message + exception
⚠️

Each secret‑gated endpoint returns 401 when its secret env var is unset — it fails closed rather than allowing the request through. Note the three distinct secret namespaces (SWAYZIO_TRIGGER_CALLBACK_SECRET, CRON_SECRET, MEDIA_INTELLIGENCE_CALLBACK_SECRET) — easy to misconfigure.

Media‑intelligence callback (Modal → Core)

POST /api/swayzio/v1/media-intelligence/callback

  • Auth: Authorization: Bearer <MEDIA_INTELLIGENCE_CALLBACK_SECRET> (timing‑safe compare; fails closed) plus x-swayzio-contract-version must equal the pinned mediaIntelligenceContractVersion (400 on mismatch).
  • Body: mediaIntelligenceCallbackRequestSchema — applies the tags / stems / lyrics lanes computed by the Modal worker.
  • Persists: machine tags + bpm/key/duration, stem assets (with storage‑object verification), lyric sections/segments; updates media_intelligence_dispatches + processing_jobs; queues an embedding refresh. A forged callback (valid secret, wrong owner/track) still can’t write — the dispatch lookup is keyed on owner_id + track_id + asset_id.
  • Response: mediaIntelligenceCallbackResponseSchema { status: "accepted", trackId, appliedLanes } 202.

Two Modal apps expose internal HTTP endpoints (FastAPI inside Modal). Both require Authorization: Bearer <api key> + x-swayzio-contract-version, accept only signed‑URL audio sources, and fail closed when their key env var is unset.

Audio embedding (swayzio-audio-embedding) — MuQ + MuLan vectors, returned in‑band (no DB writes):

PathMethodComputes
/healthGETliveness
/v1/audio-embedding/jobsPOSTMuQ + MuLan embeddings over windowed audio
/v1/audio-embedding/text-queriesPOSTMuLan text embeddings (text→track search)

Native essentia (swayzio-native-essentia) — tags / stems / lyrics lanes, result pushed back via the callback above:

PathMethodComputes
/healthGETliveness + model manifest
/v1/media-intelligence/jobsPOSTcreate a tags/stems/lyrics job
/v1/media-intelligence/jobs/{remoteJobId}GETpoll job result

Worker (Cloud Run)

The worker (services/worker) is a Fastify HTTP server fed by GCS object‑finalize push and internal drains. Its routes (/events/gcs/object-finalized, /processing/run-queued, /processing/audio-embeddings/run, /processing/metrics, /health) have no application‑layer auth and rely on private Cloud Run ingress.

🚫

Operator note: the worker’s processing routes must be reachable only from inside the private network / IAM. If exposed publicly, /processing/* would let a caller trigger GPU spend. Confirm ingress is internal‑only.

Trigger.dev tasks (async, non‑HTTP)

Invoked via the Trigger.dev SDK (not a REST surface). Their only HTTP‑facing pieces are outbound callbacks into the internal endpoints above.

TaskTriggerOutbound callback
upload-processingevent (upload workflow)/internal/workflows/trigger-status
catalog-drain-seederowner “Analyze my catalog”/internal/catalog-drain/eligible → fan‑out
catalog-drain-trackbatch from seeder/internal/catalog-drain/dispatch
catalog-drain-diamond-tricklecron 0 */6 * * *(calls seeder)