diff --git a/packages/cli/src/commands/media-use/generate.test.ts b/packages/cli/src/commands/media-use/generate.test.ts new file mode 100644 index 0000000000..117291eff7 --- /dev/null +++ b/packages/cli/src/commands/media-use/generate.test.ts @@ -0,0 +1,40 @@ +import { mkdtempSync } from "node:fs"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +vi.mock("../../cloud/auth.js", () => ({ + resolveCloudAuthHeaders: async () => ({ "x-api-key": "k" }), + refreshIfNeeded: async (credential: T) => credential, + resolveCloudBaseUrl: () => "https://api.test", +})); + +const { default: generate } = await import("./generate.js"); + +beforeEach(() => { + vi.stubEnv("HYPERFRAMES_CONFIG_DIR", mkdtempSync(join(tmpdir(), "hf-generate-test-"))); +}); +afterEach(() => { + vi.unstubAllGlobals(); + vi.unstubAllEnvs(); + vi.restoreAllMocks(); +}); + +describe("media-use generate", () => { + it.each([ + ["nano-banana-2", "nano-banana-2.1"], + ["gpt-image-2.5", "gpt-image-2.6"], + ])("names %s's replacement even with --max-credits, and sends nothing", async (model, next) => { + const fetched = vi.fn(); + vi.stubGlobal("fetch", fetched); + const out: string[] = []; + vi.spyOn(console, "log").mockImplementation((line: string) => void out.push(line)); + const args = { type: "image", prompt: "a cup", out: "cup.png", model, "max-credits": "50" }; + await expect(generate.run!({ args, rawArgs: [] } as never)).rejects.toThrow("Command failed"); + const printed = JSON.parse(out.join("\n")); + expect(printed.ok).toBe(false); + expect(printed.error).toBe(`${model} is no longer offered here`); + expect(printed.fix).toBe(`--model ${next}`); + expect(fetched).not.toHaveBeenCalled(); + }); +}); diff --git a/packages/cli/src/commands/media-use/generate.ts b/packages/cli/src/commands/media-use/generate.ts index 6c738589ea..f78c15ba73 100644 --- a/packages/cli/src/commands/media-use/generate.ts +++ b/packages/cli/src/commands/media-use/generate.ts @@ -131,7 +131,7 @@ export default defineCommand({ model: { type: "string", description: - "image: nano-banana-2.1 (default), nano-banana-2, gpt-image-2.5, gpt-image-2.6, gpt-image-2.6-flare, minimax-h3-image (2K) or minimax-h3-image-4k", + "image: nano-banana-2.1 (default), gpt-image-2.6, gpt-image-2.6-flare, minimax-h3-image (2K) or minimax-h3-image-4k", }, bpm: { type: "string", description: "music: tempo, 60–180" }, vocals: { @@ -182,10 +182,10 @@ export default defineCommand({ }; const voice = await voiceFor(request); if (voice) request.voice = voice.voice_id; + checkRequest(request); const price = priceOf(request); const credits = creditsOf(price); if (args.plan) { - checkRequest(request); return { plan: true, type, diff --git a/packages/cli/src/heygen/generate.test.ts b/packages/cli/src/heygen/generate.test.ts index 59eed13cc0..2bf09e5396 100644 --- a/packages/cli/src/heygen/generate.test.ts +++ b/packages/cli/src/heygen/generate.test.ts @@ -161,7 +161,7 @@ describe("generate", () => { type: "image", out: join(project, "assets/charged.png"), prompt: "a charged picture", - model: "gpt-image-2.5", + model: "gpt-image-2.6", }); expect(r.charged_credits).toBe(41); expect(readFileSync(join(project, ".media/manifest.jsonl"), "utf8")).toContain( @@ -182,7 +182,7 @@ describe("generate", () => { type: "image", out: join(dir, "assets/limited.png"), prompt: "a limited picture", - model: "gpt-image-2.5", + model: "gpt-image-2.6", aspect: "16:9", } as const; return generate(request, undefined, creditsOf(priceOf(request)) ?? undefined); @@ -250,7 +250,7 @@ describe("generate", () => { type: "image", out: join(project, "assets/api-charged.png"), prompt: "an api-charged picture", - model: "gpt-image-2.5", + model: "gpt-image-2.6", }); expect(r).not.toHaveProperty("charged_credits"); }); @@ -893,7 +893,7 @@ describe("generate", () => { priceOf({ type: "image", out: "a.png", - model: "gpt-image-2.5", + model: "gpt-image-2.6", aspect: "1:1", references: ["a", "b"], }).usd, @@ -905,7 +905,7 @@ describe("generate", () => { it("prices every reference picture of a GPT Image edit, on each GPT Image model", () => { const edit = (model: string, references: string[]) => creditsOf(priceOf({ type: "image", out: "a.png", model, aspect: "16:9", references })); - for (const model of ["gpt-image-2.5", "gpt-image-2.6", "gpt-image-2.6-flare"]) { + for (const model of ["gpt-image-2.6", "gpt-image-2.6-flare"]) { expect(edit(model, [])).toBe(66); expect(edit(model, ["a"])).toBe(87); expect( @@ -925,9 +925,9 @@ describe("generate", () => { it("says a GPT Image price is an estimate charged on the vendor's bill, and a Nano Banana one is not", () => { expect( - priceOf({ type: "image", out: "a.png", model: "gpt-image-2.5", aspect: "16:9" }).basis, + priceOf({ type: "image", out: "a.png", model: "gpt-image-2.6", aspect: "16:9" }).basis, ).toBe( - "gpt-image-2.5 at 16:9, about 66 credits (charged on the vendor's bill), with about $0.0125 a reference; vendor price x1.5 on an API key, x1.6545 in HyperFrames credits", + "gpt-image-2.6 at 16:9, about 66 credits (charged on the vendor's bill), with about $0.0125 a reference; vendor price x1.5 on an API key, x1.6545 in HyperFrames credits", ); expect(priceOf({ type: "image", out: "a.png" }).basis).toBe( "nano-banana-2.1, $0.0336 an image and $0.00168 a reference; vendor price x1.5 on an API key, x1.6545 in HyperFrames credits", @@ -982,8 +982,7 @@ describe("generate", () => { const rows: [string, string, number][] = [ ["gpt-image-2.6", "1:1", 87.15906], ["gpt-image-2.6-flare", "16:9", 65.5182], - ["gpt-image-2.5", "4:3", 59.76054], - ["nano-banana-2", "21:9", 110.8515], + ["gpt-image-2.6", "4:3", 59.76054], ["nano-banana-2.1", "3:2", 55.5912], ]; for (const [model, aspect, row] of rows) @@ -994,9 +993,6 @@ describe("generate", () => { expect( image("nano-banana-2.1", "1:1", 1).credits! - image("nano-banana-2.1", "1:1").credits!, ).toBeCloseTo(2.77956, 6); - expect(image("nano-banana-2", "1:1", 3).credits).toBe(image("nano-banana-2", "1:1").credits); - expect(image("nano-banana-2", "1:1").list).toBeCloseTo(0.1005, 9); - expect(image("nano-banana-2", "1:1").usd).toBe(0.12); expect(image("gpt-image-2.6", "16:9").list).toBeCloseTo(0.0594, 9); expect(image("gpt-image-2.6", "16:9").usd).toBe(0.07); expect(image("nano-banana-2.1", "16:9", 2).list).toBeCloseTo((0.0336 + 2 * 0.00168) * 1.5, 9); @@ -1027,7 +1023,9 @@ describe("generate", () => { } expect(check("gpt-image-2.6", "21:9")).toThrow("gpt-image-2.6 does not make 21:9"); expect(check("nano-banana-2.1", "21:9")).not.toThrow(); - expect(check("nano-banana-2", undefined, 15)).toThrow("at most 14 --reference pictures"); + expect(check("nano-banana-2.1", undefined, 15)).toThrow("at most 14 --reference pictures"); + expect(check("nano-banana-2")).toThrow("nano-banana-2 is no longer offered here"); + expect(check("gpt-image-2.5", "16:9")).toThrow("gpt-image-2.5 is no longer offered here"); expect(check("some-new-model", "7:5")).not.toThrow(); }); @@ -1194,16 +1192,16 @@ describe("generate", () => { it("keeps 10% headroom under the limit for an image charged on the vendor's bill", () => { const limited = (request: GenerateRequest, limit: number) => () => checkLimit(creditsOf(priceOf(request)), limit, isVendorPriced(request)); - const gpt = { type: "image", out: "a.png", model: "gpt-image-2.5", aspect: "16:9" } as const; + const gpt = { type: "image", out: "a.png", model: "gpt-image-2.6", aspect: "16:9" } as const; expect(creditsOf(priceOf(gpt))).toBe(66); expect(limited(gpt, 66)).toThrow( "about 66 credits, 73 with 10% headroom because it is charged on the vendor's bill, over --max-credits 66", ); expect(limited(gpt, 72)).toThrow("73 with 10% headroom"); expect(limited(gpt, 73)).not.toThrow(); - const nano = { type: "image", out: "a.png", model: "nano-banana-2" } as const; + const nano = { type: "image", out: "a.png", model: "nano-banana-2.1" } as const; expect(isVendorPriced(nano)).toBe(false); - expect(limited(nano, 111)).not.toThrow(); + expect(limited(nano, 56)).not.toThrow(); }); }); diff --git a/packages/cli/src/heygen/generate.ts b/packages/cli/src/heygen/generate.ts index b04f297403..e290e730a2 100644 --- a/packages/cli/src/heygen/generate.ts +++ b/packages/cli/src/heygen/generate.ts @@ -169,7 +169,6 @@ const DEFAULTS = { music: "lyria-3-pro", } as const; export const VENDOR_PRICED_IMAGES = new Set([ - "gpt-image-2.5", "gpt-image-2.6", "gpt-image-2.6-flare", "minimax-h3-image", @@ -180,14 +179,16 @@ const GEMINI_ASPECTS = [...GPT_ASPECTS, "3:2", "2:3", "21:9"]; const MINIMAX_ASPECTS = [...GPT_ASPECTS, "21:9"]; /** What /v3/images accepts from each model: its aspect ratios and how many reference pictures. */ const IMAGE_MODELS: Record = { - "nano-banana-2": { aspects: GEMINI_ASPECTS, references: 14 }, "nano-banana-2.1": { aspects: GEMINI_ASPECTS, references: 14 }, - "gpt-image-2.5": { aspects: GPT_ASPECTS, references: 16 }, "gpt-image-2.6": { aspects: GPT_ASPECTS, references: 16 }, "gpt-image-2.6-flare": { aspects: GPT_ASPECTS, references: 16 }, "minimax-h3-image": { aspects: MINIMAX_ASPECTS, references: 16 }, "minimax-h3-image-4k": { aspects: MINIMAX_ASPECTS, references: 16 }, }; +const RETIRED_IMAGE_MODELS: Record = { + "nano-banana-2": "nano-banana-2.1", + "gpt-image-2.5": "gpt-image-2.6", +}; export const isVendorPriced = (r: GenerateRequest): boolean => r.type === "image" && VENDOR_PRICED_IMAGES.has(r.model ?? ""); const VIDEO_RESOLUTION = "768p"; @@ -203,6 +204,8 @@ const need = (value: T | undefined, flag: string, example: string): T => { function imageModel(r: GenerateRequest): string { const model = r.model ?? DEFAULTS.image; + const replacement = RETIRED_IMAGE_MODELS[model]; + if (replacement) throw new Fix(`${model} is no longer offered here`, `--model ${replacement}`); const spec = IMAGE_MODELS[model]; if (!spec) return model; if (r.aspect && !spec.aspects.includes(r.aspect)) diff --git a/packages/cli/src/heygen/pricing.ts b/packages/cli/src/heygen/pricing.ts index 9af59fab70..f8ed9576fd 100644 --- a/packages/cli/src/heygen/pricing.ts +++ b/packages/cli/src/heygen/pricing.ts @@ -32,7 +32,6 @@ const GPT_IMAGE: Record = { "3:4": 0.03612, }; const GPT_REFERENCE = 0.0125; -const NANO_IMAGE = 0.067; const NANO_2_1_IMAGE = 0.0336; const NANO_2_1_REFERENCE = 0.00168; const MINIMAX_IMAGE: Record = { @@ -77,7 +76,6 @@ export function priceOf(r: GenerateRequest): Price { case "image": { const refs = r.references?.length ?? 0; const model = r.model ?? "nano-banana-2.1"; - if (model === "nano-banana-2") return image(NANO_IMAGE, "nano-banana-2, $0.067 an image"); if (model === "nano-banana-2.1") return image( NANO_2_1_IMAGE + refs * NANO_2_1_REFERENCE, diff --git a/skills-manifest.json b/skills-manifest.json index 1ef951e3dc..a961e0b11f 100644 --- a/skills-manifest.json +++ b/skills-manifest.json @@ -18,7 +18,7 @@ "files": 13 }, "media-use": { - "hash": "23ee5ebbc42b963a", + "hash": "b036fbafc769d248", "files": 131 }, "remotion-to-hyperframes": { diff --git a/skills/media-use/references/heygen.md b/skills/media-use/references/heygen.md index d2d028003f..fbea3bcc25 100644 --- a/skills/media-use/references/heygen.md +++ b/skills/media-use/references/heygen.md @@ -46,15 +46,15 @@ npx hyperframes media-use generate --type music --prompt "warm lo-fi, soft keys" The file lands at `--out` and the media ledger records it as generated, with the route, model, job, prompt and the files it was made from. Pictures and shots carry no text or logos: ask for clean plates and draw words in HyperFrames. -| Type | Model | Price | -| ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| image | nano-banana-2.1 (default), or nano-banana-2, gpt-image-2.5, gpt-image-2.6, gpt-image-2.6-flare, minimax-h3-image (2K) or minimax-h3-image-4k with `--model` | 1.5x the vendor price on an API key: nano-banana-2.1 $0.05 plus $0.0025 a reference; nano-banana-2 $0.10 an image; gpt-image about $0.054–0.079 by aspect plus $0.019 a reference; minimax-h3-image $0.0375 (4K $0.105) plus $0.0225 a reference. A plan charges the vendor price x1.6545 in credits; gpt-image and minimax-h3-image are charged on the vendor's bill | -| video | heygen-video-1, 768p | $0.02 a second from a prompt or first frame; $0.05 a second with a reference picture, voice or guide clip, and the guide's seconds count too (1080p costs about twice) | -| lipsync | HeyGen lipsync, speed | 7 credits a second of the video on a plan | -| avatar | talking photo | $4.83 a minute of speech | -| cutout | HeyGen background removal | not priced ahead | -| music | lyria-3-pro | $0.08 a track | -| voice | the voice's engine | charged per character, not priced ahead | +| Type | Model | Price | +| ------- | ----------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| image | nano-banana-2.1 (default), or gpt-image-2.6, gpt-image-2.6-flare, minimax-h3-image (2K) or minimax-h3-image-4k with `--model` | 1.5x the vendor price on an API key: nano-banana-2.1 $0.05 plus $0.0025 a reference; gpt-image about $0.054–0.079 by aspect plus $0.019 a reference; minimax-h3-image $0.0375 (4K $0.105) plus $0.0225 a reference. A plan charges the vendor price x1.6545 in credits; gpt-image and minimax-h3-image are charged on the vendor's bill | +| video | heygen-video-1, 768p | $0.02 a second from a prompt or first frame; $0.05 a second with a reference picture, voice or guide clip, and the guide's seconds count too (1080p costs about twice) | +| lipsync | HeyGen lipsync, speed | 7 credits a second of the video on a plan | +| avatar | talking photo | $4.83 a minute of speech | +| cutout | HeyGen background removal | not priced ahead | +| music | lyria-3-pro | $0.08 a track | +| voice | the voice's engine | charged per character, not priced ahead | Each image model takes only its own aspect ratios and reference count, and generate refuses the rest: gpt-image 1:1, 16:9, 9:16, 4:3 or 3:4 with up to 16 references; nano-banana those and 3:2, 2:3 or 21:9 with up to 14; minimax-h3-image gpt-image's and 21:9 with up to 16.