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.
92 lines
3.2 KiB
Python
92 lines
3.2 KiB
Python
"""FastAPI entrypoint for Prism's Sx0 image/video surface."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from uuid import uuid4
|
|
|
|
from fastapi import Depends, FastAPI, Header, Query, Request
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from .auth import ApiKeyAuthenticator, Principal
|
|
from .models import (
|
|
GenerationListResponse,
|
|
GenerationRequest,
|
|
GenerationResponse,
|
|
ModelListResponse,
|
|
)
|
|
from .service import PrismError, PrismService, SqliteGenerationStore
|
|
|
|
|
|
def create_app(
|
|
service: PrismService | None = None,
|
|
authenticator: ApiKeyAuthenticator | None = None,
|
|
) -> FastAPI:
|
|
gateway = service or PrismService(store=SqliteGenerationStore.from_environment())
|
|
auth = authenticator or ApiKeyAuthenticator()
|
|
instance = FastAPI(title="Prism Media Gateway", version="0.1.0")
|
|
|
|
def principal(request: Request) -> Principal:
|
|
return auth.authenticate(request)
|
|
|
|
@instance.exception_handler(PrismError)
|
|
async def prism_error_handler(_request: Request, exc: PrismError):
|
|
return JSONResponse(
|
|
status_code=exc.status_code, content={"error": {"message": str(exc)}}
|
|
)
|
|
|
|
@instance.get("/healthz", include_in_schema=False)
|
|
def healthz():
|
|
return gateway.health()
|
|
|
|
@instance.get("/v1/models", response_model=ModelListResponse)
|
|
def models(modality: str | None = Query(default=None)):
|
|
return ModelListResponse(data=gateway.models(modality))
|
|
|
|
@instance.post("/v1/media/generations", response_model=GenerationResponse)
|
|
def generate(
|
|
body: GenerationRequest,
|
|
actor: Principal = Depends(principal),
|
|
correlation_id: str | None = Header(default=None, alias="X-Correlation-ID"),
|
|
):
|
|
return gateway.generate(body, actor, correlation_id or uuid4().hex)
|
|
|
|
@instance.get("/v1/generation", response_model=GenerationResponse)
|
|
def generation(
|
|
generation_id: str = Query(alias="id", min_length=1),
|
|
actor: Principal = Depends(principal),
|
|
correlation_id: str | None = Header(default=None, alias="X-Correlation-ID"),
|
|
):
|
|
return gateway.generation(actor, generation_id, correlation_id or "")
|
|
|
|
@instance.get("/v1/generation/by-correlation", response_model=GenerationResponse)
|
|
def generation_by_correlation(
|
|
correlation_id: str = Query(min_length=1, max_length=128),
|
|
actor: Principal = Depends(principal),
|
|
):
|
|
return gateway.generation_by_correlation(actor, correlation_id)
|
|
|
|
@instance.get("/v1/generations", response_model=GenerationListResponse)
|
|
def generations(
|
|
limit: int = Query(default=50, ge=1, le=200),
|
|
status: str | None = Query(default=None),
|
|
actor: Principal = Depends(principal),
|
|
):
|
|
return GenerationListResponse(
|
|
data=gateway.list_generations(actor, limit=limit, status=status)
|
|
)
|
|
|
|
@instance.post(
|
|
"/v1/generation/{generation_id}/cancel", response_model=GenerationResponse
|
|
)
|
|
def cancel_generation(
|
|
generation_id: str,
|
|
actor: Principal = Depends(principal),
|
|
correlation_id: str | None = Header(default=None, alias="X-Correlation-ID"),
|
|
):
|
|
return gateway.cancel(actor, generation_id, correlation_id or "")
|
|
|
|
return instance
|
|
|
|
|
|
app = create_app()
|