Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.
TypeScript ai-artartificial-intelligencegenerative-artimage-generationimg2imginpaintinglatent-diffusionlinuxmacosoutpaintingstable-diffusiontxt2imgwindows
feat(api): report media a request's higher-precedence media override
Lincoln Stein6d718402e557
diff --git a/docs/src/content/docs/development/Guides/video-recall-api.mdx b/docs/src/content/docs/development/Guides/video-recall-api.mdxindex a821f6820f..c0695358c5 100644--- a/docs/src/content/docs/development/Guides/video-recall-api.mdx+++ b/docs/src/content/docs/development/Guides/video-recall-api.mdx@@ -64,6 +64,22 @@ whose medium was dropped. A LoRA or reference list whose every entry was droppedis left out entirely rather than sent empty, so it cannot clear the panel's list.Unknown fields, and values outside the bounds below, are rejected with `422`.+Media fields in one request are read in the Video panel's precedence, highest first:++1. `ltx2_conditioning_video` — a whole-generation conditioning clip excludes every+ other medium.+2. `minimax_h3_references` (non-empty) — references replace the frame slots; a+ `source_video` rides alongside them.+3. `source_video` — an initial video replaces `first_frame_image`, which extend+ mode takes from the clip itself.+4. `first_frame_image`, `last_frame_image`.++A medium that a higher-precedence one in the same request excludes is not sent, and+the response's `overridden` maps it to the field that won — for example+`{"first_frame_image": "source_video"}`. Only media that could be found take+precedence: a `source_video` that is missing from the gallery overrides nothing.+Send only the fields you mean to set; the Swagger page offers minimal examples.+### Send Video and Use as Ref VideoThe name-only routes take `video_name` as a query parameter; the video must be in@@ -202,13 +218,16 @@ Recall / Remix:"status": "success","queue_id": "default","parameters": { "positive_prompt": "…", "model": { "key": "…", "hash": "…", "name": "…", "base": "wan", "type": "main" } },- "skipped": ["loras[1]"]+ "skipped": ["loras[1]"],+ "overridden": {}}````status` is `no_parameters_provided` for an empty body and `nothing_resolved`when every field was dropped; no event is emitted in either case. `parameters` is-exactly what the frontend receives.+exactly what the frontend receives. `skipped` lists fields whose model or medium+could not be used; `overridden` maps media fields that lost to a higher-precedence+medium in the same request to the field that won.Send Video / Use as Ref Video:diff --git a/invokeai/app/api/routers/video_recall.py b/invokeai/app/api/routers/video_recall.pyindex 37d36770f7..33bf4662a7 100644--- a/invokeai/app/api/routers/video_recall.py+++ b/invokeai/app/api/routers/video_recall.py@@ -8,6 +8,7 @@ how they land in the panel.from typing import Annotated, Any, Literal, Optional, Unionfrom fastapi import Body, HTTPException, Path, Query, Request+from fastapi.openapi.models import Examplefrom fastapi.routing import APIRouterfrom pydantic import BaseModel, ConfigDict, Field, StringConstraints, model_validator@@ -213,6 +214,13 @@ class VideoRecallParametersResponse(BaseModel):queue_id: strparameters: dict[str, Any] = Field(description="The resolved parameters sent to the frontend")skipped: list[str] = Field(description="Requested fields dropped because their model or media could not be used")+ overridden: dict[str, str] = Field(+ default_factory=dict,+ description=(+ "Requested media fields dropped because another medium in the same request takes precedence over them, "+ "mapped to that field (e.g. first_frame_image -> source_video)"+ ),+ )class VideoRecallMediaResponse(BaseModel):@@ -334,10 +342,7 @@ def resolve_video_recall_parameters(resolved[key] = value# Trim bounds and the conditioning role qualify their medium; without it they mean nothing.- for medium, qualifiers in (- ("source_video", ("source_video_start_frame", "source_video_end_frame")),- ("ltx2_conditioning_video", ("ltx2_conditioning_role",)),- ):+ for medium, qualifiers in MEDIA_QUALIFIERS.items():if medium not in resolved:for qualifier in qualifiers:if resolved.pop(qualifier, None) is not None:@@ -346,6 +351,86 @@ def resolve_video_recall_parameters(return resolved, skipped+# Media keys and the keys that only qualify them.+MEDIA_QUALIFIERS: dict[str, tuple[str, ...]] = {+ "source_video": ("source_video_start_frame", "source_video_end_frame"),+ "ltx2_conditioning_video": ("ltx2_conditioning_role",),+}+++def apply_media_precedence(resolved: dict[str, Any]) -> dict[str, str]:+ """Drop media a higher-precedence medium in the same request excludes; returns {dropped field: winner}.++ Mirrors the Video panel's reading of a record: a whole-generation conditioning clip excludes every other slot;+ Ref2VA references replace the frame slots (an initial video rides alongside them); an initial video replaces+ the first frame, which extend mode extracts from the clip itself.+ """+ rules: list[tuple[str, bool, tuple[str, ...]]] = [+ (+ "ltx2_conditioning_video",+ "ltx2_conditioning_video" in resolved,+ ("minimax_h3_references", "source_video", "first_frame_image", "last_frame_image"),+ ),+ (+ "minimax_h3_references",+ bool(resolved.get("minimax_h3_references")),+ ("first_frame_image", "last_frame_image"),+ ),+ ("source_video", "source_video" in resolved, ("first_frame_image",)),+ ]+ overridden: dict[str, str] = {}+ for winner, present, losers in rules:+ if not present or winner not in resolved:+ continue+ for loser in losers:+ # An explicitly empty reference list asks for no references; the winning clip clears them too, so it+ # loses nothing and stays.+ if resolved.get(loser) == []:+ continue+ if resolved.pop(loser, None) is not None:+ overridden[loser] = winner+ for qualifier in MEDIA_QUALIFIERS.get(loser, ()):+ if resolved.pop(qualifier, None) is not None:+ overridden[qualifier] = winner+ return overridden+++# Swagger pre-fills the first example. Without these it offers every field with placeholder values, and the+# placeholder media then take precedence over the one field a caller meant to send.+VIDEO_RECALL_EXAMPLES: dict[str, Example] = {+ "prompt_and_model": Example(+ summary="Prompt and model",+ value={"positive_prompt": "a heron takes flight over a misty lake", "model": "Wan 2.2 I2V A14B (Diffusers)"},+ ),+ "first_frame": Example(+ summary="Start from a gallery image",+ value={+ "model": "Wan 2.2 I2V A14B (Diffusers)",+ "first_frame_image": {"image_name": "<gallery image name>.png"},+ },+ ),+ "extend_video": Example(+ summary="Extend a gallery video",+ value={+ "positive_prompt": "the camera keeps panning left",+ "source_video": {"video_name": "<gallery video name>.mp4"},+ "source_video_start_frame": 0,+ "source_video_end_frame": 80,+ },+ ),+ "ref2va_references": Example(+ summary="MiniMax H3 Ref2VA references",+ value={+ "model": "MiniMax H3 Ref2VA Transformer (int8, pruned)",+ "minimax_h3_references": [+ {"kind": "image", "image_name": "<gallery image name>.png"},+ {"kind": "video", "video_name": "<gallery video name>.mp4", "conditioning": "video_audio"},+ ],+ },+ ),+}++@video_recall_router.post("/{queue_id}",operation_id="recall_video_parameters",@@ -354,7 +439,11 @@ def resolve_video_recall_parameters(def recall_video_parameters(current_user: CurrentUserOrDefault,queue_id: str = Path(..., description="The queue id to perform this operation on"),- parameters: VideoRecallParameter = Body(..., description="Video parameters to recall"),+ parameters: VideoRecallParameter = Body(+ ...,+ description="Video parameters to recall. Every field is optional: send only the ones to change.",+ openapi_examples=VIDEO_RECALL_EXAMPLES,+ ),mode: VideoRecallMode = Query(default="recall", description="`recall` applies every field; `remix` applies everything except the seed"),@@ -377,15 +466,18 @@ def recall_video_parameters(assert_image_move_maintenance_inactive()resolved, skipped = resolve_video_recall_parameters(parameters, mode, current_user)+ overridden = apply_media_precedence(resolved)if not resolved:return VideoRecallParametersResponse(- status="nothing_resolved", queue_id=queue_id, parameters={}, skipped=skipped+ status="nothing_resolved", queue_id=queue_id, parameters={}, skipped=skipped, overridden=overridden)ApiDependencies.invoker.services.events.emit_video_recall_requested(queue_id, current_user.user_id, "parameters", mode=mode, strict=strict, parameters=resolved)- return VideoRecallParametersResponse(status="success", queue_id=queue_id, parameters=resolved, skipped=skipped)+ return VideoRecallParametersResponse(+ status="success", queue_id=queue_id, parameters=resolved, skipped=skipped, overridden=overridden+ )def _emit_video_placement(diff --git a/invokeai/frontend/web/openapi.json b/invokeai/frontend/web/openapi.jsonindex 4fdbddd44c..99253080bf 100644--- a/invokeai/frontend/web/openapi.json+++ b/invokeai/frontend/web/openapi.json@@ -15507,7 +15507,53 @@"application/json": {"schema": {"$ref": "#/components/schemas/VideoRecallParameter",- "description": "Video parameters to recall"+ "description": "Video parameters to recall. Every field is optional: send only the ones to change."+ },+ "examples": {+ "prompt_and_model": {+ "summary": "Prompt and model",+ "value": {+ "positive_prompt": "a heron takes flight over a misty lake",+ "model": "Wan 2.2 I2V A14B (Diffusers)"+ }+ },+ "first_frame": {+ "summary": "Start from a gallery image",+ "value": {+ "model": "Wan 2.2 I2V A14B (Diffusers)",+ "first_frame_image": {+ "image_name": "<gallery image name>.png"+ }+ }+ },+ "extend_video": {+ "summary": "Extend a gallery video",+ "value": {+ "positive_prompt": "the camera keeps panning left",+ "source_video": {+ "video_name": "<gallery video name>.mp4"+ },+ "source_video_start_frame": 0,+ "source_video_end_frame": 80+ }+ },+ "ref2va_references": {+ "summary": "MiniMax H3 Ref2VA references",+ "value": {+ "model": "MiniMax H3 Ref2VA Transformer (int8, pruned)",+ "minimax_h3_references": [+ {+ "kind": "image",+ "image_name": "<gallery image name>.png"+ },+ {+ "kind": "video",+ "video_name": "<gallery video name>.mp4",+ "conditioning": "video_audio"+ }+ ]+ }+ }}}}@@ -106174,6 +106220,14 @@"type": "array","title": "Skipped","description": "Requested fields dropped because their model or media could not be used"+ },+ "overridden": {+ "additionalProperties": {+ "type": "string"+ },+ "type": "object",+ "title": "Overridden",+ "description": "Requested media fields dropped because another medium in the same request takes precedence over them, mapped to that field (e.g. first_frame_image -> source_video)"}},"type": "object",diff --git a/invokeai/frontend/web/src/services/api/schema.ts b/invokeai/frontend/web/src/services/api/schema.tsindex 9f48c30dc1..a195885c6a 100644--- a/invokeai/frontend/web/src/services/api/schema.ts+++ b/invokeai/frontend/web/src/services/api/schema.ts@@ -47606,6 +47606,13 @@ export type components = {* @description Requested fields dropped because their model or media could not be used*/skipped: string[];+ /**+ * Overridden+ * @description Requested media fields dropped because another medium in the same request takes precedence over them, mapped to that field (e.g. first_frame_image -> source_video)+ */+ overridden?: {+ [key: string]: string;+ };};/*** VideoRecallRequestedEventdiff --git a/tests/app/routers/test_video_recall.py b/tests/app/routers/test_video_recall.pyindex 15460a21b8..fdb68dadac 100644--- a/tests/app/routers/test_video_recall.py+++ b/tests/app/routers/test_video_recall.py@@ -383,37 +383,33 @@ class TestParameterRecall:"source_video_start_frame","source_video_end_frame",]+ # References replace the frame slots, so the last frame is reported as overridden rather than sent.+ assert response.json()["overridden"] == {"last_frame_image": "minimax_h3_references"}assert _only_recall_event(invoker).parameters == {- "last_frame_image": {"image_name": "last.png"},"minimax_h3_references": [{"kind": "video", "video_name": "ref.mp4", "conditioning": "video", "start_frame": 0, "end_frame": 8},{"kind": "image", "image_name": "ref.png", "detail": "max"},],}- def test_trims_and_roles_travel_with_their_media(self, invoker: Invoker, client: TestClient) -> None:- _save_video(invoker, "source.mp4")- _save_video(invoker, "song.mp4")+ @pytest.mark.parametrize(+ "body",+ [+ {"source_video": {"video_name": "clip.mp4"}, "source_video_start_frame": 8, "source_video_end_frame": 40},+ {"ltx2_conditioning_video": {"video_name": "clip.mp4"}, "ltx2_conditioning_role": "audio"},+ ],+ ids=["source-video-trim", "conditioning-role"],+ )+ def test_trims_and_roles_travel_with_their_media(+ self, invoker: Invoker, client: TestClient, body: dict[str, Any]+ ) -> None:+ _save_video(invoker, "clip.mp4")- response = client.post(- "/api/v1/recall/video/default",- json={- "source_video": {"video_name": "source.mp4"},- "source_video_start_frame": 8,- "source_video_end_frame": 40,- "ltx2_conditioning_video": {"video_name": "song.mp4"},- "ltx2_conditioning_role": "audio",- },- )+ response = client.post("/api/v1/recall/video/default", json=body)assert response.json()["skipped"] == []- assert _only_recall_event(invoker).parameters == {- "source_video": {"video_name": "source.mp4"},- "source_video_start_frame": 8,- "source_video_end_frame": 40,- "ltx2_conditioning_video": {"video_name": "song.mp4"},- "ltx2_conditioning_role": "audio",- }+ assert response.json()["overridden"] == {}+ assert _only_recall_event(invoker).parameters == bodydef test_a_missing_conditioning_video_takes_its_role_with_it(self, invoker: Invoker, client: TestClient) -> None:response = client.post(@@ -442,6 +438,104 @@ class TestParameterRecall:assert _only_recall_event(invoker).queue_id == "queue-b"+ @pytest.mark.parametrize(+ ("body", "sent", "overridden"),+ [+ (+ {"first_frame_image": {"image_name": "first.png"}, "source_video": {"video_name": "clip.mp4"}},+ {"source_video"},+ {"first_frame_image": "source_video"},+ ),+ (+ {+ "first_frame_image": {"image_name": "first.png"},+ "last_frame_image": {"image_name": "last.png"},+ "source_video": {"video_name": "clip.mp4"},+ "minimax_h3_references": [{"kind": "image", "image_name": "ref.png"}],+ },+ {"source_video", "minimax_h3_references"},+ {"first_frame_image": "minimax_h3_references", "last_frame_image": "minimax_h3_references"},+ ),+ (+ {+ "first_frame_image": {"image_name": "first.png"},+ "source_video": {"video_name": "clip.mp4"},+ "source_video_start_frame": 0,+ "source_video_end_frame": 8,+ "minimax_h3_references": [{"kind": "image", "image_name": "ref.png"}],+ "ltx2_conditioning_video": {"video_name": "song.mp4"},+ "ltx2_conditioning_role": "audio",+ },+ {"ltx2_conditioning_video", "ltx2_conditioning_role"},+ {+ "first_frame_image": "ltx2_conditioning_video",+ "source_video": "ltx2_conditioning_video",+ "source_video_start_frame": "ltx2_conditioning_video",+ "source_video_end_frame": "ltx2_conditioning_video",+ "minimax_h3_references": "ltx2_conditioning_video",+ },+ ),+ (+ {"first_frame_image": {"image_name": "first.png"}, "minimax_h3_references": []},+ {"first_frame_image", "minimax_h3_references"},+ {},+ ),+ (+ {+ "ltx2_conditioning_video": {"video_name": "song.mp4"},+ "ltx2_conditioning_role": "audio",+ "minimax_h3_references": [],+ },+ {"ltx2_conditioning_video", "ltx2_conditioning_role", "minimax_h3_references"},+ {},+ ),+ ],+ ids=[+ "initial-video-over-first-frame",+ "references-over-frames",+ "conditioning-clip-over-all",+ "empty-list-beside-a-frame",+ "empty-list-beside-a-clip",+ ],+ )+ def test_media_a_higher_precedence_medium_excludes_is_reported_not_sent(+ self,+ invoker: Invoker,+ client: TestClient,+ body: dict[str, Any],+ sent: set[str],+ overridden: dict[str, str],+ ) -> None:+ """The Video panel reads media in this precedence; sending a loser would be silently ignored there."""+ for image_name in ("first.png", "last.png", "ref.png"):+ _save_image(invoker, image_name)+ for video_name in ("clip.mp4", "song.mp4"):+ _save_video(invoker, video_name)++ response = client.post("/api/v1/recall/video/default", json=body)++ assert response.json()["overridden"] == overridden+ assert response.json()["skipped"] == []+ assert set(_only_recall_event(invoker).parameters) == sent++ def test_a_missing_winner_overrides_nothing(self, invoker: Invoker, client: TestClient) -> None:+ _save_image(invoker, "first.png")++ response = client.post(+ "/api/v1/recall/video/default",+ json={"first_frame_image": {"image_name": "first.png"}, "source_video": {"video_name": "gone.mp4"}},+ )++ assert response.json()["skipped"] == ["source_video"]+ assert response.json()["overridden"] == {}+ assert _only_recall_event(invoker).parameters == {"first_frame_image": {"image_name": "first.png"}}++ def test_every_swagger_example_is_a_valid_request(self) -> None:+ from invokeai.app.api.routers.video_recall import VIDEO_RECALL_EXAMPLES, VideoRecallParameter++ for example in VIDEO_RECALL_EXAMPLES.values():+ VideoRecallParameter.model_validate(example["value"])+def test_an_empty_request_emits_nothing(self, invoker: Invoker, client: TestClient) -> None:response = client.post("/api/v1/recall/video/default", json={})@@ -457,6 +551,7 @@ class TestParameterRecall:"queue_id": "default","parameters": {},"skipped": ["model"],+ "overridden": {},}assert _recall_events(invoker) == []