"use client"; import { useState } from "react"; import { API_DOCS_URL } from "@/lib/plans"; type Props = { initialStatus: { configured: boolean; prefix: string | null }; initialRateLimit: { limit: number; used: number; remaining: number; windowSeconds: number; resetsInSeconds: number; }; }; export function ApiKeySettings({ initialStatus, initialRateLimit }: Props) { const [status, setStatus] = useState(initialStatus); const [newKey, setNewKey] = useState(null); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); async function generateKey() { if (status.configured && !confirm("Replace your existing API key?")) return; setLoading(true); setError(null); setNewKey(null); try { const res = await fetch("/api/account/api-key", { method: "POST" }); const data = await res.json(); if (!res.ok) throw new Error(data.error || "Failed to generate API key"); setNewKey(data.apiKey); setStatus({ configured: true, prefix: data.prefix }); } catch (err) { setError(err instanceof Error ? err.message : "Failed to generate API key"); } finally { setLoading(false); } } async function revokeKey() { if (!confirm("Revoke your API key?")) return; setLoading(true); setError(null); try { const res = await fetch("/api/account/api-key", { method: "DELETE" }); const data = await res.json(); if (!res.ok) throw new Error(data.error || "Failed to revoke API key"); setStatus({ configured: false, prefix: null }); setNewKey(null); } catch (err) { setError(err instanceof Error ? err.message : "Failed to revoke API key"); } finally { setLoading(false); } } return (

Use the REST API to upload files and create video jobs programmatically.

Rate limit: {initialRateLimit.limit} requests per {initialRateLimit.windowSeconds} seconds.

{status.configured && status.prefix && (

Active key: {status.prefix}…

)} {newKey && (

Copy your new API key now

{newKey}
)} {error &&

{error}

}
{status.configured && ( )} API documentation
); }