Skip to main content
The AI Gateway serves OpenAI-compatible image endpoints, so your app can generate images from a prompt or edit them using reference images, with control over the model, aspect ratio, resolution, and quality. Requests are billed to your app’s credits, with no separate provider account or API key.
Before you begin: Call the gateway from a backend function rather than the browser, so you can check who’s calling and control usage before a request is billed to your app. Get the baseURL and token from base44.aiGateway.connection().
For a quick image from a prompt with no extra options, 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 call generateImage(). 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
The Vercel AI SDK’s own 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
To have the gateway fetch the images itself, pass their URLs in reference_image_urls instead. This also works for private files that your app owns:
Pass reference image URLs
Reference images can be JPEG, PNG, WebP, GIF, BMP, TIFF, or HEIC files, passed as 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

Set model 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.
  • GPT Image models: output_format can be png (default), jpeg, or webp. background can be auto, opaque, or transparent.
  • FLUX models: output_format can be jpeg (default), png, or webp.
  • Seedream models: output_format can be jpeg or png.
  • Gemini and Grok models: Return the provider’s native format. output_format and background aren’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:
  1. Gemini 3.1 Flash Lite
  2. Gemini 3.1 Flash
  3. Gemini 2.5 Flash
  4. GPT Image 1
  5. GPT Image 2
  6. GPT Image 2.5 Flare
  7. GPT Image 2.5 Sunburst
A plain request runs on Gemini 3.1 Flash Lite. Asking for 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.
Gemini models don’t support quality, output_format, or background. Setting any of them with automatic, even quality: "auto", skips the Gemini models and runs the request on a GPT Image model, which changes the result and the cost. Leave these fields out unless you need 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

Each item in 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

Set dry_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
Image requests use your app’s credits, the same shared quota as the rest of the AI Gateway. The cost of each image depends on the model, resolution, quality, and number of reference images. If a request produces no images, it’s still billed a minimum charge.

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