ReqLLM. Images
(ReqLLM v1.26.0)
View Source
Image generation functionality for ReqLLM.
This module provides image generation capabilities with support for:
- Prompt-based image generation (
generate_image/3) - Streaming generation with preview frames (
stream_image/3, OpenAI and Azure gpt-image models) - Model validation for image support
- The full gpt-image parameter set on OpenAI and Azure: quality tiers,
:background,:moderation,:output_compression, and:input_fidelity(seeschema/0for the per-option rules)
Image results are returned as canonical ReqLLM.Response structs where the
assistant message contains ReqLLM.Message.ContentPart entries of type
:image and/or :image_url.
Summary
Functions
Drops the options only the OpenAI Images wire format has fields for.
Generates images using an AI model with full response metadata.
Returns the base image generation options schema.
Streams image generation, yielding preview frames before the final image.
Streams image generation, raising on error.
Returns a list of model specs that likely support image generation.
Validates that a model supports image generation operations.
Functions
Drops the options only the OpenAI Images wire format has fields for.
:background, :moderation, :output_compression, and :input_fidelity are
part of this shared schema, so every provider's image path accepts them. A
provider whose endpoint has no such field must drop them in its
ReqLLM.Provider.translate_options/3 image clause: an option that survives
translation reaches the Req pipeline unregistered and raises there, instead of
surfacing through :on_unsupported like any other lossy translation.
Returns {opts, warnings}, with provider_label naming the provider in each
warning.
@spec generate_image( ReqLLM.model_input(), String.t() | list() | ReqLLM.Context.t(), keyword() ) :: {:ok, ReqLLM.Response.t()} | {:error, term()}
Generates images using an AI model with full response metadata.
Returns a canonical ReqLLM.Response where images are represented as message content parts.
@spec schema() :: NimbleOptions.t()
Returns the base image generation options schema.
@spec stream_image( ReqLLM.model_input(), String.t() | list() | ReqLLM.Context.t(), keyword() ) :: {:ok, ReqLLM.StreamResponse.t()} | {:error, term()}
Streams image generation, yielding preview frames before the final image.
See ReqLLM.stream_image/3 for the chunk contract. Supported for OpenAI and
Azure gpt-image models; other providers return ReqLLM.Error.Invalid.Parameter.
@spec stream_image!( ReqLLM.model_input(), String.t() | list() | ReqLLM.Context.t(), keyword() ) :: ReqLLM.StreamResponse.t() | no_return()
Streams image generation, raising on error.
Same as stream_image/3 but raises the error struct instead of returning
{:error, error}. Only errors raised before the request starts are surfaced
here; failures mid-stream still surface while enumerating or through
ReqLLM.StreamResponse.to_response/1.
@spec supported_models() :: [String.t()]
Returns a list of model specs that likely support image generation.
Uses capability metadata when present, otherwise falls back to a conservative name-based heuristic (models containing "image" or "imagen").
@spec validate_model(ReqLLM.model_input()) :: {:ok, LLMDB.Model.t()} | {:error, term()}
Validates that a model supports image generation operations.