invoke-ai/InvokeAI · error · TypeError
Expected AutoencoderKL or FluxAutoEncoder for Z-Image VAE, g
Error message
Expected AutoencoderKL or FluxAutoEncoder for Z-Image VAE, got {type(vae_info.model).__name__}. Ensure you are using a compatible VAE model. What it means
Z-Image image-to-latents encodes images with a VAE that must be an AutoencoderKL or FluxAutoEncoder instance. vae_encode is a static method that validates the loaded model type before encoding; anything else (wrong architecture's VAE) raises TypeError so encoding proceeds only with a compatible VAE.
Source
Thrown at invokeai/app/invocations/z_image_image_to_latents.py:46
@invocation(
"z_image_i2l",
title="Image to Latents - Z-Image",
tags=["image", "latents", "vae", "i2l", "z-image"],
category="latents",
version="1.1.0",
classification=Classification.Prototype,
)
class ZImageImageToLatentsInvocation(BaseInvocation, WithMetadata, WithBoard):
"""Generates latents from an image using Z-Image VAE (supports both Diffusers and FLUX VAE)."""
image: ImageField = InputField(description="The image to encode.")
vae: VAEField = InputField(description=FieldDescriptions.vae, input=Input.Connection)
@staticmethod
def vae_encode(vae_info: LoadedModel, image_tensor: torch.Tensor) -> torch.Tensor:
if not isinstance(vae_info.model, (AutoencoderKL, FluxAutoEncoder)):
raise TypeError(
f"Expected AutoencoderKL or FluxAutoEncoder for Z-Image VAE, got {type(vae_info.model).__name__}. "
"Ensure you are using a compatible VAE model."
)
# Estimate working memory needed for VAE encode
estimated_working_memory = estimate_vae_working_memory_flux(
operation="encode",
image_tensor=image_tensor,
vae=vae_info.model,
)
with vae_info.model_on_device(working_mem_bytes=estimated_working_memory) as (_, vae):
if not isinstance(vae, (AutoencoderKL, FluxAutoEncoder)):
raise TypeError(
f"Expected AutoencoderKL or FluxAutoEncoder, got {type(vae).__name__}. "
"VAE model type changed unexpectedly after loading."
)
View on GitHub (pinned to 0b6a024f2f)
Solutions
- Connect a Z-Image-compatible VAE (AutoencoderKL or FluxAutoEncoder) to the invocation's 'vae' input
- Check the model manager that the VAE entry points at the correct architecture's file
- Replace the VAE node in the workflow with one matching the Z-Image base model
Example fix
// before img2latents = ZImageImageToLatentsInvocation(image=img, vae=sdxl_vae_field) // after img2latents = ZImageImageToLatentsInvocation(image=img, vae=z_image_vae_field)
Defensive patterns
Strategy: type-guard
Validate before calling
vae_info = context.models.load(vae_field.vae)
if not isinstance(vae_info.model, (AutoencoderKL, FluxAutoEncoder)):
raise TypeError(f"Incompatible VAE: {type(vae_info.model).__name__}") Type guard
def is_zimage_vae(model) -> bool:
return isinstance(model, (AutoencoderKL, FluxAutoEncoder)) Try / catch
try:
latents = img2latents.invoke(context)
except TypeError as e:
if "Expected AutoencoderKL or FluxAutoEncoder for Z-Image VAE" in str(e):
raise ModelCompatibilityError("swap in a Z-Image-compatible VAE") from e
raise Prevention
- Pair VAE nodes with the matching base model architecture
- Verify the VAE model-manager entry points at the right file after model updates
- Never reuse Flux/SD VAE nodes across architectures without checking the class
When it happens
Trigger: Calling invoke() on the Z-Image image-to-latents invocation where the VAE referenced by the VAEField loads to a model that is neither AutoencoderKL nor FluxAutoEncoder — e.g. an SDXL/SD-1 VAE or other architecture's autoencoder.
Common situations: Wiring a VAE from a different model family into a Z-Image workflow; a model-manager entry pointing at the wrong VAE file; using an old workflow whose VAE key refers to a now-different model.
Related errors
- Expected AutoencoderKLQwenImage or AutoencoderKLWan, got {ty
- Expected AutoencoderKLWan or FluxAutoEncoder for Anima VAE,
- Expected AutoencoderKLWan or FluxAutoEncoder, got {type(vae)
- Expected AutoencoderKLWan or FluxAutoEncoder for Anima VAE,
- Expected AutoencoderKLWan or FluxAutoEncoder, got {type(vae)
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/702fb24a1560d6d2.
Report an issue: GitHub.