openAIImages
June 15, 2026 · View on GitHub
Connect to OpenAI® Image Generation API from MATLAB®
Creation
Syntax
model = openAIImages
model = openAIImages(___,APIKey=key)
model = openAIImages(___,Name=Value)
Description
Connect to the OpenAI Image Generation API to generate images using models developed by OpenAI.
To connect to the OpenAI API, you need a valid API key. For information on how to obtain an API key, see https://platform.openai.com/docs/quickstart.
model = openAIImages creates an openAIImages object. Connecting to the OpenAI API requires a valid API key. Either set the environment variable OPENAI_API_KEY or specify the APIKey name-value argument.
model = openAIImages(___,APIKey=key) uses the specified API key.
model = openAIImages(___,Name=Value) specifies additional options using one or more name-value arguments.
Input Arguments
Name-Value Arguments
APIKey — OpenAI API key
character vector | string scalar
OpenAI API key to access OpenAI APIs.
Instead of using the APIKey name-value argument, you can also set the environment variable OPEN_API_KEY. For more information, see OpenAI API.
Properties Settable at Construction
Optionally specify these properties at construction using name-value arguments. Specify PropertyName1=PropertyValue1,...,PropertyNameN=PropertyValueN, where PropertyName is the property name and PropertyValue is the corresponding value.
ModelName — Model name
"gpt-image-1-mini" (default) | "gpt-image-1" | "gpt-image-1.5" | "gpt-image-2"
After construction, this property is read-only.
Name of the OpenAI model to use for image generation.
TimeOut — Connection timeout in seconds
10 (default) | nonnegative numeric scalar
After construction, this property is read-only.
If the OpenAI server does not respond within the timeout, then the function throws an error.
Object Functions
generate — Generate image using OpenAI image generation API
edit — Edit images
Examples
Generate Image
First, specify the OpenAI API key as an environment variable and save it to a file called ".env". Next, load the environment file using the loadenv function.
loadenv(".env")
Connect to the OpenAI Images API.
model = openAIImages;
Generate and display an image based on a natural language prompt.
catImage = generate(model,"An image of a cat confused by a complicated knitting pattern.");
imshow(catImage{1})

See Also
openAIChat | generate | edit
Copyright 2024-2026 The MathWorks, Inc.