Skip to content

🎥 Make videos programmatically with React

Remove zod-incompatible AI sdk

Vlad Mdb93f507abd4
diff --git a/bun.lock b/bun.lock
index 7c53de2c26..b64cb7aa32 100644
--- a/bun.lock
+++ b/bun.lock
@@ -1320,17 +1320,15 @@
"name": "template-ai-video",
"version": "1.0.0",
"dependencies": {
- "@ai-sdk/openai": "^2.0.53",
"@remotion/animation-utils": "workspace:*",
"@remotion/cli": "workspace:*",
"@remotion/google-fonts": "workspace:*",
"@remotion/layout-utils": "workspace:*",
"@remotion/zod-types": "workspace:*",
- "ai": "^5.0.76",
"react": "19.0.0",
"react-dom": "19.0.0",
"remotion": "workspace:*",
- "zod": "^4.1.12",
+ "zod": "3.22.3",
},
"devDependencies": {
"@elevenlabs/elevenlabs-js": "^2.20.0",
@@ -1349,6 +1347,7 @@
"typescript": "5.8.2",
"uuid": "^13.0.0",
"yargs": "^18.0.0",
+ "zod-to-json-schema": "^3.24.6",
},
},
"packages/template-audiogram": {
@@ -2043,14 +2042,6 @@
"packages": {
"@aashutoshrathi/word-wrap": ["@aashutoshrathi/[email protected]", "", {}, "sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA=="],
- "@ai-sdk/gateway": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "2.0.0", "@ai-sdk/provider-utils": "3.0.12", "@vercel/oidc": "3.0.3" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-Gj0PuawK7NkZuyYgO/h5kDK/l6hFOjhLdTq3/Lli1FTl47iGmwhH1IZQpAL3Z09BeFYWakcwUmn02ovIm2wy9g=="],
-
- "@ai-sdk/openai": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "2.0.0", "@ai-sdk/provider-utils": "3.0.12" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-GIkR3+Fyif516ftXv+YPSPstnAHhcZxNoR2s8uSHhQ1yBT7I7aQYTVwpjAuYoT3GR+TeP50q7onj2/nDRbT2FQ=="],
-
- "@ai-sdk/provider": ["@ai-sdk/[email protected]", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-6o7Y2SeO9vFKB8lArHXehNuusnpddKPk7xqL7T2/b+OvXMRIXUO1rR4wcv1hAFUAT9avGZshty3Wlua/XA7TvA=="],
-
- "@ai-sdk/provider-utils": ["@ai-sdk/[email protected]", "", { "dependencies": { "@ai-sdk/provider": "2.0.0", "@standard-schema/spec": "^1.0.0", "eventsource-parser": "^3.0.5" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-ZtbdvYxdMoria+2SlNarEk6Hlgyf+zzcznlD55EAl+7VZvJaSg2sqPvwArY7L6TfDEDJsnCq0fdhBSkYo0Xqdg=="],
-
"@algolia/abtesting": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.40.0", "@algolia/requester-browser-xhr": "5.40.0", "@algolia/requester-fetch": "5.40.0", "@algolia/requester-node-http": "5.40.0" } }, "sha512-c4M/Z/KWkEG+RHpZsWKDTTlApXu3fe4vlABNcpankWBhdMe4oPZ/r4JxEr2zKUP6K+BT66tnp8UbHmgOd/vvqQ=="],
"@algolia/autocomplete-core": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/autocomplete-plugin-algolia-insights": "1.17.9", "@algolia/autocomplete-shared": "1.17.9" } }, "sha512-O7BxrpLDPJWWHv/DLA9DRFWs+iY1uOJZkqUwjS5HSZAGcl0hIVCQ97LTLewiZmZ402JYUrun+8NqFP+hCknlbQ=="],
@@ -3519,8 +3510,6 @@
"@smithy/util-waiter": ["@smithy/[email protected]", "", { "dependencies": { "@smithy/abort-controller": "4.0.2", "@smithy/types": "4.2.0", "tslib": "2.8.1" } }, "sha512-JtaY3FxmD+te+KSI2FJuEcfNC9T/DGGVf551babM7fAaXhjJUt7oSYurH1Devxd2+BOSUACCgt3buinx4UnmEA=="],
- "@standard-schema/spec": ["@standard-schema/[email protected]", "", {}, "sha512-m2bOd0f2RT9k8QJx1JN85cZYyH1RqFBdlwtkSlf4tBDYLCiiZnv1fIIwacK6cqwXavOydf0NPToMQgpKq+dVlA=="],
-
"@svgr/babel-plugin-add-jsx-attribute": ["@svgr/[email protected]", "", { "peerDependencies": { "@babel/core": "7.23.2" } }, "sha512-b9MIk7yhdS1pMCZM8VeNfUlSKVRhsHZNMl5O9SfaX0l0t5wjdgu4IDzGB8bpnGBBOjGST3rRFVsaaEtI4W6f7g=="],
"@svgr/babel-plugin-remove-jsx-attribute": ["@svgr/[email protected]", "", { "peerDependencies": { "@babel/core": "7.23.2" } }, "sha512-BcCkm/STipKvbCl6b7QFrMh/vx00vIP63k2eM66MfHJzPr6O2U0jYEViXkHJWqXqQYjdeA9cuCl5KWmlwjDvbA=="],
@@ -3923,8 +3912,6 @@
"@vanilla-extract/private": ["@vanilla-extract/[email protected]", "", {}, "sha512-ytsG/JLweEjw7DBuZ/0JCN4WAQgM9erfSTdS1NQY778hFQSZ6cfCDEZZ0sgVm4k54uNz6ImKB33AYvSR//fjxw=="],
- "@vercel/oidc": ["@vercel/[email protected]", "", {}, "sha512-yNEQvPcVrK9sIe637+I0jD6leluPxzwJKx/Haw6F4H77CdDsszUn5V3o96LPziXkSNE2B83+Z3mjqGKBK/R6Gg=="],
-
"@vercel/remix": ["@vercel/[email protected]", "", { "dependencies": { "@vercel/static-config": "3.0.0", "isbot": "3.8.0", "ts-morph": "12.0.0" }, "peerDependencies": { "@remix-run/dev": "2.15.2", "@remix-run/node": "2.15.2", "@remix-run/server-runtime": "2.15.2", "react": "19.0.0", "react-dom": "19.0.0" } }, "sha512-JZJmuM/pZl5zLACRHzq2uOamzTOeiKRnco0o07A+hUxTKemhS1tqc2R9PdQ6Mf/8ZcXY5ZxW5tah3zjBea6D4w=="],
"@vercel/static-config": ["@vercel/[email protected]", "", { "dependencies": { "ajv": "8.6.3", "json-schema-to-ts": "1.6.4", "ts-morph": "12.0.0" } }, "sha512-2qtvcBJ1bGY0dYGYh3iM7yGKkk971FujLEDXzuW5wcZsPr1GSEjO/w2iSr3qve6nDDtBImsGoDEnus5FI4+fIw=="],
@@ -4021,8 +4008,6 @@
"aggregate-error": ["[email protected]", "", { "dependencies": { "clean-stack": "2.2.0", "indent-string": "4.0.0" } }, "sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA=="],
- "ai": ["[email protected]", "", { "dependencies": { "@ai-sdk/gateway": "2.0.0", "@ai-sdk/provider": "2.0.0", "@ai-sdk/provider-utils": "3.0.12", "@opentelemetry/api": "1.9.0" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-ZCxi1vrpyCUnDbtYrO/W8GLvyacV9689f00yshTIQ3mFFphbD7eIv40a2AOZBv3GGRA7SSRYIDnr56wcS/gyQg=="],
-
"ai-improvements": ["ai-improvements@workspace:packages/ai-improvements"],
"ajv": ["[email protected]", "", { "dependencies": { "fast-deep-equal": "3.1.3", "fast-json-stable-stringify": "2.1.0", "json-schema-traverse": "0.4.1", "uri-js": "4.4.1" } }, "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g=="],
@@ -5255,8 +5240,6 @@
"json-parse-even-better-errors": ["[email protected]", "", {}, "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w=="],
- "json-schema": ["[email protected]", "", {}, "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA=="],
-
"json-schema-to-ts": ["[email protected]", "", { "dependencies": { "@types/json-schema": "7.0.15", "ts-toolbelt": "6.15.5" } }, "sha512-pR4yQ9DHz6itqswtHCm26mw45FSNfQ9rEQjosaZErhn5J3J2sIViQiz8rDaezjKAhFGpmsoczYVBgGHzFw/stA=="],
"json-schema-traverse": ["[email protected]", "", {}, "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="],
@@ -6969,14 +6952,6 @@
"zwitch": ["[email protected]", "", {}, "sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A=="],
- "@ai-sdk/gateway/zod": ["[email protected]", "", {}, "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ=="],
-
- "@ai-sdk/openai/zod": ["[email protected]", "", {}, "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ=="],
-
- "@ai-sdk/provider-utils/eventsource-parser": ["[email protected]", "", {}, "sha512-Vo1ab+QXPzZ4tCa8SwIHJFaSzy4R6SHf7BY79rFBDf0idraZWAkYrDjDj8uWaSm3S2TK+hJ7/t1CEmZ7jXw+pg=="],
-
- "@ai-sdk/provider-utils/zod": ["[email protected]", "", {}, "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ=="],
-
"@algolia/autocomplete-preset-algolia/@algolia/client-search": ["@algolia/[email protected]", "", { "dependencies": { "@algolia/client-common": "5.24.0", "@algolia/requester-browser-xhr": "5.24.0", "@algolia/requester-fetch": "5.24.0", "@algolia/requester-node-http": "5.24.0" } }, "sha512-k+nuciQuq7WERNNE+hsx3DX636zIy+9R4xdtvW3PANT2a2BDGOv3fv2mta8+QUMcVTVcGe/Mo3QCb4pc1HNoxA=="],
"@algolia/autocomplete-preset-algolia/algoliasearch": ["[email protected]", "", { "dependencies": { "@algolia/client-abtesting": "5.18.0", "@algolia/client-analytics": "5.18.0", "@algolia/client-common": "5.18.0", "@algolia/client-insights": "5.18.0", "@algolia/client-personalization": "5.18.0", "@algolia/client-query-suggestions": "5.18.0", "@algolia/client-search": "5.18.0", "@algolia/ingestion": "1.18.0", "@algolia/monitoring": "1.18.0", "@algolia/recommend": "5.18.0", "@algolia/requester-browser-xhr": "5.18.0", "@algolia/requester-fetch": "5.18.0", "@algolia/requester-node-http": "5.18.0" } }, "sha512-/tfpK2A4FpS0o+S78o3YSdlqXr0MavJIDlFK3XZrlXLy7vaRXJvW5jYg3v5e/wCaF8y0IpMjkYLhoV6QqfpOgw=="],
@@ -8039,8 +8014,6 @@
"acorn-jsx/acorn": ["[email protected]", "", { "bin": { "acorn": "bin/acorn" } }, "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA=="],
- "ai/zod": ["[email protected]", "", {}, "sha512-gzUt/qt81nXsFGKIFcC3YnfEAx5NkunCfnDlvuBSSFS02bcXu4Lmea0AFIUwbLWxWPx3d9p8S5QoaujKcNQxcQ=="],
-
"ajv-formats/ajv": ["[email protected]", "", { "dependencies": { "fast-deep-equal": "3.1.3", "json-schema-traverse": "1.0.0", "require-from-string": "2.0.2", "uri-js": "4.4.1" } }, "sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg=="],
"ansi-align/string-width": ["[email protected]", "", { "dependencies": { "emoji-regex": "8.0.0", "is-fullwidth-code-point": "3.0.0", "strip-ansi": "6.0.1" } }, "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g=="],
@@ -8921,8 +8894,6 @@
"template-ai-video/uuid": ["[email protected]", "", { "bin": { "uuid": "dist-node/bin/uuid" } }, "sha512-XQegIaBTVUjSHliKqcnFqYypAd4S+WCYt5NIeRs6w/UAry7z8Y9j5ZwRRL4kzq9U3sD6v+85er9FvkEaBpji2w=="],
- "template-ai-video/zod": ["[email protected]", "", {}, "sha512-JInaHOamG8pt5+Ey8kGmdcAcg3OL9reK8ltczgHTAwNhMys/6ThXHityHxVV2p3fkw/c+MAvBHFVYHFZDmjMCQ=="],
-
"template-next-app/@typescript-eslint/eslint-plugin": ["@typescript-eslint/[email protected]", "", { "dependencies": { "@eslint-community/regexpp": "^4.10.0", "@typescript-eslint/scope-manager": "8.46.0", "@typescript-eslint/type-utils": "8.46.0", "@typescript-eslint/utils": "8.46.0", "@typescript-eslint/visitor-keys": "8.46.0", "graphemer": "^1.4.0", "ignore": "^7.0.0", "natural-compare": "^1.4.0", "ts-api-utils": "^2.1.0" }, "peerDependencies": { "@typescript-eslint/parser": "^8.46.0", "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <6.0.0" } }, "sha512-hA8gxBq4ukonVXPy0OKhiaUh/68D0E88GSmtC1iAEnGaieuDi38LhS7jdCHRLi6ErJBNDGCzvh5EnzdPwUc0DA=="],
"template-next-app/@typescript-eslint/parser": ["@typescript-eslint/[email protected]", "", { "dependencies": { "@typescript-eslint/scope-manager": "8.46.0", "@typescript-eslint/types": "8.46.0", "@typescript-eslint/typescript-estree": "8.46.0", "@typescript-eslint/visitor-keys": "8.46.0", "debug": "^4.3.4" }, "peerDependencies": { "eslint": "^8.57.0 || ^9.0.0", "typescript": ">=4.8.4 <6.0.0" } }, "sha512-n1H6IcDhmmUEG7TNVSspGmiHHutt7iVKtZwRppD7e04wha5MrkV1h3pti9xQLcCMt6YWsncpoT0HMjkH1FNwWQ=="],
diff --git a/packages/template-ai-video/cli/service.ts b/packages/template-ai-video/cli/service.ts
index 551e167918..9e63b6b352 100644
--- a/packages/template-ai-video/cli/service.ts
+++ b/packages/template-ai-video/cli/service.ts
@@ -1,11 +1,9 @@
import z from "zod";
-import { createOpenAI } from "@ai-sdk/openai";
-import { generateObject } from "ai";
-import { experimental_generateImage as generateImage } from "ai";
import * as fs from "fs";
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
import { CharacterAlignmentResponseModel } from "@elevenlabs/elevenlabs-js/api";
import { ImageHeight, ImageWidth } from "../src/lib/constants";
+import { zodToJsonSchema } from "zod-to-json-schema";
let apiKey: string | null = null;
@@ -13,29 +11,49 @@ export const setApiKey = (key: string) => {
apiKey = key;
};
-const getOpenAiProvider = () => {
- if (!apiKey) {
- throw "Missing OpenAI API KEY";
- }
-
- return createOpenAI({
- apiKey,
- });
-};
-
export const openaiStructuredCompletion = async <T>(
prompt: string,
schema: z.ZodType<T>,
): Promise<T> => {
- const openai = getOpenAiProvider();
-
- const { object } = await generateObject({
- model: openai("gpt-4.1"),
- schema,
- prompt,
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const jsonSchema = zodToJsonSchema(schema) as any;
+
+ const res = await fetch("https://api.openai.com/v1/chat/completions", {
+ method: "POST",
+ headers: {
+ Authorization: `Bearer ${apiKey}`,
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ model: "gpt-4.1",
+ messages: [{ role: "user", content: prompt }],
+ response_format: {
+ type: "json_schema",
+ json_schema: {
+ name: "response",
+ schema: {
+ type: jsonSchema.type || "object",
+ properties: jsonSchema.properties,
+ required: jsonSchema.required,
+ additionalProperties: jsonSchema.additionalProperties ?? false,
+ },
+ strict: true,
+ },
+ },
+ }),
});
- return object as T;
+ if (!res.ok) throw new Error(`OpenAI error: ${await res.text()}`);
+
+ const data = await res.json();
+ const content = data.choices[0]?.message?.content;
+
+ if (!content) {
+ throw new Error("No content in OpenAI response");
+ }
+
+ const parsed = JSON.parse(content);
+ return schema.parse(parsed);
};
function saveUint8ArrayToPng(uint8Array: Uint8Array, filePath: string) {
@@ -44,15 +62,27 @@ function saveUint8ArrayToPng(uint8Array: Uint8Array, filePath: string) {
}
export const generateAiImage = async (prompt: string, path: string) => {
- const openai = getOpenAiProvider();
-
- const { image } = await generateImage({
- model: openai.image("dall-e-3"),
- prompt,
- size: `${ImageWidth}x${ImageHeight}`,
+ const res = await fetch("https://api.openai.com/v1/images/generations", {
+ method: "POST",
+ headers: {
+ Authorization: `Bearer ${apiKey}`,
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({
+ model: "dall-e-3",
+ prompt,
+ size: `${ImageWidth}x${ImageHeight}`,
+ response_format: "b64_json",
+ }),
});
- saveUint8ArrayToPng(image.uint8Array, path);
+ if (!res.ok) throw new Error(`OpenAI error: ${await res.text()}`);
+
+ const data = await res.json();
+ const buffer = Buffer.from(data.data[0].b64_json, "base64");
+ const uint8Array = new Uint8Array(buffer);
+
+ saveUint8ArrayToPng(uint8Array, path);
};
export const getGenerateStoryPrompt = (title: string, topic: string) => {
diff --git a/packages/template-ai-video/package.json b/packages/template-ai-video/package.json
index 88fbc4b28a..e3be336d28 100644
--- a/packages/template-ai-video/package.json
+++ b/packages/template-ai-video/package.json
@@ -12,17 +12,15 @@
"repository": {},
"license": "UNLICENSED",
"dependencies": {
- "@ai-sdk/openai": "^2.0.53",
"@remotion/animation-utils": "workspace:*",
"@remotion/cli": "workspace:*",
"@remotion/google-fonts": "workspace:*",
"@remotion/layout-utils": "workspace:*",
"@remotion/zod-types": "workspace:*",
- "ai": "^5.0.76",
"react": "19.0.0",
"react-dom": "19.0.0",
"remotion": "workspace:*",
- "zod": "^4.1.12"
+ "zod": "3.22.3"
},
"devDependencies": {
"@elevenlabs/elevenlabs-js": "^2.20.0",
@@ -40,7 +38,8 @@
"tsx": "^4.20.6",
"typescript": "5.8.2",
"uuid": "^13.0.0",
- "yargs": "^18.0.0"
+ "yargs": "^18.0.0",
+ "zod-to-json-schema": "^3.24.6"
},
"private": true
}
diff --git a/packages/template-ai-video/src/Root.tsx b/packages/template-ai-video/src/Root.tsx
index 4c69f81ca3..af7768c794 100644
--- a/packages/template-ai-video/src/Root.tsx
+++ b/packages/template-ai-video/src/Root.tsx
@@ -5,7 +5,7 @@ import {
getInputProps,
} from "remotion";
import { AIVideo, aiVideoSchema } from "./components/AIVideo";
-import { useEffect, useState } from "react";
+import { useEffect, useMemo, useState } from "react";
import { FPS, WindowHeight, WindowWidth } from "./lib/constants";
import { getTimelinePath, loadTimelineFromFile } from "./lib/utils";
@@ -17,7 +17,10 @@ export const RemotionRoot: React.FC = () => {
const inputProps = getInputProps<InputProps>();
const [frameLength, setFrameLength] = useState(1);
- const resolvedProjectName = inputProps.projectName ?? "history_of_venus";
+ const resolvedProjectName = useMemo(
+ () => inputProps.projectName ?? "history_of_venus",
+ [inputProps],
+ );
useEffect(() => {
const handle = delayRender("Calculating FPS duration...");
@@ -35,7 +38,7 @@ export const RemotionRoot: React.FC = () => {
return () => {
continueRender(handle);
};
- }, []);
+ }, [resolvedProjectName]);
return (
<>
@@ -46,7 +49,6 @@ export const RemotionRoot: React.FC = () => {
fps={FPS}
width={WindowWidth}
height={WindowHeight}
- // @ts-expect-error zod version mismatch
schema={aiVideoSchema}
defaultProps={{
projectName: resolvedProjectName,