Skip to content

feat(image): add --seed for reproducible generations#44

Open
mvanhorn wants to merge 1 commit into
vercel-labs:mainfrom
mvanhorn:feat/image-seed
Open

feat(image): add --seed for reproducible generations#44
mvanhorn wants to merge 1 commit into
vercel-labs:mainfrom
mvanhorn:feat/image-seed

Conversation

@mvanhorn

@mvanhorn mvanhorn commented May 2, 2026

Copy link
Copy Markdown

Summary

Adds --seed <n> to ai image. The flag is forwarded to generateImage as the SDK's top-level seed option, so providers that honor it (BFL, Stability, fal, and other supported models) return reproducible images for a given (prompt, model, seed) tuple.

Why this matters

The repo's tagline is "predictable artifact outputs" but ai image has no way to ask for a specific seed today. Seeded generation is the canonical reproducibility primitive across most image CLIs (replicate, fal, the Stable Diffusion UIs). With this flag, prompt iteration becomes a clean diff on the prompt rather than two changing variables.

Demo

Simulated demo. Real image generation needs an AI Gateway key, so the demo uses placeholder gradients to make the contrast visible:

demo

Without --seed, two runs of the same prompt produce different outputs. With --seed 42, two runs produce identical outputs.

Changes

  • packages/ai-cli/src/commands/image.ts: add --seed <n> option, parse via parsePositiveInt, forward as the SDK's top-level seed argument. Print a warning on stderr when every selected model is OpenAI (gpt-image ignores seed). Print a separate warning when --seed is combined with -n > 1, since the generations would be identical on supported providers.
  • packages/ai-cli/src/commands/completions.ts: add --seed to IMAGE_FLAGS and the zsh image flag list so tab completion picks it up in bash, zsh, and fish.
  • packages/ai-cli/README.md: add the --seed <n> row to the image flag block and a short note describing the SDK pass-through, the OpenAI exception, and the -n > 1 caveat.

Testing

bun run typecheck                            # passes
bun run --cwd packages/ai-cli format:check   # passes
bun run --cwd packages/ai-cli lint           # 24 pre-existing warnings in lib/openh264.mjs, 0 errors
bun test                                     # 71 tests, 0 fail (1 new in cli.test.ts)

The new test asserts ai image --seed abc x exits 1 with --seed must be a positive integer. The two warning paths follow the existing --quality/--style warning shape, so no new coverage was added for them.

buildProviderOptions stays the only place provider-specific keys are assembled; the OpenAI quality/style branch is unchanged.

@vercel

vercel Bot commented May 2, 2026

Copy link
Copy Markdown

@mvanhorn is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

? parseAspectRatio(opts.aspectRatio)
: undefined;
const provOpts = buildProviderOptions(opts);
const seed = opts.seed ? parsePositiveInt(opts.seed, "seed") : undefined;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

--seed 0 is incorrectly rejected because parsePositiveInt requires n > 0, but 0 is a valid seed value for image generation APIs.

Fix on Vercel

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