🎥 Make videos programmatically with React
Remove OpenAI API Key entry
ASchwad52f17357945d
diff --git a/packages/template-code-generation/src/app/api/generate/route.ts b/packages/template-code-generation/src/app/api/generate/route.tsindex 8b2cb0fb1e..6f3d32c113 100644--- a/packages/template-code-generation/src/app/api/generate/route.ts+++ b/packages/template-code-generation/src/app/api/generate/route.ts@@ -523,20 +523,18 @@ IMPORTANT RULES:`;export async function POST(req: Request) {- const { prompt, model = "gpt-5-mini", apiKey } = await req.json();+ const { prompt, model = "gpt-5-mini" } = await req.json();- if (!apiKey) {- return new Response(JSON.stringify({ error: "API key is required" }), {- status: 400,- headers: { "Content-Type": "application/json" },- });- }+ const apiKey = process.env.OPENAI_API_KEY;- if (!apiKey.startsWith("sk-")) {- return new Response(JSON.stringify({ error: "Invalid API key format" }), {- status: 400,- headers: { "Content-Type": "application/json" },- });+ if (!apiKey) {+ return new Response(+ JSON.stringify({ error: "OPENAI_API_KEY environment variable is not set" }),+ {+ status: 500,+ headers: { "Content-Type": "application/json" },+ },+ );}// Parse model ID - format can be "model-name" or "model-name:reasoning_effort"diff --git a/packages/template-code-generation/src/app/layout.tsx b/packages/template-code-generation/src/app/layout.tsxindex d398a02ff0..e19d2dc5cb 100644--- a/packages/template-code-generation/src/app/layout.tsx+++ b/packages/template-code-generation/src/app/layout.tsx@@ -1,6 +1,5 @@import "../../styles/global.css";import { Metadata, Viewport } from "next";-import { ApiKeyProvider } from "@/context/ApiKeyContext";export const metadata: Metadata = {title: "Remotion and Next.js",@@ -20,9 +19,7 @@ export default function RootLayout({}) {return (<html lang="en">- <body className="bg-background">- <ApiKeyProvider>{children}</ApiKeyProvider>- </body>+ <body className="bg-background">{children}</body></html>);}diff --git a/packages/template-code-generation/src/components/PromptInput.tsx b/packages/template-code-generation/src/components/PromptInput.tsxindex e7e362f207..0c490b5a4d 100644--- a/packages/template-code-generation/src/components/PromptInput.tsx+++ b/packages/template-code-generation/src/components/PromptInput.tsx@@ -18,13 +18,6 @@ import {SelectTrigger,SelectValue,} from "@/components/ui/select";-import {- Tooltip,- TooltipContent,- TooltipProvider,- TooltipTrigger,-} from "@/components/ui/tooltip";-import { useApiKeyContext } from "@/context/ApiKeyContext";import { examplePrompts } from "@/data/examplePrompts";const iconMap: Record<string, LucideIcon> = {@@ -73,7 +66,6 @@ export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(},ref,) {- const { apiKey, hasApiKey, isLoaded } = useApiKeyContext();const [uncontrolledPrompt, setUncontrolledPrompt] = useState("");const [model, setModel] = useState<ModelId>("gpt-5.1:low");@@ -84,7 +76,7 @@ export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(const [isLoading, setIsLoading] = useState(false);const runGeneration = async () => {- if (!prompt.trim() || isLoading || !hasApiKey) return;+ if (!prompt.trim() || isLoading) return;setIsLoading(true);onStreamingChange?.(true);@@ -93,7 +85,7 @@ export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(const response = await fetch("/api/generate", {method: "POST",headers: { "Content-Type": "application/json" },- body: JSON.stringify({ prompt, model, apiKey }),+ body: JSON.stringify({ prompt, model }),});if (!response.ok) {@@ -232,30 +224,17 @@ export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(</SelectContent></Select>- <TooltipProvider>- <Tooltip>- <TooltipTrigger asChild>- <button- type="submit"- disabled={isLoading || !prompt.trim() || !hasApiKey}- className="p-2 rounded-lg bg-white text-black hover:bg-gray-200 disabled:opacity-30 disabled:cursor-not-allowed transition-all"- >- {isLoading ? (- <Loader2 className="w-5 h-5 animate-spin" />- ) : (- <ArrowUp className="w-5 h-5" />- )}- </button>- </TooltipTrigger>- {!hasApiKey && isLoaded && (- <TooltipContent>- <p>- Add your OpenAI API key in Settings to enable generation- </p>- </TooltipContent>- )}- </Tooltip>- </TooltipProvider>+ <button+ type="submit"+ disabled={isLoading || !prompt.trim()}+ className="p-2 rounded-lg bg-white text-black hover:bg-gray-200 disabled:opacity-30 disabled:cursor-not-allowed transition-all"+ >+ {isLoading ? (+ <Loader2 className="w-5 h-5 animate-spin" />+ ) : (+ <ArrowUp className="w-5 h-5" />+ )}+ </button></div></div>@@ -264,7 +243,7 @@ export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(isLanding ? "justify-center mt-6 gap-2" : ""}`}>- <span className="text-[#666] text-xs mr-1">Try</span>+ <span className="text-[#666] text-xs mr-1">Prompt Examples</span>{examplePrompts.map((example) => {const Icon = iconMap[example.icon];return (@@ -278,7 +257,9 @@ export const PromptInput = forwardRef<PromptInputRef, PromptInputProps>(}}className={`rounded-full bg-[#1a1a1a] border hover:brightness-125 transition-all flex items-center gap-1 px-1.5 py-0.5 text-[11px]`}>- {Icon && <Icon className={isLanding ? "w-3 h-3" : "w-3 h-3"} />}+ {Icon && (+ <Icon className={isLanding ? "w-3 h-3" : "w-3 h-3"} />+ )}{example.headline}</button>);diff --git a/packages/template-code-generation/src/components/SettingsModal.tsx b/packages/template-code-generation/src/components/SettingsModal.tsxindex 0b52f60c53..54bd15eab3 100644--- a/packages/template-code-generation/src/components/SettingsModal.tsx+++ b/packages/template-code-generation/src/components/SettingsModal.tsx@@ -1,6 +1,6 @@"use client";-import { useState, useEffect } from "react";+import { useState } from "react";import {Dialog,DialogContent,@@ -10,8 +10,7 @@ import {DialogTrigger,DialogFooter,} from "@/components/ui/dialog";-import { Settings, Eye, EyeOff, ExternalLink } from "lucide-react";-import { useApiKeyContext } from "@/context/ApiKeyContext";+import { Settings } from "lucide-react";import { Button } from "@/components/ui/button";interface SettingsModalProps {@@ -27,30 +26,7 @@ export function SettingsModal({fps,onFpsChange,}: SettingsModalProps) {- const { apiKey, setApiKey, clearApiKey, hasApiKey } = useApiKeyContext();const [open, setOpen] = useState(false);- const [inputValue, setInputValue] = useState("");- const [showKey, setShowKey] = useState(false);-- // Sync input with stored key when modal opens- useEffect(() => {- if (open) {- setInputValue(apiKey);- setShowKey(false);- }- }, [open, apiKey]);-- const handleSave = () => {- setApiKey(inputValue.trim());- setOpen(false);- };-- const handleClear = () => {- clearApiKey();- setInputValue("");- };-- const isValidFormat = inputValue.startsWith("sk-") && inputValue.length > 20;return (<Dialog open={open} onOpenChange={setOpen}>@@ -64,7 +40,7 @@ export function SettingsModal({<DialogHeader><DialogTitle>Settings</DialogTitle><DialogDescription className="text-[#888]">- Configure your animation and API settings.+ Configure your animation settings.</DialogDescription></DialogHeader><div className="grid gap-6 py-4">@@ -111,74 +87,11 @@ export function SettingsModal({{durationInFrames} frames / {fps} FPS)</p></div>-- <div className="grid gap-2">- <h3 className="text-sm font-medium text-white">API</h3>- <label htmlFor="api-key" className="text-[#888] text-sm">- OpenAI API Key- </label>- <div className="relative">- <input- id="api-key"- type={showKey ? "text" : "password"}- value={inputValue}- onChange={(e) => setInputValue(e.target.value)}- placeholder="sk-..."- className="w-full px-3 py-2 pr-10 rounded border border-[#333] bg-[#0f0f0f] text-white text-sm font-sans placeholder:text-[#666] focus:outline-none focus:border-indigo-500"- />- <button- type="button"- onClick={() => setShowKey(!showKey)}- className="absolute right-2 top-1/2 -translate-y-1/2 text-[#888] hover:text-white bg-transparent border-none cursor-pointer"- >- {showKey ? (- <EyeOff className="w-4 h-4" />- ) : (- <Eye className="w-4 h-4" />- )}- </button>- </div>- {inputValue && !isValidFormat && (- <p className="text-sm text-red-400">- API key should start with "sk-"- </p>- )}- <p className="text-xs text-[#666]">- Your API key is stored locally in your browser and only sent to- OpenAI for generation requests.- </p>- <a- href="https://platform.openai.com/api-keys"- target="_blank"- rel="noopener noreferrer"- className="text-xs text-indigo-400 hover:text-indigo-300 flex items-center gap-1 w-fit"- >- Get your API key from OpenAI- <ExternalLink className="w-3 h-3" />- </a>- </div></div>- <DialogFooter className="flex gap-2 sm:justify-between">- {hasApiKey && (- <Button- onClick={handleClear}- variant="destructive"- className="mr-auto"- >- Clear Key- </Button>- )}- <div className="flex gap-2">- <Button variant="outline" onClick={() => setOpen(false)}>- Cancel- </Button>- <Button- onClick={handleSave}- disabled={!inputValue.trim() || !isValidFormat}- >- Save- </Button>- </div>+ <DialogFooter>+ <Button variant="outline" onClick={() => setOpen(false)}>+ Close+ </Button></DialogFooter></DialogContent></Dialog>diff --git a/packages/template-code-generation/src/context/ApiKeyContext.tsx b/packages/template-code-generation/src/context/ApiKeyContext.tsxdeleted file mode 100644index 487acdeba9..0000000000--- a/packages/template-code-generation/src/context/ApiKeyContext.tsx+++ /dev/null@@ -1,32 +0,0 @@-"use client";--import { createContext, useContext, ReactNode } from "react";-import { useApiKey } from "../hooks/useApiKey";--interface ApiKeyContextType {- apiKey: string;- setApiKey: (key: string) => void;- clearApiKey: () => void;- hasApiKey: boolean;- isLoaded: boolean;-}--const ApiKeyContext = createContext<ApiKeyContextType | undefined>(undefined);--export function ApiKeyProvider({ children }: { children: ReactNode }) {- const apiKeyState = useApiKey();-- return (- <ApiKeyContext.Provider value={apiKeyState}>- {children}- </ApiKeyContext.Provider>- );-}--export function useApiKeyContext() {- const context = useContext(ApiKeyContext);- if (context === undefined) {- throw new Error("useApiKeyContext must be used within an ApiKeyProvider");- }- return context;-}diff --git a/packages/template-code-generation/src/hooks/useApiKey.ts b/packages/template-code-generation/src/hooks/useApiKey.tsdeleted file mode 100644index 72d069d468..0000000000--- a/packages/template-code-generation/src/hooks/useApiKey.ts+++ /dev/null@@ -1,49 +0,0 @@-"use client";--import { useState, useEffect, useCallback } from "react";--const STORAGE_KEY = "openai-api-key";--export function useApiKey() {- const [apiKey, setApiKeyState] = useState<string>("");- const [isLoaded, setIsLoaded] = useState(false);-- // Load from localStorage on mount (client-side only)- useEffect(() => {- if (typeof window !== "undefined") {- const stored = localStorage.getItem(STORAGE_KEY);- if (stored) {- setApiKeyState(stored);- }- setIsLoaded(true);- }- }, []);-- // Save to localStorage and update state- const setApiKey = useCallback((key: string) => {- setApiKeyState(key);- if (typeof window !== "undefined") {- if (key) {- localStorage.setItem(STORAGE_KEY, key);- } else {- localStorage.removeItem(STORAGE_KEY);- }- }- }, []);-- // Clear API key- const clearApiKey = useCallback(() => {- setApiKeyState("");- if (typeof window !== "undefined") {- localStorage.removeItem(STORAGE_KEY);- }- }, []);-- return {- apiKey,- setApiKey,- clearApiKey,- isLoaded,- hasApiKey: !!apiKey,- };-}