Skip to content

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.

fix(external): hosted models fail in the v7 UI and lose transparency (#10321)

ximga3f9a35fff5da
diff --git a/invokeai/app/services/external_generation/image_utils.py b/invokeai/app/services/external_generation/image_utils.py
index a23c1f11d6..289f4c57e8 100644
--- a/invokeai/app/services/external_generation/image_utils.py
+++ b/invokeai/app/services/external_generation/image_utils.py
@@ -16,4 +16,7 @@ def encode_image_base64(image: PILImageType, format: str = "PNG") -> str:
def decode_image_base64(encoded: str) -> PILImageType:
data = base64.b64decode(encoded)
image = Image.open(io.BytesIO(data))
+ # Keep transparency (e.g. a "transparent" background request) instead of flattening it away.
+ if image.mode in ("RGBA", "LA") or (image.mode == "P" and "transparency" in image.info):
+ return image.convert("RGBA")
return image.convert("RGB")
diff --git a/invokeai/backend/model_manager/starter_models/external.py b/invokeai/backend/model_manager/starter_models/external.py
index 858b816f27..96625b0a7a 100644
--- a/invokeai/backend/model_manager/starter_models/external.py
+++ b/invokeai/backend/model_manager/starter_models/external.py
@@ -82,6 +82,7 @@ gemini_flash_image = StarterModel(
type=ModelType.ExternalImageGenerator,
format=ModelFormat.ExternalApi,
capabilities=ExternalModelCapabilities(
+ supports_negative_prompt=False,
modes=["txt2img"],
supports_seed=True,
supports_reference_images=True,
@@ -123,6 +124,7 @@ gemini_pro_image_preview = StarterModel(
type=ModelType.ExternalImageGenerator,
format=ModelFormat.ExternalApi,
capabilities=ExternalModelCapabilities(
+ supports_negative_prompt=False,
modes=["txt2img"],
supports_seed=True,
supports_reference_images=True,
@@ -144,6 +146,7 @@ gemini_3_1_flash_image_preview = StarterModel(
type=ModelType.ExternalImageGenerator,
format=ModelFormat.ExternalApi,
capabilities=ExternalModelCapabilities(
+ supports_negative_prompt=False,
modes=["txt2img"],
supports_seed=True,
supports_reference_images=True,
@@ -604,6 +607,7 @@ openai_gpt_image_2 = StarterModel(
type=ModelType.ExternalImageGenerator,
format=ModelFormat.ExternalApi,
capabilities=ExternalModelCapabilities(
+ supports_negative_prompt=False,
modes=["txt2img", "img2img"],
supports_reference_images=True,
max_images_per_request=10,
@@ -622,6 +626,7 @@ openai_gpt_image_1_5 = StarterModel(
type=ModelType.ExternalImageGenerator,
format=ModelFormat.ExternalApi,
capabilities=ExternalModelCapabilities(
+ supports_negative_prompt=False,
modes=["txt2img", "img2img"],
supports_reference_images=True,
max_images_per_request=10,
@@ -640,6 +645,7 @@ openai_gpt_image_1 = StarterModel(
type=ModelType.ExternalImageGenerator,
format=ModelFormat.ExternalApi,
capabilities=ExternalModelCapabilities(
+ supports_negative_prompt=False,
modes=["txt2img", "img2img"],
supports_reference_images=True,
max_images_per_request=10,
@@ -658,6 +664,7 @@ openai_gpt_image_1_mini = StarterModel(
type=ModelType.ExternalImageGenerator,
format=ModelFormat.ExternalApi,
capabilities=ExternalModelCapabilities(
+ supports_negative_prompt=False,
modes=["txt2img", "img2img"],
supports_reference_images=True,
max_images_per_request=10,
@@ -676,6 +683,7 @@ openai_dall_e_3 = StarterModel(
type=ModelType.ExternalImageGenerator,
format=ModelFormat.ExternalApi,
capabilities=ExternalModelCapabilities(
+ supports_negative_prompt=False,
modes=["txt2img"],
max_images_per_request=1,
allowed_aspect_ratios=["1:1", "7:4", "4:7"],
@@ -723,6 +731,7 @@ seedream_5_0 = StarterModel(
type=ModelType.ExternalImageGenerator,
format=ModelFormat.ExternalApi,
capabilities=ExternalModelCapabilities(
+ supports_negative_prompt=False,
modes=["txt2img", "img2img"],
supports_reference_images=True,
max_reference_images=14,
@@ -742,6 +751,7 @@ seedream_5_0_lite = StarterModel(
type=ModelType.ExternalImageGenerator,
format=ModelFormat.ExternalApi,
capabilities=ExternalModelCapabilities(
+ supports_negative_prompt=False,
modes=["txt2img", "img2img"],
supports_reference_images=True,
max_reference_images=14,
@@ -761,6 +771,7 @@ seedream_4_5 = StarterModel(
type=ModelType.ExternalImageGenerator,
format=ModelFormat.ExternalApi,
capabilities=ExternalModelCapabilities(
+ supports_negative_prompt=False,
modes=["txt2img", "img2img"],
supports_reference_images=True,
max_reference_images=14,
@@ -780,6 +791,7 @@ seedream_4_0 = StarterModel(
type=ModelType.ExternalImageGenerator,
format=ModelFormat.ExternalApi,
capabilities=ExternalModelCapabilities(
+ supports_negative_prompt=False,
modes=["txt2img", "img2img"],
supports_reference_images=True,
max_reference_images=14,
diff --git a/tests/app/services/external_generation/test_external_provider_adapters.py b/tests/app/services/external_generation/test_external_provider_adapters.py
index a64f197b4d..c0def594d8 100644
--- a/tests/app/services/external_generation/test_external_provider_adapters.py
+++ b/tests/app/services/external_generation/test_external_provider_adapters.py
@@ -1,3 +1,4 @@
+import dataclasses
import io
import logging
@@ -391,3 +392,33 @@ def test_openai_generate_txt2img_with_references_uses_edit_endpoint(monkeypatch:
assert image_files[0][1][0] == "image_0.png"
assert image_files[1][1][0] == "image_1.png"
assert result.images
+
+
+def test_decode_image_base64_keeps_alpha_and_flattens_opaque_images() -> None:
+ transparent = Image.new("RGBA", (8, 8), (255, 0, 0, 0))
+ assert decode_image_base64(encode_image_base64(transparent)).mode == "RGBA"
+ assert decode_image_base64(encode_image_base64(_make_image("white"))).mode == "RGB"
+ palette = Image.new("P", (8, 8))
+ palette.info["transparency"] = 0
+ assert decode_image_base64(encode_image_base64(palette)).mode == "RGBA"
+
+
+def test_openai_transparent_background_result_keeps_alpha(monkeypatch: pytest.MonkeyPatch) -> None:
+ config = InvokeAIAppConfig(external_openai_api_key="openai-key")
+ provider = OpenAIProvider(config, logging.getLogger("test"))
+ request = dataclasses.replace(
+ _build_request(_build_model("openai", "gpt-image-1")), provider_options={"background": "transparent"}
+ )
+ encoded = encode_image_base64(Image.new("RGBA", (32, 32), (0, 0, 0, 0)))
+ captured: dict[str, object] = {}
+
+ def fake_post(url: str, headers: dict, json: dict, timeout: int) -> DummyResponse:
+ captured["json"] = json
+ return DummyResponse(ok=True, json_data={"data": [{"b64_json": encoded}]})
+
+ monkeypatch.setattr("requests.post", fake_post)
+
+ result = provider.generate(request)
+
+ assert captured["json"]["background"] == "transparent" # type: ignore[index]
+ assert result.images[0].image.mode == "RGBA"
diff --git a/tests/app/services/external_generation/test_external_starter_model_capabilities.py b/tests/app/services/external_generation/test_external_starter_model_capabilities.py
new file mode 100644
index 0000000000..538772d41e
--- /dev/null
+++ b/tests/app/services/external_generation/test_external_starter_model_capabilities.py
@@ -0,0 +1,36 @@
+"""External starter models must not advertise capabilities their provider's invocation node can't accept.
+
+The frontend wires graph edges from model capabilities (e.g. a `negative_prompt` edge when
+`supports_negative_prompt` is true). If the node has no such field, every generation fails graph validation.
+"""
+
+import pytest
+
+from invokeai.app.invocations.external_image_generation import BaseExternalImageGenerationInvocation
+from invokeai.backend.model_manager.starter_models import STARTER_MODELS
+
+
+def _invocations_by_provider() -> dict[str, type[BaseExternalImageGenerationInvocation]]:
+ found: dict[str, type[BaseExternalImageGenerationInvocation]] = {}
+ pending = list(BaseExternalImageGenerationInvocation.__subclasses__())
+ while pending:
+ cls = pending.pop()
+ pending.extend(cls.__subclasses__())
+ provider_id = getattr(cls, "provider_id", None)
+ if isinstance(provider_id, str) and provider_id:
+ found[provider_id] = cls
+ return found
+
+
+EXTERNAL_STARTERS = [m for m in STARTER_MODELS if m.source.startswith("external://") and m.capabilities is not None]
+
+
[email protected]("starter", EXTERNAL_STARTERS, ids=lambda m: m.source)
+def test_negative_prompt_capability_matches_invocation_fields(starter) -> None:
+ provider_id = starter.source.removeprefix("external://").split("/", 1)[0]
+ invocation = _invocations_by_provider().get(provider_id)
+ assert invocation is not None, f"no invocation node registered for provider {provider_id!r}"
+ if starter.capabilities.supports_negative_prompt:
+ assert "negative_prompt" in invocation.model_fields, (
+ f"{starter.source} advertises negative prompts but {invocation.__name__} has no negative_prompt field"
+ )