feat: add POST /api/video/render endpoint

SI
9mo ago
+707-4

Summary

Adds a POST /api/video/render endpoint that triggers a server-side video render as a Trigger.dev background task. Returns a run ID that can be polled via the existing GET /api/tasks/runs endpoint.

What Changed

New Files (10 files, 686 lines)

FilePurpose
app/api/video/render/route.tsRoute handler (POST + OPTIONS)
lib/render/renderVideoHandler.tsHandler: auth → validate → trigger → respond
lib/render/validateRenderVideoBody.tsZod schema + validation function
lib/trigger/triggerRenderVideo.tsTriggers render-video task on Trigger.dev
lib/mcp/tools/render/registerRenderVideoTool.tsMCP tool sharing triggerRenderVideo
lib/mcp/tools/render/index.tsRender tool registration group

Modified Files

FileChange
lib/mcp/tools/index.tsRegister render tools

Tests (18 passing)

FileTests
lib/render/__tests__/validateRenderVideoBody.test.ts11 tests (valid inputs, defaults, error cases)
lib/render/__tests__/renderVideoHandler.test.ts5 tests (auth, validation, trigger, error)
lib/trigger/__tests__/triggerRenderVideo.test.ts2 tests (trigger payload, handle return)

Architecture

Follows the exact same pattern as POST /api/sandboxes/setup:

POST /api/video/render
  → validateAuthContext (x-api-key or Bearer)
  → validateRenderVideoBody (Zod)
  → triggerRenderVideo (Trigger.dev)
  → { status: "processing", runId }

GET /api/tasks/runs?runId=xxx  ← existing endpoint
  → { status: "complete", data: { videoUrl } }

DRY

The MCP tool (render_video) and REST endpoint both call the same triggerRenderVideo function.

Next Steps (PR 2)

  • Trigger.dev renderVideoTask implementation (in tasks repo)
  • Remotion SocialPost composition added to remotion submodule
  • Upload to Supabase storage after render

Related

  • Docs PR: Added POST /api/video/render to OpenAPI spec + Mintlify docs

Summary by CodeRabbit

  • New Features

    • Added a video rendering API with customizable parameters (resolution, frame rate, duration, codec) and background processing with run ID tracking.
    • Authentication supported via API keys and Bearer tokens for secure render requests.
    • Improved request validation with clear error responses and consistent CORS handling.
  • Documentation

    • Added API docs describing request/response formats and authentication expectations.