ASK KNOX
beta
LESSON 447

AI Image Generation in the Pipeline — Fallback Chains

Leonardo fails ~3% of runs. Without a fallback chain, 3% of Mondays publish without a hero image.

8 min read·Production Content Pipelines

The Image Problem in Production

The beginner pipeline generated one image, checked that it looked correct, and moved on. Production image generation has a different requirement: the pipeline must generate a valid hero image every time, without manual intervention, even when the primary provider fails.

This is not paranoia. Leonardo AI, Knox's primary image provider, experiences periodic failures — rate limit surges on high-demand mornings, CDN failures that return empty bodies with HTTP 200, and occasional content policy rejections. These failures happen roughly 3% of the time. Without a fallback chain, 3% of Monday articles publish without a hero image. With a three-provider fallback chain, 0% do.

The Three-Provider Chain

Knox's pipeline uses three providers in fixed order, each with defined triggers and quality gates:

The provider selection logic is straightforward: attempt Leonardo first, validate with the quality gate, and only trigger the next provider if the gate fails. The pipeline never attempts providers in parallel — it tries each in sequence, stopping at the first success.

Leonardo Phoenix 1.0 is the primary for editorial quality — use the Phoenix model ID from your Leonardo dashboard or API docs. Its strengths are consistent lighting, composition awareness, and style preset support. When given a precise prompt (title + excerpt + style directive), it reliably produces images that match Knox's editorial aesthetic. The failure modes are API-level — rate limits, server errors, CDN hiccups — not quality failures.

Gemini Imagen (imagen-4.0-generate-001) is the low-cost fallback. It is accessed via the mcp-image MCP server. The quality is slightly lower than Leonardo for editorial photography styles, but it excels at abstract and conceptual imagery — which often matches AI engineering content better than photorealistic images anyway. Depending on your access path (AI Studio free quota vs. a paid Vertex AI endpoint), it can add zero or minimal cost to the pipeline — confirm the access tier in your own setup.

OpenAI gpt-image-1 is the reliable backstop. It is the most expensive option ($0.04–$0.08 per image) and is reserved for the cases where both Leonardo and Gemini fail. Its advantage is prompt adherence — given a precise prompt, it produces what was asked for. Its disadvantage is cost, which is why it is position 3 rather than position 1.

Quality Gates on Each Provider

Every provider attempt runs through the same quality gate before the pipeline advances:

  1. File size > 50KB — an image smaller than 50KB is almost certainly a failed generation or an error body returned with HTTP 200. This catches CDN failures and content policy rejections.

  2. MIME type is image/* — the response must identify itself as an image. An error response body mistakenly treated as an image will fail this check.

  3. Image loads in browser — the URL or local path must serve a displayable image. CDN-cached images sometimes return valid MIME types from expired URLs.

  4. Aspect ratio matches target — this is a soft gate (logs a warning but does not block). Aspect ratio mismatches are logged for review but do not prevent publishing.

If any of the first three checks fail, the pipeline immediately triggers the next provider in the chain. It does not retry the same provider unless the failure was clearly transient (network timeout → single retry).

Aspect Ratio by Platform

Hero image requirements differ by platform. Getting this wrong produces cropped or stretched images in production:

The pipeline handles this by accepting a target_platform parameter at the start of the IMAGE stage. For blog articles, the target is blog and the aspect ratio is 16:9. For Discord carousels, the target is discord and the aspect ratio is 1:1. The provider prompt includes the required dimensions explicitly — the model does not guess.

The og:image requirement (1200×630, 1.91:1) is particularly important for blog articles. Twitter, LinkedIn, and Slack all use this image when the article URL is pasted. A hero image at 16:9 does not automatically satisfy the og:image requirement — they are different files with different dimensions. The pipeline generates both.

The Image Prompt Strategy

The image prompt is not a free-text description. It is a structured prompt built from the article's frontmatter:

Editorial photography. {title}. {excerpt}.
Style: [dark tech aesthetic / conceptual / abstract — based on source_type].
Aspect ratio: {target_aspect_ratio}.
No text overlays. No logos.

The "no text overlays" constraint is critical — AI image generators tend to add title text to editorial images, which looks wrong on a blog hero. The constraint is explicit in the prompt across all three providers.

The style directive is source-type-dependent: RSS and transcript articles get "dark tech aesthetic" (Knox's editorial style), manual queue entries get style guidance from Knox's additions.

Building Your Own Fallback Chain

For a pipeline you are building today, the minimum viable fallback chain is two providers: your primary and one free fallback. Adding a third is a judgment call based on how critical the image is to the publish flow.

The non-negotiables are:

  1. Each provider must have a quality gate — never accept HTTP 200 as "image generated"
  2. The chain must be sequential, not parallel — parallel attempts waste API quota
  3. Failure of all providers must fail the pipeline explicitly — never publish without a hero image

Write the chain now: implement the quality gate and the sequential try-each-provider-then-fall-through logic that turns "usually works" into "always produces an image."

The fallback chain is the difference between a pipeline that publishes reliably and one that requires Monday morning manual intervention. Build it once, trust it permanently.