| OpenAIImageModel | R Documentation |
Image model implementation for OpenAI's image generation and editing APIs. Exported so that OpenAI-compatible providers in companion packages (e.g. aisdk.providers) can construct image models across package boundaries.
aisdk::ImageModelV1 -> OpenAIImageModel
new()Initialize the OpenAI image model.
OpenAIImageModel$new(model_id, config)
model_idThe model ID (e.g., "gpt-image-2", "gpt-image-1.5").
configConfiguration list.
do_generate_image()Generate images.
Tries the classic POST /v1/images/generations endpoint first. If that
returns a 404 with invalid_api_path / "not available" — the signal
some OpenAI-compatible proxies emit when they only expose the newer
Responses API — falls back to POST /v1/responses with the
image_generation tool and decodes the returned base64 image.
On the fallback path, the standard image params (quality, size,
output_format, output_compression, background, moderation, n)
are forwarded into the tool config, and a previous_response_id from a
prior fallback call is auto-attached so multi-turn edits ("now make it
realistic") work the same as on the language-model path. Use
get_last_response_id() / reset() to inspect or clear that state.
OpenAIImageModel$do_generate_image(params)
paramsA list of call options.
A GenerateImageResult object.
do_generate_image_classic()Generate images via the classic POST /v1/images/generations
endpoint. Called by do_generate_image(); exposed for callers that want
to bypass the Responses-API fallback on proxies they trust.
OpenAIImageModel$do_generate_image_classic(params)
paramsA list of call options (see do_generate_image).
A GenerateImageResult object.
do_generate_image_via_responses()Generate images via POST /v1/responses with the
image_generation tool. Used as a fallback when the classic
/v1/images/generations endpoint is unreachable (e.g. OpenAI-compatible
proxies that only expose the Responses API).
OpenAIImageModel$do_generate_image_via_responses(params)
paramsA list of call options (see do_generate_image).
A GenerateImageResult object.
looks_like_missing_classic_endpoint()Heuristic check used by do_generate_image() /
do_edit_image() to decide whether a classic-endpoint error looks
like "endpoint not available" on the proxy, in which case the
Responses-API fallback is taken. Matches both the /images/generations
and /images/edits paths.
OpenAIImageModel$looks_like_missing_classic_endpoint(err)
errAn error condition raised by the classic-endpoint call.
TRUE if the error message matches the "missing endpoint" shape.
get_last_response_id()Return the most recent Responses-API response id captured
during the /v1/responses fallback path. Used to chain multi-turn
image edits via previous_response_id.
OpenAIImageModel$get_last_response_id()
Character scalar or NULL if no fallback call has succeeded yet.
reset()Clear any stored previous_response_id, ending the current
multi-turn image session on the Responses-API fallback path.
OpenAIImageModel$reset()
The model, invisibly.
do_edit_image()Edit images.
Tries the classic POST /v1/images/edits multipart endpoint first.
If that returns the same "missing endpoint" 404 signal handled by
do_generate_image(), falls back to POST /v1/responses with the
source image inlined as an input_image data URL and the optional
mask passed via input_image_mask on the image_generation tool.
The Responses fallback accepts a single source image per turn
(multi-reference edit is classic-only). Image params (quality,
size, output_format, background, output_compression,
moderation, input_fidelity) are forwarded into the tool config,
and previous_response_id is auto-attached from any prior fallback
call so iterative edits chain.
OpenAIImageModel$do_edit_image(params)
paramsA list of call options.
A GenerateImageResult object.
do_edit_image_classic()Edit images via the classic POST /v1/images/edits
multipart endpoint. Called by do_edit_image(); exposed for callers
that want to bypass the Responses-API fallback.
OpenAIImageModel$do_edit_image_classic(params)
paramsA list of call options (see do_edit_image).
A GenerateImageResult object.
do_stream_image()Stream image generation with partial-image previews via
POST /v1/responses. Sets stream = TRUE and partial_images on
the image_generation tool config; dispatches SSE events to the
user-supplied callback (one per partial frame, one final). Uses
the same Responses-API path as the non-streaming fallback, with the
same previous_response_id chaining.
OpenAIImageModel$do_stream_image(params, callback)
paramsA list of call options. The partial_images field
(0–3) controls how many preview frames the API emits before the
final image; default 2.
callbackA function receiving each event list.
A GenerateImageResult with the final image.
do_edit_image_via_responses()Edit images via POST /v1/responses with the
image_generation tool in edit mode. Inlines the source image as a
base64 data URL inside an input_image block; passes the optional
mask via the tool's input_image_mask field.
OpenAIImageModel$do_edit_image_via_responses(params)
paramsA list of call options (see do_edit_image).
A GenerateImageResult object.
clone()The objects of this class are cloneable with this method.
OpenAIImageModel$clone(deep = FALSE)
deepWhether to make a deep clone.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.