Qubittron Bastion
TypeScript SDKAPI reference

images

Generate images from text prompts.

client.images.generate(
  params: ImageGenerateParams,
  options?: { signal?: AbortSignal },
): Promise<ImageGenerateResponse>

Text-to-image generation. OpenAI-compatible response shape.

Example

const res = await client.images.generate({
  model: "sd-xl",
  prompt: "a sovereign Canadian moose, oil painting",
  size: "1024x1024",
  n: 1,
});

console.log(res.data[0]?.url);

Parameters

interface ImageGenerateParams {
  model: string;
  prompt: string;
  size?: string;                          // e.g. "1024x1024"
  quality?: string;                       // upstream-specific
  n?: number;                             // number of images
  response_format?: "url" | "b64_json";   // default: upstream default ("url")
}
  • size follows the OpenAI WxH format; valid combinations depend on the upstream model.
  • response_format: "b64_json" returns base64-encoded image bytes inline. Use "url" (the default) when you want CDN URLs.

Response

interface ImageData {
  url?: string;
  b64_json?: string;
}

interface ImageGenerateResponse {
  data: ImageData[];
  created: number;       // unix seconds
  model?: string;        // echoed back by some upstreams
}

Each entry has either url or b64_json populated, never both.

Saving a result

import { writeFile } from "node:fs/promises";

const res = await client.images.generate({
  model: "sd-xl",
  prompt: "a maple leaf in the style of A.Y. Jackson",
  response_format: "b64_json",
});

const b64 = res.data[0]?.b64_json;
if (b64) {
  await writeFile("out.png", Buffer.from(b64, "base64"));
}

Errors

WhenClass
Invalid model or unsupported sizeBadRequestError
Invalid keyAuthenticationError
Quota / content policyPermissionDeniedError
Rate-limitedRateLimitError
Upstream issueUpstreamError

On this page