Skip to content

feat(image): accept reference images in the Image Generator - #10755

Open
myxamediyar wants to merge 2 commits into
stagingfrom
feat/image-generator-reference-images
Open

myxamediyar wants to merge 2 commits into
stagingfrom
feat/image-generator-reference-images

Conversation

@myxamediyar

Copy link
Copy Markdown
Contributor

Summary

The Image Generator block took a text prompt only. It now also takes reference images, for models whose provider API accepts them.

  • Block: a Reference Images field: upload in basic mode, a reference to earlier block outputs in advanced mode. It shows only for models that take reference images.
    • With references attached, the settings dropdowns follow the endpoint the run will call.
    • The params mapping returns every setting the endpoint does not take as undefined, so it can't reach the tool through the executor's merge with the raw inputs. A value left over from the other endpoint is dropped too, such as a size of auto that only FLUX.2 [pro] edits take.
    • A reference that isn't a file object (a file ID, or a URL) goes on to the executor, which resolves a file ID and refuses anything else. A run never silently falls back to the prompt alone.
  • OpenAI: references go to /v1/images/edits as images: [{ image_url: <data URL> }], up to 16, with the same settings as generation. The JSON edits schema takes moderation and the gpt-image-2 sizes.
  • Google Gemini: references go in as inlineData parts after the prompt: up to 14 on Nano Banana 2.1, Nano Banana Pro and Nano Banana 2, and 3 on Nano Banana and Nano Banana 2 Lite.
  • Fal.ai: 88 of the 178 catalog models now name their image-input sibling under image in fal-image-models.json (/edit, /image-to-image, /remix or /redux). Each entry records the endpoint, the image field, the most images it takes, and that endpoint's own settings. An endpoint with an image to edit plus a separate reference list (Ideogram 4.5 edit, Luma Uni-1 edit) gets the first image as the one to edit and the rest as references.
  • Higgsfield: no catalog model takes image input. SOUL Standard's image_reference_url only guides prompt enhancement and takes a public URL, so the field stays hidden.
  • Validation: a model without image input, more images than a model takes, or a typed (unlisted) model ID is rejected before any file is read.
  • Server: each reference passes the same checks as the Video block's start frame: file access, the model-safe file check, and model-input provenance. Then it is read from storage under a 14 MB total, which stays under Gemini's ~20 MB inline request limit once base64 encoded. Its type is read from the bytes, and anything but PNG, JPEG or WebP is rejected.
  • Tool: image_generate takes an optional referenceImages (file[]). Tool metadata is regenerated.
  • Schema check: validate-fal-image-models.ts also checks every image-input variant, with one image and with its maximum, against fal's published schema.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • validate-fal-image-models.ts against fal's live schemas: all 140 runs with reference images pass across the 88 variants. The 21 failing runs are existing prompt-only endpoints whose schemas fal no longer publishes (404), unrelated to this change.
  • New request.test.ts cases: the rejections above, and the OpenAI edits and Gemini inline-part request shapes, which no schema check covers.
  • New operations.test.ts cases: a file the caller cannot read, a file not cleared to reach a model, non-image bytes, references over 14 MB, and invalid provenance are each refused without calling the provider. A readable reference reaches OpenAI with the type read from its bytes.
  • New field-analysis.test.ts cases, through the serializer and the executor's params merge:
    • a size the edit endpoint has no field for is dropped once a reference is attached;
    • a size only the edit endpoint takes is dropped once the reference is removed;
    • a reference left in the inactive member, or on a model that takes none, keeps the prompt-only request;
    • a reference that isn't a file object is passed on, not dropped.
  • Each run-time guard was removed in turn and its test went red.
  • bun run generate, lint, type-check, check:audits, test, and check-block-registry.ts origin/staging all pass.

Before merge: run one real generation with reference images per provider. fal documents no maximum queue request size, and references reach it as data URIs, the same way the Video block's start frame does. If fal rejects bodies near the 14 MB cap, references should go to fal storage instead.

Reviewers: please check the reference field's visibility and the settings dropdowns when you switch models or toggle basic/advanced mode with a reference attached.

Known gaps, left for follow-ups:

  • For OpenAI and Gemini models the upload field allows files up to ~50 MB. The shared upload component raises its cap from the model value for LLM attachments. The server still rejects more than 14 MB in total, and the field's placeholder states the total.
  • The hosted fal fallback cost floor is picked by matching the endpoint name. When the billing lookup fails, 12 of the new edit endpoints (and 49 existing image endpoints) fall through to the video floor.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

🤖 Generated with Claude Code

The Image Generator now takes optional reference images for models whose
provider API accepts them: OpenAI sends them to image edits, Gemini as
inline parts after the prompt, and 88 fal models to their image-input
sibling endpoint, now recorded in the fal image catalog. Higgsfield
models take none.

Each reference passes the start frame's file access, model-safe and
provenance checks, and is read under a 14 MB total with its type taken
from its bytes. The block's settings follow the endpoint the run calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Dec 5, 2026 1:30am UTC

Request Review

@myxamediyar
myxamediyar marked this pull request as ready for review December 4, 2026 01:02

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 14 files

Confidence score: 3/5

  • apps/sim/lib/internal/image/schema.ts rejects file IDs and URLs in referenceImages, so advanced-mode requests can fail with a 400 before reference resolution runs. Accept string references in the schema.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/lib/internal/image/schema.ts">

<violation number="1" location="apps/sim/lib/internal/image/schema.ts:45">
P1: This schema rejects non-file references. `referenceImages` is `z.array(userFileSchema)`, but advanced mode passes file IDs or URLs as strings, so `executeImageTool` returns 400 before resolution can run. Accept string references here, or confirm where they are resolved before this parse.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment on lines +45 to +47
referenceImages: z
.array(userFileSchema)
.max(MAX_REFERENCE_IMAGES, `Attach at most ${MAX_REFERENCE_IMAGES} reference images`)

@cubic-dev-ai cubic-dev-ai Bot Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: This schema rejects non-file references. referenceImages is z.array(userFileSchema), but advanced mode passes file IDs or URLs as strings, so executeImageTool returns 400 before resolution can run. Accept string references here, or confirm where they are resolved before this parse.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At apps/sim/lib/internal/image/schema.ts, line 45:

<comment>This schema rejects non-file references. `referenceImages` is `z.array(userFileSchema)`, but advanced mode passes file IDs or URLs as strings, so `executeImageTool` returns 400 before resolution can run. Accept string references here, or confirm where they are resolved before this parse.</comment>

<file context>
@@ -40,6 +42,10 @@ export const imageGenerationInputSchema = z
     enableSafetyChecker: booleanInputSchema.optional(),
     enableWebSearch: booleanInputSchema.optional(),
     thinkingLevel: z.string().optional(),
+    referenceImages: z
+      .array(userFileSchema)
+      .max(MAX_REFERENCE_IMAGES, `Attach at most ${MAX_REFERENCE_IMAGES} reference images`)
</file context>
Suggested change
referenceImages: z
.array(userFileSchema)
.max(MAX_REFERENCE_IMAGES, `Attach at most ${MAX_REFERENCE_IMAGES} reference images`)
referenceImages: z
.array(z.union([userFileSchema, z.string().trim().min(1)]))
.max(MAX_REFERENCE_IMAGES, `Attach at most ${MAX_REFERENCE_IMAGES} reference images`)
Fix with cubic

…or-reference-images

# Conflicts:
#	apps/sim/tools/generated/tool-metadata.ts

This branch was successfully deployed

1 active deployment
Preview — 50970867 Deployed Dec 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant