Open source CapCut alternative.
TypeScript
feat(video): wire Veo text-to-video with hardcoded models, tiers, and pricing
David Le386d1da00a9b
diff --git a/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/video/SKILL.md b/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/video/SKILL.mdindex 29324219..acf5b172 100644--- a/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/video/SKILL.md+++ b/apps/Donkey/Sources/DonkeyRuntime/Resources/BuiltInSkills/video/SKILL.md@@ -18,9 +18,10 @@ are the user's call — so DON'T just generate. First call `user.choose` to surfpanel, then read the picks and call `video.generate`. Always GUESS sensible defaults from the requestso they can submit in one tap; only the *defaults* differ run to run.-- **Speed & quality** — a `segmented` field `tier` with options like `fast` ("Quicker, lower cost"),- `standard` ("Balanced"), `high` ("Best quality, slower"). Default from the words: "quick"/"draft" →- `fast`; "cinematic"/"high quality"/"best" → `high`; otherwise `standard`.+- **Speed & quality** — a `segmented` field `tier` with options like `lite` ("Cheapest, draft+ quality"), `fast` ("Quicker, lower cost"), `standard` ("Balanced"), `high` ("Best quality, slower").+ Default from the words: "draft"/"cheap"/"rough" → `lite`; "quick" → `fast`;+ "cinematic"/"high quality"/"best" → `high`; otherwise `standard`.- **Audio** — a `toggle` field `audio`. Default on, unless they said "silent"/"no sound".- **Length** — a `segmented` field `length` with options like `4`, `6`, `8` (seconds). Default `8` (areasonable clip length); honor an explicit ask ("a 4 second clip" → default `4`).diff --git a/site/src/lib/credits/provider-pricing.ts b/site/src/lib/credits/provider-pricing.tsindex b72d4ad0..dfe3503c 100644--- a/site/src/lib/credits/provider-pricing.ts+++ b/site/src/lib/credits/provider-pricing.ts@@ -6,7 +6,12 @@ import {elevenLabsModels,type ElevenLabsRunModel,} from "@/lib/inference/elevenlabs-models";-import { geminiModels, type GeminiModel } from "@/lib/inference/gemini-models";+import {+ geminiModels,+ veoModels,+ type GeminiModel,+ type VeoModel,+} from "@/lib/inference/gemini-models";import { openaiModels, type OpenAIRunModel } from "@/lib/inference/openai-models";import { browserUsePerStepUsd } from "@/lib/browser/pricing";@@ -42,10 +47,9 @@ export function providerCreditPricing(if (normalizedProvider === "gemini") {return geminiCreditPricing(normalizedModel);}- // The video model id is configuration (GEMINI_VIDEO_MODEL), not a hardcoded constant, so the Veo- // provider is priced per clip at the provider level rather than keyed to a specific model id.+ // Veo video ids are hardcoded (gemini-models.ts); each is priced per clip below.if (normalizedProvider === "veo") {- return veoCreditPricing();+ return veoCreditPricing(normalizedModel);}if (normalizedProvider === "elevenlabs") {return elevenLabsCreditPricing(normalizedModel);@@ -270,12 +274,20 @@ const geminiModelPricing: Record<GeminiModel, ProviderCreditPricing> = {[geminiModels.flashImage]: { generationCostMicros: usdWithMargin("0.039") },};-// Generative text/image-to-video (Veo). The model id is configuration (GEMINI_VIDEO_MODEL), so this-// is a provider-level flat price per clip, not a per-model rate. Veo bills per second of output; an-// ~8s clip with audio at ~$0.40/s ≈ $3.20, charged at submit time (assets/refresh is free). Adjust-// the rate (or move to durationSecondCostMicros) if the real Veo rate or default clip length differs.-function veoCreditPricing(): ProviderCreditPricing {- return { generationCostMicros: usdWithMargin("3.20") };+// Generative text/image-to-video (Veo). Model ids are hardcoded (gemini-models.ts), so each is priced+// per clip. Veo bills per second of output; these reflect a default ~8s clip with audio (quality+// ~$0.40/s ≈ $3.20, fast ~$0.15/s ≈ $1.20, lite ~$0.05/s ≈ $0.40), charged once at submit+// (assets/refresh is free). A shorter/longer clip still pays the flat rate; move to+// durationSecondCostMicros if that drifts too far. The Record is keyed by VeoModel, so adding a Veo id+// without a price fails the build.+const veoModelPricing: Record<VeoModel, ProviderCreditPricing> = {+ [veoModels.quality]: { generationCostMicros: usdWithMargin("3.20") },+ [veoModels.fast]: { generationCostMicros: usdWithMargin("1.20") },+ [veoModels.lite]: { generationCostMicros: usdWithMargin("0.40") },+};++function veoCreditPricing(model: string): ProviderCreditPricing | undefined {+ return veoModelPricing[model as VeoModel];}function geminiCreditPricing(model: string): ProviderCreditPricing | undefined {diff --git a/site/src/lib/inference/adapters/gemini-video.ts b/site/src/lib/inference/adapters/gemini-video.tsindex c2f30944..79e5fb16 100644--- a/site/src/lib/inference/adapters/gemini-video.ts+++ b/site/src/lib/inference/adapters/gemini-video.ts@@ -13,6 +13,7 @@ import {type AdapterEnvironment,} from "@/lib/inference/adapters/gemini-client";import { providerCreditPricing } from "@/lib/credits/provider-pricing";+import { veoModels, veoTierModels } from "@/lib/inference/gemini-models";import { ensureConfigured } from "@/lib/inference/http";import { isJsonObject, toJsonObject, toJsonValue } from "@/lib/inference/json";import {@@ -33,8 +34,7 @@ import {// registry auto-selects this provider for kind="video". Veo is a long-running operation, so unlike// the synchronous image adapter this submits a job and the Mac side polls refresh until it lands.// A DISTINCT provider id ("veo", not "gemini") keeps that refresh routing from colliding with the-// image adapter. Veo is named only here; adopting a newer model is a new id in gemini-models.ts (or-// the GEMINI_VIDEO_MODEL override), not an app change.+// image adapter. Adopting a newer Veo is a one-line change in gemini-models.ts, not an app change.const providerID = "veo";// Veo needs both `models` (submit) and `operations` (poll) on the client; the shared GeminiClient@@ -51,53 +51,34 @@ export function createGeminiVideoAssetProvider(): InferenceProvider {const clientConfig = geminiClientConfig(environment);const configured = clientConfig.configured;- // The video model id is configuration, never a hardcoded guess: it comes from GEMINI_VIDEO_MODEL- // (or an explicit per-call model). Vertex AI is assumed (see geminiClientConfig). With the env- // unset and no caller model, generateAsset fails cleanly rather than inventing a model id.- const videoModel = environment.GEMINI_VIDEO_MODEL?.trim() || undefined;+ // Model selection lives in code: the speed/quality tier the user picks maps to a hardcoded Veo id+ // (see gemini-models.ts), so video is on by default rather than gated behind an env var. Vertex AI+ // is assumed (see geminiClientConfig).async function listModels(modalities: InferenceModality[],): Promise<InferenceModel[]> {- if (!modalities.includes("video") || !videoModel) {+ if (!modalities.includes("video")) {return [];}- return [- {- id: videoModel,- name: videoModel,- provider: providerID,- inputModalities: ["text", "image"],- outputModalities: ["video"],- contextLength: null,- pricing: null,- metadata: { provider: providerID, api: "generateVideos" },- },- ];- }-- // The speed/quality tier the user picks selects a per-tier model from configuration —- // GEMINI_VIDEO_MODEL_<TIER> (e.g. GEMINI_VIDEO_MODEL_FAST) — never a hardcoded id. An unconfigured- // tier falls back to the default GEMINI_VIDEO_MODEL.- function modelForTier(tier?: string): string | undefined {- const key = tier?.trim().toUpperCase();- if (!key) {- return undefined;- }- return environment[`GEMINI_VIDEO_MODEL_${key}`]?.trim() || undefined;+ return Object.values(veoModels).map((id) => ({+ id,+ name: id,+ provider: providerID,+ inputModalities: ["text", "image"],+ outputModalities: ["video"],+ contextLength: null,+ pricing: null,+ metadata: { provider: providerID, api: "generateVideos" },+ }));}function resolveModel(requested?: string, tier?: string): string {- const model = requested?.trim() || modelForTier(tier) || videoModel;- // Never guess a video model id — without GEMINI_VIDEO_MODEL (or a caller model) there is nothing- // to run, so fail cleanly instead of fabricating one.- if (!model) {- throw new InferenceProviderError(- "No video model is configured. Set GEMINI_VIDEO_MODEL.",- { statusCode: 503, code: "missing_provider_credentials" },- );- }- // Fail before spending: the resolved model must have a configured price.+ const tierModel =+ veoTierModels[tier?.trim().toLowerCase() as keyof typeof veoTierModels];+ const model = requested?.trim() || tierModel || veoModels.fast;+ // Fail before spending: the resolved model must have a configured price. A hardcoded Veo id+ // always resolves; this only bites if a caller passes an unpriced model override.if (!providerCreditPricing(providerID, model)) {throw new InferenceProviderError("No credit price is configured for the selected video model.",diff --git a/site/src/lib/inference/gemini-models.ts b/site/src/lib/inference/gemini-models.tsindex 7a129848..91a1ea1c 100644--- a/site/src/lib/inference/gemini-models.ts+++ b/site/src/lib/inference/gemini-models.ts@@ -17,6 +17,30 @@ export const geminiModels = {export type GeminiModel = (typeof geminiModels)[keyof typeof geminiModels];+// Generative text/image-to-video (Veo 3.1). Model selection lives in code, so the+// ids are hardcoded here rather than gated behind an env var — that keeps the+// feature on by default instead of silently dormant. Bump here when adopting a+// newer Veo.+export const veoModels = {+ // Best quality, slower, priciest per second.+ quality: "veo-3.1-generate-preview",+ // Balanced speed/cost; the default when no tier is given.+ fast: "veo-3.1-fast-generate-preview",+ // Cheapest and quickest, lower fidelity.+ lite: "veo-3.1-lite-generate-preview",+} as const;++export type VeoModel = (typeof veoModels)[keyof typeof veoModels];++// Maps the user-facing speed/quality tier (see the `video` SKILL.md picker) to a+// Veo model. An unknown/absent tier falls back to `fast` at the call site.+export const veoTierModels = {+ lite: veoModels.lite,+ fast: veoModels.fast,+ standard: veoModels.fast,+ high: veoModels.quality,+} as const;+// Semantic roles map a job to the model we run for it. Prefer referencing a// role over a bare constant so intent stays explicit at the call site.export const geminiModelRoles = {