OpenFlowLM-Next icon indicating copy to clipboard operation
OpenFlowLM-Next copied to clipboard

Image generation API: OpenAI-compatible /v1/images/generations in `oflm serve`

Open Cyronius opened this issue 2 months ago • 0 comments

What this is

Let apps generate images through oflm serve, using the NPU image model from #127. The server speaks OpenAI's Images API, so any app already built for OpenAI should work unchanged. Apps written for vLLM-Omni, Lemonade or Automatic1111-style tools should work too, because the extra settings accept both of their naming styles.

What it will support

  • POST /v1/images/generations: text to image.
  • The usual OpenAI fields:
    • model;
    • prompt;
    • n: 1 to 10 images;
    • size: 512x512 or 1024x1024 (auto means 1024 × 1024);
    • output_format: png or jpeg.
  • The answer: images come back as base64 (b64_json), the way OpenAI returns them.
  • Optional extras:
    • seed: same seed, same image;
    • steps (also accepted as num_inference_steps);
    • cfg_scale / guidance_scale;
    • negative_prompt;
    • sampler / sampler_name.

Decisions already made

  • cfg_scale and negative_prompt are accepted but ignored. This model was trained to work without them. Automatic1111-style apps always send them, so refusing would break those apps. The server logs a line when it ignores them.

  • Samplers: Euler-family names are accepted (euler, Euler a, and so on). Anything else, like DPM++ 2M, gets a clear error listing the accepted names. A client never gets a different sampler without knowing it.

  • Formats: PNG and JPEG for now. Asking for WebP returns a clear "not implemented yet" error.

  • Sharing the NPU with chat:

    • By default, the server swaps between the chat model and the image model as requests arrive. A swap takes about 5 seconds.
    • Starting the server with oflm serve <model> --imagegen 1 keeps both loaded, just like --asr 1 and --embed 1 do today.
  • Editing images (/v1/images/edits): requests are accepted and checked, but answered with "not implemented yet" until the NPU can read input images.

  • Not planned:

    • /variations: OpenAI no longer documents it;
    • URL responses;
    • ComfyUI's API.

    An Automatic1111-style endpoint (/sdapi/v1/txt2img) gets added only if a specific app needs it.

Needs to happen first

#127: the model has to be installable and runnable from the command line.

To find out along the way

  • Do the chat model and the image model fit on the NPU together? The image model uses 6 of the NPU's hardware contexts. That decides how far --imagegen 1 can go.

Done when

  • A standard OpenAI client can call /v1/images/generations on oflm serve and get back a valid image of the requested size and format.
  • Bad requests get clear errors, for example an unsupported size or sampler.
  • Chat keeps working before and after image requests.

More detail

The plan, with every field and requirement: specs/server-api/plans/images-api.md (on branch feat/open-diffusion).

Cyronius avatar Sep 27 '26 19:09 Cyronius