| stream_image | R Documentation |
Stream image generation with partial-image previews, useful for showing
the user progressive renders before the final image arrives. Currently
implemented for OpenAI's Responses API (partial_images 0–3); other
providers raise an informative error directing callers back to
generate_image().
stream_image(
model,
prompt,
callback,
output_dir = tempdir(),
partial_images = 2,
registry = NULL,
...
)
model |
An |
prompt |
Prompt describing the desired image. |
callback |
A function called for each partial/final event. The event
is a named list with |
output_dir |
Directory where the final image is written. Defaults to
|
partial_images |
Integer 0–3 — how many preview frames to request.
Defaults to |
registry |
Optional provider registry. |
... |
Additional arguments passed to the model implementation
(e.g. |
A GenerateImageResult with the final image.
## Not run:
provider <- create_openai()
model <- provider$image_model("gpt-image-1.5")
stream_image(model, "a glowing nebula", callback = function(event) {
if (event$type == "partial") {
message(sprintf("Preview #%d (%d bytes)", event$index, length(event$bytes)))
} else {
message("Final image arrived: ", length(event$bytes), " bytes")
}
})
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.