feat(openai): simulate image generation endpoint (gpt-image / ChatGPT Images) - #76
Merged
Merged
Conversation
… Images)
Add POST /openai/v1/images/generations simulating the gpt-image family
("ChatGPT Images"). Each request returns a synthetic, watermarked PNG of the
exact requested size that renders the prompt text and a "LLMSIM SIMULATED
IMAGE" label, so generated bytes are unmistakably simulated.
- Self-contained PNG synthesis (src/imagegen.rs): dependency-free indexed-PNG
encoder (CRC32/Adler32/stored-DEFLATE), base64 encoder, and a 5x7 bitmap
font for readable, deterministic placeholder images.
- Image API types and streaming events (src/openai/images.rs): request/response
shapes, usage accounting scaled by size/quality, and quality/size-anchored
generation timing.
- Streaming engine (src/image_stream.rs): emits image_generation.partial_image
frames (progressively sharper previews) then image_generation.completed,
evenly spaced across the simulated generation time.
- Register gpt-image-1, gpt-image-1-mini, gpt-image-1.5 model profiles; track
image_requests in stats.
- Examples (Python + TypeScript), spec (specs/image-generation.md), docs, and
integration tests covering non-streaming, n>1, defaults, streaming partials,
and model listing. Wire both examples into CI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a simulated OpenAI image generation endpoint
POST /openai/v1/images/generations, replicating the traffic shape of the gpt-image family (the "ChatGPT Images" capability) without running a real model.Each request returns a synthetic but valid PNG of the exact requested size that renders the request prompt text and a clear "LLMSIM SIMULATED IMAGE" watermark, so generated bytes are unambiguously identifiable as simulated.
Highlights:
image_generation.partial_image→image_generation.completed).src/imagegen.rs): indexed-PNG encoder (CRC32/Adler32/stored-DEFLATE), base64 encoder, and a 5×7 bitmap font for readable, deterministic placeholders.instant/fastcollapse the wait for tests/load runs).gpt-image-1,gpt-image-1-mini,gpt-image-1.5model profiles; tracks animage_requestsstat.Why
LLMSim simulates the shape of LLM API traffic for testing and development. Image generation is a common production workload (gpt-image / ChatGPT Images) that was not yet covered, so clients had no way to exercise image-generation request/response handling — including the partial-image streaming flow — against the simulator.
How
src/openai/images.rs: request/response types, streaming event shapes, usage accounting (text input + size/quality-scaled image output tokens), and timing.src/imagegen.rs: placeholder image synthesis with a tiny self-contained PNG encoder and bitmap font; aCanvasabstraction draws the gradient background, header (model/size/quality), wrapped prompt, and watermark. Progressive previews are simulated via decreasing pixelation.src/image_stream.rs: streaming engine that emits partial frames then a completed frame, evenly spaced across the simulated generation time.src/cli/handlers.rs+src/cli/mod.rs:create_imagehandler and route, sharing the existing error-injection and stats plumbing.EndpointType::Imagesandimage_requestsadded to stats.Risk
Checklist
imagegen,image_stream,openai::images), 5 integration tests (tests/images_test.rs: non-streaming, n>1, defaults, streaming partials, model listing), and smoke-test coverage (tests/smoke_test.sh). Full suite green;cargo fmt --checkandcargo clippy -D warningsclean.specs/image-generation.md; updatedspecs/api-endpoints.md,specs/architecture.md,AGENTS.md.docs/api.md,README.md,examples/README.md, plus Python/TypeScript example clients.https://claude.ai/code/session_01NqMz1eKZ5Cf4TUg2V11cB4
Generated by Claude Code