Core.GenerateImage is simpler and also accepts reference images.
Endpoints
Both endpoints accept JSON or
multipart/form-data and follow OpenAI’s request and response format, with a few Base44 fields added. Authenticate with Authorization: Bearer {token}.
Generate an image
With the Vercel AI SDK, create an OpenAI-compatible provider from the connection details and callgenerateImage(). Pass Base44 fields such as aspect_ratio and resolution under providerOptions, keyed by the provider name you chose.
Generate an image with the Vercel AI SDK
aspectRatio option isn’t sent to the gateway. Use aspect_ratio in providerOptions, or size with exact pixel dimensions.
To call the endpoint without a client library, send the request with fetch(). Setting response_format to url returns a link to a stored image instead of base64 data:
Generate an image with fetch
Use reference images
Reference images let you edit an existing image, keep a character or product consistent, or match a style. Describe in the prompt what to do with them. With the Vercel AI SDK, pass the images in the prompt. The SDK downloads each URL and uploads the image data to/images/edits, so each URL must be reachable from your backend function:
Edit an image with the Vercel AI SDK
reference_image_urls instead. This also works for private files that your app owns:
Pass reference image URLs
https:// URLs, data:image/... URIs, or file uploads. FLUX, GPT Image 2.5, Grok, and Seedream models accept only JPEG, PNG, and WebP. You can pass up to 10 reference images per request, and some models accept fewer. See Models and Limits.
Models
Setmodel to automatic or leave it out to let Base44 choose, or pin one of these model IDs. Image models are separate from the chat models the gateway uses for text.
A pinned model is never swapped for another one. If the model doesn’t support an option you set, the request fails with an error that names the option.
Supported aspect ratios
Supported aspect ratios
Supported output formats and backgrounds
Supported output formats and backgrounds
- GPT Image models:
output_formatcan bepng(default),jpeg, orwebp.backgroundcan beauto,opaque, ortransparent. - FLUX models:
output_formatcan bejpeg(default),png, orwebp. - Seedream models:
output_formatcan bejpegorpng. - Gemini and Grok models: Return the provider’s native format.
output_formatandbackgroundaren’t supported.
How automatic chooses a model
automatic picks the first model in this order that supports everything in your request, including the resolution, aspect ratio, reference images, and any quality, output_format, or background you set:
- Gemini 3.1 Flash Lite
- Gemini 3.1 Flash
- Gemini 2.5 Flash
- GPT Image 1
- GPT Image 2
- GPT Image 2.5 Flare
- GPT Image 2.5 Sunburst
2K or 4K resolution, or a 9:21 aspect ratio, moves it to Gemini 3.1 Flash. FLUX, Grok, and Seedream models are never chosen automatically, so pin them by ID to use them.
Quality
quality trades cost for detail, from low up to high, with xhigh and max available only on GPT Image 2.5 models. On GPT Image models, auto and an omitted quality both use low. Gemini and FLUX models don’t support quality.
Request parameters
The gateway rejects requests that set
mask, style, output_compression, moderation, partial_images, or stream. Other fields that aren’t listed here are ignored.
Response
data has either b64_json with the image data, or url when you set response_format to url. URLs point to a file stored in your app’s public file storage. The Vercel AI SDK always requests b64_json and returns each image as a GeneratedFile with base64, uint8Array, and mediaType.
When you ask for more than one image, the gateway generates them in parallel. If some fail, data contains only the images that succeeded, and you’re billed only for those.
Estimate the cost
Setdry_run to true to see which model a request would run on and what it would cost, without generating an image or using credits:
Estimate the cost of a request
Limits
The gateway needs a
Content-Length header on every request, and rejects chunked uploads. fetch() and the Vercel AI SDK set it for you.
The Vercel AI SDK sends up to 10 images in one call. To generate more than 4 images with one
generateImage() call, set maxImagesPerCall: 4 (or 2 for Seedream) so the SDK splits them into several requests.Errors
Errors use OpenAI’s format,{ "error": { "message", "type", "code", "param" } }, so client libraries report them like any other OpenAI error.
See also
- ai-gateway: Get connection details and use chat models through the gateway.
- GenerateImage: Generate an image with one SDK call.
- Backend functions: Write the server-side code that calls the gateway.