Image generation
Generate images with an OpenAI-compatible API and private persistent storage.
Generate images through the runtime; manage their private assets through the API. Configure a supported provider credential and AWS S3 storage first. Your API key needs gateway:execute; discovery needs model:read, history needs image:read, and downloads need media:read.
Generate with the SDK
import { Nirmos } from "@nirmos/sdk";
const nirmos = new Nirmos({
auth: { type: "api-key", key: process.env.NIRMOS_API_KEY! },
apiBaseUrl: "https://YOUR_NIRMOS_API",
runtimeBaseUrl: "https://YOUR_NIRMOS_RUNTIME",
});
const models = await nirmos.images.models.list();
console.log(models.data.map(model => model.id));
const result = await nirmos.images.generate({
model: "openai/gpt-image-2.5-flare",
prompt: "A futuristic electric motorcycle photographed in a studio",
n: 1,
size: "1024x1024",
output_format: "png",
});
console.log(result.created, result.data[0]?.b64_json);
if (result.generationId) {
const generation = await nirmos.images.generations.get(result.generationId);
console.log(generation.outputs, generation.estimatedCost);
}Replace the origins with your deployments. Models must be present in your catalog, active, and backed by an active organization credential. The SDK never needs provider or AWS credentials. Image requests default to a 330-second SDK timeout and disable automatic retries, including requests with an idempotency key.
images.generate() returns the standard created, data, and optional provider usage fields. The SDK adds non-enumerable optional generationId and requestId correlation properties. Existing gateway.images.generate() retains its camel-case parameters and normalized images response.
HTTP and OpenAI client
Send POST /v1/images/generations to the runtime with Bearer authentication and a JSON body. Image generation accepts ordinary OpenAI requests without Nirmos replay headers. Supplied replay headers must still be valid.
curl https://YOUR_NIRMOS_RUNTIME/v1/images/generations \
-H "Authorization: Bearer $NIRMOS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"openai/gpt-image-2.5-flare","prompt":"A futuristic electric motorcycle","n":1,"size":"1024x1024"}'import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.NIRMOS_API_KEY,
baseURL: "https://YOUR_NIRMOS_RUNTIME/v1",
maxRetries: 0,
timeout: 330000,
});
const result = await client.images.generate({
model: "openai/gpt-image-2.5-flare",
prompt: "A futuristic electric motorcycle",
size: "1024x1024",
n: 1,
});
console.log(result.data[0].b64_json);See the generated HTTP reference for the exact request schema. Runtime responses are unwrapped OpenAI objects; management APIs use a data envelope. Generation correlation is also available in Nirmos-Generation-Id, X-Request-Id, and X-Trace-Id response headers.
Models and parameters
GET /v1/images/models returns { object: "list", data: [...] }. Each entry has an executable provider-qualified id and explicit capability metadata. nirmos/<route-slug> selects an existing configured route; its eligible targets must support the entire request.
Initial OpenAI profiles cover GPT Image 2.5 Flare/Sunburst and their September 8 snapshots, plus GPT Image 1.5 and GPT Image 2. Retired GPT Image 1 and DALL-E models are unavailable. Run catalog seeding when deploying this release.
Discover supported sizes, quality levels, formats, transparency, output counts, and operation support from capabilities. GPT Image 2/2.5 profiles also accept custom dimensions: both edges are multiples of 16, neither exceeds 3840 pixels, the aspect ratio is at most 3:1, and total pixels are 655,360 through 8,294,400. Experimental high resolutions remain subject to provider acceptance. GPT Image 1.5 uses the listed sizes only.
Supported fields include model, prompt, n, size, quality, background, output_format, output_compression, moderation, safety_identifier, and deprecated user. Compression applies only to JPEG/WebP. Transparent output requires PNG/WebP. Unsupported parameters return an error instead of being silently discarded. Current upstream specifications are maintained in the OpenAI reference.
Storage and URL responses
Every successful output is validated and stored in private S3 before success is returned. Default responses retain base64. As a Nirmos extension, request response_format: "url" to receive short-lived signed asset URLs. This extension is handled by Nirmos rather than forwarded to GPT Image. Never persist these URLs as asset identity; use generation outputs and asset IDs instead.
History is available through images.generations.list() and .get(id). Costs are estimates from reported usage and configured image pricing; unknown costs are null. Provider execution may be billable even if subsequent storage fails. Referenced generated assets cannot be deleted independently.
Errors and limits
Images V1 is synchronous, with a default 300-second runtime deadline, four outputs per request, two active executions per process, 20 MiB per image, and 40 MiB aggregate output bytes. Uploaded images are limited to 16 megapixels. Base64 increases response size; use a long-running Node deployment and proxy limits compatible with these bounds. The dashboard requests signed URLs.
Streaming, partial images, edits, variations, reference-image generation, seed, negative prompts, SVG, GIF, and async jobs are unavailable. Known unsupported streaming fields produce UNSUPPORTED_FEATURE; invalid or unsupported model parameters produce a 400 response. Storage configuration errors produce 503, capacity limits 429, and provider/persistence failures 502 or an applicable upstream status.
Check generation history after timeout or an interrupted response before submitting again. A timed-out provider request might still be billed. Nirmos only considers configured fallback after a definite rejection, never after ambiguous provider completion or an S3 failure. Errors suppress automatic retries in the official OpenAI client, but other clients should also disable generation retries.
Images SDK reference · Media guide · S3 configuration
Provider connections
Image generation supports configured OpenAI, Vercel AI Gateway, xAI/Grok, Google, OpenRouter, Together and Cloudflare Workers AI connections when discovery returns an executable model. Use images.models.list() and the returned provider-qualified model ID. A Vercel connection uses its own credentials even when the model creator is Google, OpenAI or xAI.
Only send settings supported by the returned capabilities. aspect_ratio and resolution are optional model-dependent controls. Omit output_format to use the provider default; outputs are verified and stored privately as PNG, JPEG or WebP. Provider-hosted artifacts are imported before Nirmos returns signed URLs. Generation remains synchronous to callers, including provider job polling, and paid POSTs are never automatically retried.