Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
155 lines
8.2 KiB
Markdown
155 lines
8.2 KiB
Markdown
# Prism — universal media-generation gateway
|
|
|
|
Prism is an executable FastAPI service over Menivor's reviewed media
|
|
catalog and routing policy. It exposes image, video, and audio (music) models
|
|
through one OpenAI-shaped surface, performs consented equivalent-model failover,
|
|
supports a hard microdollar cost cap, polls queued video/audio providers, and
|
|
provides owner-scoped exact-cost readback. Every provider execution is gated by a
|
|
durable Mint hold; successful generations capture their exact cost and failures
|
|
release the hold.
|
|
|
|
Implemented endpoints:
|
|
|
|
- `GET /v1/models?modality=image|video|audio`
|
|
- `POST /v1/media/generations`
|
|
- `GET /v1/generation?id=gen_...`
|
|
- `GET /v1/generation/by-correlation?correlation_id=...`
|
|
- `GET /v1/generations?limit=50&status=queued|running|completed|failed` — owner-scoped
|
|
history, newest first, with settlement state; never polls providers
|
|
- `POST /v1/generation/{id}/cancel` — cancels the upstream provider run (or
|
|
abandons it locally when the provider has no cancel primitive), marks the
|
|
generation `failed` with zero cost and releases its Mint hold. Idempotent on
|
|
terminal generations; a run that already finished upstream is settled truthfully
|
|
- `GET /healthz`
|
|
|
|
Authentication fails closed. Set `PRISM_API_KEY_SHA256S` to comma-separated
|
|
SHA-256 hashes of accepted Prism keys. Callers may send a key as
|
|
`Authorization: Bearer ...` or `X-Prism-Key`. Optional BYOK credentials use
|
|
`X-Provider` plus `X-Provider-Api-Key` and are never persisted. For asynchronous
|
|
video, resend those two BYOK headers while polling `GET /v1/generation`; Prism
|
|
uses the credential for that request only.
|
|
|
|
Provider handles and owner-scoped generation snapshots are stored in SQLite so
|
|
polling resumes after a Prism process restart. Set `PRISM_STORE_PATH` to a
|
|
volume-backed path in deployed environments. When omitted, Prism uses an OS
|
|
temporary-data path suitable for local development. `PRISM_STORE_MAX_RECORDS`
|
|
sets the bounded retention count (default 100,000). API keys and BYOK provider
|
|
credentials are never stored.
|
|
Active generations are never evicted. The configured record limit applies to
|
|
terminal generations and their resolved intent rows, and also bounds unresolved
|
|
intents without deleting them (new submissions fail closed at capacity).
|
|
|
|
Each accepted key is bounded at the public edge so a single leaked key cannot run
|
|
up an unbounded bill or flood the service:
|
|
|
|
- `PRISM_DAILY_CAP_MICROS` sets a per-key daily spend ceiling in integer
|
|
microdollars, resetting at midnight UTC. Checked against the reserved cost
|
|
before any Mint hold is authorized; a breach returns `429` and performs no
|
|
provider I/O. Default `0` (unlimited). The cap counts reservations idempotently
|
|
per `X-Correlation-ID`, so retrying the same request never double-debits it.
|
|
- `PRISM_RATE_LIMIT_PER_MINUTE` caps authenticated requests per key within a
|
|
sliding window; exceeding it returns `429`. Default `0` (unlimited).
|
|
- `PRISM_RATE_LIMIT_WINDOW_SECONDS` sets that window (default `60`).
|
|
|
|
The daily spend cap is authoritative across worker processes. When the durable
|
|
SQLite store is configured, the cap sums the committed spend for a key directly
|
|
from the settlement ledger on disk (captured charges plus still-outstanding
|
|
holds, attributed to the UTC day the reservation was made) before admitting a new
|
|
charge. Because every worker reads the same ledger, a leaked key cannot exceed
|
|
the cap by fanning requests across workers. The in-memory sliding window remains
|
|
as a cheap per-worker pre-check in front of that authoritative sum. The rate
|
|
limit stays purely per gateway worker in memory.
|
|
|
|
**Owner step for a durable cap:** point every gateway worker at one shared
|
|
`PRISM_STORE_PATH` on a volume they all mount. With the default per-worker
|
|
temporary path (or an ephemeral in-memory store) the cap falls back to the
|
|
per-worker in-memory window only — each worker then enforces its own copy of the
|
|
ceiling. `PRISM_STORE_PATH` is the same shared volume already needed for
|
|
restart-safe polling, so a single volume satisfies both.
|
|
|
|
`X-Correlation-ID` is an owner-scoped idempotency key. Prism durably records
|
|
the canonical request before provider I/O: repeating the same request returns
|
|
the existing generation, while reusing the correlation ID for different input
|
|
returns `409`. If a submit response is lost, the caller can recover the accepted
|
|
generation through the correlation lookup endpoint without resubmitting it.
|
|
|
|
Provider execution goes through the versioned `reelforge-provider-adapter-kit`
|
|
contract and Menivor's public `app.domains.gateway.provider_execution` boundary.
|
|
Prism does not import private gateway helpers. Equivalent-provider fallback is
|
|
allowed only when the typed provider error proves the request was not accepted;
|
|
ambiguous, auth, validation, and BYOK failures never fan out.
|
|
|
|
## Modalities
|
|
|
|
Image models return synchronously; video and audio (music) providers are
|
|
submitted then polled to completion through the same durable pipeline. Audio
|
|
models are billed per clip (a flat per-generation price) while video is billed
|
|
per second. Audio requests accept modality-specific fields — `instrumental`
|
|
(music without vocals), `voice_id`, `reference_audio_url`, and `language` — which
|
|
are forwarded to the provider that supports them and ignored by image/video
|
|
models. Video-only knobs (`duration_seconds`, `aspect_ratio`) are dropped for
|
|
image and audio requests.
|
|
|
|
The audio backend is Suno; its service credential is read from the environment
|
|
as `SUNO_API_KEY` (or supplied per-request as a BYOK `X-Provider: suno` +
|
|
`X-Provider-Api-Key` header pair, never persisted). Without a configured key the
|
|
audio path fails closed with a typed auth error and no Mint capture.
|
|
|
|
Voice (ElevenLabs, self-hosted TTS) and avatar (HeyGen) adapters exist in
|
|
`app.domains.routing.providers` but implement the separate `routing.base`
|
|
`ProviderRun` contract rather than the `ProviderResultV1` execution contract this
|
|
gateway drives; ElevenLabs/self-host TTS additionally return raw audio rather
|
|
than a hostable output URL. They must be ported to the
|
|
`provider_execution.MediaProviderExecutor` dispatch (with output hosting) before
|
|
Prism can route to them — see the audio (Suno) branch as the reference shape.
|
|
|
|
Mint settlement also fails closed. Configure all of:
|
|
|
|
- `PRISM_MINT_SERVER_URL`
|
|
- `PRISM_MINT_API_KEY`
|
|
- `PRISM_MINT_PAYEE_ACCOUNT`
|
|
- `PRISM_MINT_PAYER_ACCOUNTS_JSON`, an object mapping Prism API-key SHA-256
|
|
fingerprints to funded Mint account IDs
|
|
- `PRISM_MINT_ATTESTATION_PUBLIC_KEYS_JSON`, an object mapping trusted Mint key
|
|
IDs to Ed25519 public-key hex
|
|
|
|
Prism persists the hold and atomically claims provider-submission ownership
|
|
before provider I/O. Mint operations use stable idempotency keys, so a lost
|
|
authorization or capture response is replayable after restart without duplicate
|
|
provider work or duplicate charges. A completed response includes reserved and
|
|
charged microdollars plus a privacy-safe receipt projection, but only after the
|
|
Mint attestation has been verified against the pinned key, payer/payee mapping,
|
|
hold, amount, idempotency key, and reference. Failed generations report zero
|
|
charged microdollars and a verified release receipt. `/healthz` is `degraded`
|
|
until the complete Mint configuration is present and its payee is reachable.
|
|
|
|
```bash
|
|
cd apps/prism-media-gateway
|
|
PRISM_API_KEY_SHA256S="$(printf prism-dev | shasum -a 256 | cut -d' ' -f1)" \
|
|
PYTHONPATH=../api:../../packages/provider-adapter-kit/python:. \
|
|
../../.venv/bin/python -m uvicorn prism_gateway.app:app --port 8090
|
|
|
|
PYTHONPATH=../api:../../packages/provider-adapter-kit/python:. \
|
|
../../.venv/bin/python -m pytest tests -q
|
|
```
|
|
|
|
Transparent arbitrage accounting and the public cost/health leaderboard remain
|
|
later work. The product roadmap remains in
|
|
[`docs/apps-vision/prism-media-gateway.md`](../../docs/apps-vision/prism-media-gateway.md).
|
|
|
|
## Deployment
|
|
|
|
`compose.yml` in this directory runs Prism as a standalone service with a named
|
|
volume for `PRISM_STORE_PATH`, a `/healthz` health check and N uvicorn workers
|
|
sharing that one store:
|
|
|
|
```bash
|
|
cp apps/prism-media-gateway/prism.env.example apps/prism-media-gateway/prism.env
|
|
docker compose -f apps/prism-media-gateway/compose.yml up -d --build
|
|
```
|
|
|
|
Then set `PRISM_GATEWAY_URL` and `PRISM_GATEWAY_API_KEY` on the Menivor API so
|
|
video generations route through Prism. `prism.env` is gitignored and is never
|
|
copied into the image.
|
|
|