The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Clean the voice first: every step it adds is checked and priced on the install's GPUs, and an unknown step price stays unknown
Claude0a78966b5a2f
diff --git a/docs/billing-hook.md b/docs/billing-hook.mdindex ef682499..9e25b609 100644--- a/docs/billing-hook.md+++ b/docs/billing-hook.md@@ -47,6 +47,7 @@ type RunFacts = {kind: "image" | "video" | "audio" | "text" | "model3d"; engine: "open" | "cloud"; provider: string;jobs: number; outputsPerJob: number; megapixels: number | null; seconds: number | null; fps: number | null;loras: number; inputs: { image: number; video: number; audio: number }; lane: string | null; providerUsd: number | null;+ steps?: { model: string; op: string }[]; // the run's other steps beside `model` (a transcript or lip sync with its voice cleaned first)};type QueueFacts = { lane: string; ahead: number; etaS: number | null; workersOnline: number; nextOpenAt: number | null; mine: { waiting: number; running: number } };type Action = { label: string; url: string }; // Fuobe opens url as given (https, or a path on this site)diff --git a/src/server/billing.ts b/src/server/billing.tsindex 7eb6d2b7..74f7b756 100644--- a/src/server/billing.ts+++ b/src/server/billing.ts@@ -46,6 +46,8 @@ export interface RunFacts {inputs: { image: number; video: number; audio: number };lane: string | null;providerUsd: number | null;+ /** The other steps the run makes beside `model` (Clean the voice first's clean voice and music put back), when it makes any. */+ steps?: { model: string; op: string }[];}export interface QueueFacts {diff --git a/src/server/generations.ts b/src/server/generations.tsindex b59e004d..4f333e91 100644--- a/src/server/generations.ts+++ b/src/server/generations.ts@@ -849,9 +849,11 @@ export function previewGeneration(asked: GenerationRequest) {// "Clean the voice first" (voice-first.ts): its other steps are checked as the run checks them, and priced in.const voiced = moved.request.voiceFirst ? voiceFirstExtra(moved.request, plan.model) : null;if (voiced) {- post = cost === null || voiced.costUsd === null ? post : post + voiced.costUsd;+ if (voiced.costUsd !== null) post += voiced.costUsd;notes.push(...voiced.notes);}+ // A clean-voice step whose price isn't known leaves the run's price unknown too, never the main step's alone.+ const priceUnknown = cost === null || voiced?.costUsd === null;return {model: plan.model,op: plan.op,@@ -859,7 +861,9 @@ export function previewGeneration(asked: GenerationRequest) {outputs: plan.jobs * plan.perJobOutputs,demo,providerId,- costUsd: cost === null ? null : post ? Math.round((cost * plan.jobs + post) * 1000) / 1000 : cost * plan.jobs,+ costUsd: priceUnknown || cost === null ? null : post ? Math.round((cost * plan.jobs + post) * 1000) / 1000 : cost * plan.jobs,+ // The other steps the run makes beside its own model (Clean the voice first's), so a policy and a price see them all.+ ...(voiced?.steps.length && { steps: voiced.steps }),// The engine it runs on (a Fuobe Original picks one per request).engine: plan.model.engine,// What the route runs (the evaluation harness records it): the provider endpoint, the final prompt and the LoRAs it loads.@@ -874,10 +878,11 @@ export function previewGeneration(asked: GenerationRequest) {}/** The steps "Clean the voice first" adds to a run (all but the run itself), checked and priced as the run makes them. */-function voiceFirstExtra(req: GenerationRequest, model: ModelDef): { costUsd: number | null; notes: string[] } | null {+function voiceFirstExtra(req: GenerationRequest, model: ModelDef): { costUsd: number | null; notes: string[]; steps: { model: string; op: string }[] } | null {const vf = voiceFirstPlanFor(req, model);if (!vf) return null;let costUsd: number | null = 0;+ const steps: { model: string; op: string }[] = [];for (const s of vf.steps) {if (s.key === "main") continue;let p: ReturnType<typeof previewChained>;@@ -887,10 +892,11 @@ function voiceFirstExtra(req: GenerationRequest, model: ModelDef): { costUsd: nuthrow new Error(`${VOICE_FIRST_LABEL} can't run: ${(e as Error).message}. Turn it off to run without it`);}costUsd = costUsd === null || p.costUsd === null ? null : costUsd + p.costUsd;+ steps.push({ model: p.model.id, op: p.op });}const op = inferOperation(model, req);const notes = op === "lipsync" && req.inputs?.video ? [vf.bed ? BED_NOTES.open : model.engine === "cloud" ? BED_NOTES.cloud : null].filter((x): x is string => !!x) : [];- return { costUsd: costUsd === null ? null : Math.round(costUsd * 10000) / 10000, notes };+ return { costUsd: costUsd === null ? null : Math.round(costUsd * 10000) / 10000, notes, steps };}/** Preview a step that will wait for `deps` earlier steps: validated with placeholders in its chain slots, as createGenerations does. */diff --git a/src/server/hosted-run.ts b/src/server/hosted-run.tsindex 4b52b95b..0d918324 100644--- a/src/server/hosted-run.ts+++ b/src/server/hosted-run.ts@@ -20,7 +20,7 @@ import {type RefuseCode,} from "./billing";import { outputKind, previewGeneration } from "./generations";-import { HOSTED_WORDS, inputCounts, poolAllows, poolReady, queueFacts, runFacts, runOnPool } from "./hosted";+import { HOSTED_WORDS, inputCounts, poolAllowsRun, poolReady, queueFacts, runFacts, runOnPool } from "./hosted";import { hostedRunsOn } from "./hosted-switch";import { checkRun, moderationConfigured } from "./moderation";import type { RunStamp } from "./run-stamp";@@ -98,7 +98,7 @@ export async function decidePlace(account: Account, req: GenerationRequest, wish// From here on the run would be this install's: what it can't take there goes to the account's own GPU when it has one.const notHere = (error: string): PlaceDecision => (hasGpu && wish !== "pool" ? { kind: "own" } : { kind: "refuse", refusal: { status: 403, body: { error, code: "not-offered" }, headers: { [BILLING_HEADER]: "not-offered" } } });if (outputKind(planned.op, planned.model) === "model3d") return hasGpu && wish !== "pool" ? { kind: "own" } : { kind: "refuse", refusal: { status: 403, body: { error: OWN_GPU_TOOL_MESSAGE, code: "own-gpu-tool" }, headers: {} } };- if (!poolAllows(p, planned.model.id, req.presetId)) return notHere(HOSTED_WORDS.notOffered);+ if (!poolAllowsRun(p, planned, req.presetId)) return notHere(HOSTED_WORDS.notOffered);if (req.loras?.length) return notHere(HOSTED_WORDS.loras);const inputs = inputCounts(req);if ((inputs.image && !p.uploads.image) || (inputs.video && !p.uploads.video) || (inputs.audio && !p.uploads.audio)) return notHere(HOSTED_WORDS.inputs);@@ -199,7 +199,7 @@ export async function poolQuote(account: Account | null, asked: GenerationReques}if (planned.route.provider !== "comfyui") return null;if (account && wish !== "pool" && accountGpu(account.id) && (await ownGpuOnline(account.id))) return null;- if (p && (!p.hosted || !poolAllows(p, planned.model.id, req.presetId))) return null;+ if (p && (!p.hosted || !poolAllowsRun(p, planned, req.presetId))) return null;const kind = outputKind(planned.op, planned.model);const q = await billingQuote(account ? accountFacts(account) : null, runFacts(req, planned, kind), queueFacts(account?.id ?? null));return { planned, quote: q };diff --git a/src/server/hosted.ts b/src/server/hosted.tsindex 043fe2fd..f5b4c6fb 100644--- a/src/server/hosted.ts+++ b/src/server/hosted.ts@@ -63,6 +63,14 @@ export function poolAllows(p: Pick<Policy, "pool">, modelId: string, presetId?:return true;}+/**+ * May this whole run go on this install's GPUs: its model and every other step it makes (Clean the voice first's+ * clean voice, a lip re-sync's music put back), so a policy that keeps a model off the pool keeps it off as a step too.+ */+export function poolAllowsRun(p: Pick<Policy, "pool">, planned: { model: { id: string }; steps?: { model: string }[] }, presetId?: string | null): boolean {+ return [planned.model.id, ...(planned.steps ?? []).map((s) => s.model)].every((id) => poolAllows(p, id, presetId));+}+/** The file kinds a request uses (for the policy's uploads rule and the billing facts). */export function inputCounts(req: GenerationRequest): { image: number; video: number; audio: number } {const i = req.inputs ?? {};@@ -138,7 +146,7 @@ export function placeInLine(generationId: string): { place: number; etaSeconds:/** The facts the billing service prices a run by (from a planned request: previewGeneration's answer). */export function runFacts(req: GenerationRequest,- p: { model: { id: string; kind: string; engine: "open" | "cloud" }; op: string; jobs: number; outputs: number; providerId: string; costUsd: number | null; loras: { applied: unknown[] } },+ p: { model: { id: string; kind: string; engine: "open" | "cloud" }; op: string; jobs: number; outputs: number; providerId: string; costUsd: number | null; loras: { applied: unknown[] }; steps?: { model: string; op: string }[] },kind: RunFacts["kind"],): RunFacts {const model = getModel(p.model.id);@@ -161,5 +169,7 @@ export function runFacts(inputs: inputCounts(req),lane: POOL_LANE,providerUsd: p.costUsd,+ // The run's other steps (Clean the voice first's), each a model and op the service prices beside the main one.+ ...(p.steps?.length && { steps: p.steps.map((s) => ({ model: s.model, op: s.op })) }),};}diff --git a/tests/hosted-runs.test.ts b/tests/hosted-runs.test.tsindex 491e31e7..ebffc316 100644--- a/tests/hosted-runs.test.ts+++ b/tests/hosted-runs.test.ts@@ -145,6 +145,37 @@ describe("hosted runs on", () => {expect(quoted?.quote).toBeTruthy();});+ it("Clean the voice first: its clean-voice step plans and prices here, and a policy that keeps it off keeps the run off", async () => {+ process.env.FUOBE_BILLING_URL = fake.url;+ process.env.FUOBE_BILLING_TOKEN = "test-billing-token";+ fake.policy = { ...fake.policy, uploads: { image: true, video: false, audio: true } };+ const up = await upload(wav(), "audio/wav", "voice.wav");+ expect(up.status).toBe(201);+ const { url } = (await up.json()) as { url: string };+ const { decidePlace, poolQuote } = await import("@/server/hosted-run");+ const req = { feature: "transcribe", modelId: "oss-qwen3-asr", op: "transcribe" as const, inputs: { audio: url }, params: { sourceLanguage: "en" }, voiceFirst: true };+ const place = await decidePlace(auth.accountById(a)!, req, undefined);+ expect(place.kind).toBe("pool");+ if (place.kind !== "pool") return;+ expect(place.planned.steps).toEqual([{ model: "oss-dbs-separate", op: "separate-audio" }]);+ const before = fake.calls_of("/v1/quote").length;+ const quoted = await poolQuote(auth.accountById(a)!, req, undefined);+ expect(quoted?.planned.model.id).toBe("oss-qwen3-asr");+ const sent = fake.calls_of("/v1/quote").slice(before).at(-1)?.body as { run: { model: string; steps?: unknown } };+ expect(sent.run.model).toBe("oss-qwen3-asr");+ expect(sent.run.steps).toEqual([{ model: "oss-dbs-separate", op: "separate-audio" }]);+ // Without the switch there are no other steps to send.+ const plain = await poolQuote(auth.accountById(a)!, { ...req, voiceFirst: false }, undefined);+ expect(plain?.planned.steps).toBeUndefined();+ // A policy that keeps the clean-voice model off this install's GPUs keeps the whole run off, priced or run.+ fake.policy = { ...fake.policy, pool: { deny: ["oss-dbs-separate"] } };+ billing.resetBillingCache();+ expect(await poolQuote(auth.accountById(a)!, req, undefined)).toBeNull();+ const refused = await decidePlace(auth.accountById(a)!, req, undefined);+ expect(refused.kind).toBe("refuse");+ expect((await decidePlace(auth.accountById(a)!, { ...req, voiceFirst: false }, undefined)).kind).toBe("pool");+ });+it("the pool's allow and deny lists, for models and apps", () => {expect(poolAllows({ pool: {} }, "m")).toBe(true);expect(poolAllows({ pool: { allow: ["m"] } }, "m")).toBe(true);@@ -164,3 +195,23 @@ describe("hosted runs on", () => {}});});++/** A 1 s mono 16 kHz WAV. */+function wav(): Buffer {+ const frames = 16000;+ const b = Buffer.alloc(44 + frames * 2);+ b.write("RIFF", 0);+ b.writeUInt32LE(36 + frames * 2, 4);+ b.write("WAVE", 8);+ b.write("fmt ", 12);+ b.writeUInt32LE(16, 16);+ b.writeUInt16LE(1, 20);+ b.writeUInt16LE(1, 22);+ b.writeUInt32LE(16000, 24);+ b.writeUInt32LE(32000, 28);+ b.writeUInt16LE(2, 32);+ b.writeUInt16LE(16, 34);+ b.write("data", 36);+ b.writeUInt32LE(frames * 2, 40);+ return b;+}