Skip to content

feat: add POST /api/video/render endpoint - #222

Open
sidneyswift wants to merge 3 commits into
testfrom
feature/video-render-endpoint
Open

sidneyswift wants to merge 3 commits into
testfrom
feature/video-render-endpoint

Conversation

@sidneyswift

@sidneyswift sidneyswift commented Feb 13, 2026 •

Copy link
Copy Markdown
Contributor

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)

File Purpose
app/api/video/render/route.ts Route handler (POST + OPTIONS)
lib/render/renderVideoHandler.ts Handler: auth → validate → trigger → respond
lib/render/validateRenderVideoBody.ts Zod schema + validation function
lib/trigger/triggerRenderVideo.ts Triggers render-video task on Trigger.dev
lib/mcp/tools/render/registerRenderVideoTool.ts MCP tool sharing triggerRenderVideo
lib/mcp/tools/render/index.ts Render tool registration group

Modified Files

File Change
lib/mcp/tools/index.ts Register render tools

Tests (18 passing)

File Tests
lib/render/__tests__/validateRenderVideoBody.test.ts 11 tests (valid inputs, defaults, error cases)
lib/render/__tests__/renderVideoHandler.test.ts 5 tests (auth, validation, trigger, error)
lib/trigger/__tests__/triggerRenderVideo.test.ts 2 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.

- Route handler at app/api/video/render/route.ts
- Zod validation for compositionId, inputProps, output settings
- Trigger function that fires render-video task on Trigger.dev
- Handler follows sandbox setup pattern: trigger → return runId
- MCP tool (render_video) shares triggerRenderVideo logic with API
- 18 tests covering validation, handler, and trigger function

Polling for render status uses existing GET /api/tasks/runs endpoint.
@vercel

vercel Bot commented Feb 13, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
recoup-api Ready Ready Preview Feb 20, 2026 6:11am

Request Review

@coderabbitai

coderabbitai Bot commented Feb 13, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

Adds a new video rendering feature: a POST /api/video/render route with CORS, request validation, authentication, Trigger.dev task triggering, and MCP tool registration for a render_video tool.

Changes

Cohort / File(s) Summary
API Route & Handler
app/api/video/render/route.ts, lib/render/renderVideoHandler.ts
New Next.js route with OPTIONS CORS preflight and POST handler. Handler authenticates, parses/validates body, triggers a background render via Trigger.dev, and returns { status: "processing", runId } or error responses (with CORS headers).
Request Validation
lib/render/validateRenderVideoBody.ts
Adds Zod schema renderVideoBodySchema and validateRenderVideoBody to enforce compositionId and defaults (width=720, height=1280, fps=30, durationInFrames, codec). Returns validated payload or structured 400 response with CORS headers.
Trigger Integration
lib/trigger/triggerRenderVideo.ts
Introduces RenderVideoPayload type and triggerRenderVideo function that calls Trigger.dev tasks.trigger("render-video", payload) and returns the task handle.
MCP Tools Registration
lib/mcp/tools/index.ts, lib/mcp/tools/render/index.ts, lib/mcp/tools/render/registerRenderVideoTool.ts
Registers render tools into MCP pipeline. Adds registerAllRenderTools(server) which calls registerRenderVideoTool, registering a render_video tool schema that authenticates via extra.authInfo, resolves accountId, and invokes triggerRenderVideo.

Sequence Diagram

sequenceDiagram
    participant Client
    participant APIRoute as API Route<br/>/api/video/render
    participant Handler as renderVideoHandler
    participant Validator as validateRenderVideoBody
    participant Trigger as Trigger.dev
    participant MCP as MCP Tool Reg

    Client->>APIRoute: POST /api/video/render (auth + body)
    APIRoute->>Handler: POST(request)
    Handler->>Handler: validateAuthContext (x-api-key/Bearer)
    Handler->>Validator: validateRenderVideoBody(body)
    Validator-->>Handler: RenderVideoBody (or 400 error)
    Handler->>Trigger: triggerRenderVideo(payload with accountId)
    Trigger-->>Handler: { runId } / task handle
    Handler-->>Client: 200 {status:"processing", runId} + CORS
    Note over MCP: registerAllRenderTools -> registerRenderVideoTool registers tool that triggers same flow via triggerRenderVideo
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🎬 A route awakes to render light,
Zod guards the shape, auth holds the key,
Trigger.dev hums a background flight,
MCP tools whisper "enqueue for me",
Frames align — processing set free.

🚥 Pre-merge checks | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Solid & Clean Code ❓ Inconclusive Source code files from PR summary are not accessible in the repository despite extensive search attempts. Verify PR branch is checked out, files are committed (not just staged), and correct remote is accessed. Then re-run assessment.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/video-render-endpoint

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@lib/mcp/tools/render/registerRenderVideoTool.ts`:
- Around line 70-76: The code manually extracts accountId from extra.authInfo;
replace that with the shared resolver: import resolveAccountId and call await
resolveAccountId({ authInfo }) using the existing authInfo variable, then check
the returned { accountId, error } and return getToolResultError(error ||
"Authentication required.") if error or no accountId; update the handler where
authInfo is used (the async handler in registerRenderVideoTool) to follow the
same pattern as registerUpdatePulseTool and registerCreateNewArtistTool.
🧹 Nitpick comments (4)
lib/trigger/triggerRenderVideo.ts (1)

1-27: Clean implementation — good SRP and DRY foundation.

This function correctly serves as the single shared trigger point for both the REST endpoint and MCP tool. The type definition, JSDoc, and delegation are all solid.

One minor note: the "render-video" task ID on Line 26 is a magic string. Per coding guidelines, shared constants should live in lib/const.ts. If this identifier is referenced elsewhere (e.g., in the tasks repo), extracting it would reduce drift risk.

lib/render/validateRenderVideoBody.ts (1)

11-21: Schema defaults are duplicated in the MCP tool — consider reusing.

The defaults defined here (720×1280, 30 fps, 240 frames, "h264") are manually replicated in lib/mcp/tools/render/registerRenderVideoTool.ts (Lines 82–86) via ?? fallback expressions. If these values ever change, they'll need updating in two places.

Consider exporting the defaults (or the schema itself) so the MCP tool can reference the same source of truth, or at minimum add a comment linking the two.

lib/render/renderVideoHandler.ts (1)

45-48: Consider HTTP 202 Accepted for async task dispatch.

The endpoint returns 200 with status: "processing", but semantically 202 Accepted is the standard HTTP status for "request accepted, processing not yet complete." If this deviates from an established project convention, feel free to keep 200 — but 202 more clearly signals the async nature to API consumers.

lib/mcp/tools/render/registerRenderVideoTool.ts (1)

11-46: Duplicated schema constraints with validateRenderVideoBody.ts.

The validation constraints (e.g., .int().min(1).max(3840) for width/height, .min(1).max(60) for fps, .min(1).max(1800) for durationInFrames, the codec enum) are defined in both this file and lib/render/validateRenderVideoBody.ts. If constraints diverge over time, the MCP tool and REST endpoint would accept different inputs.

Consider extracting the shared constraints or base schema into a common module that both consumers can reference, while each applies its own .optional() vs .default() semantics on top.

Comment thread lib/mcp/tools/index.ts Resolved

This branch was successfully deployed

1 active deployment
Preview — 98bfe959 Deployed Feb 20, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants