SDK · images

rw.image()

Generate images from a prompt. Calls POST /api/v1/images/generations and returns the image URLs. The key needs the images scope.

Signature

TypeScript
rw.image(model: string, prompt: string, options?: ImageOptions): Promise<ImageResponse>

Parameters

Only model and prompt work for every model. The other options are passed on and used only where the model has that input; each model page lists its inputs.

modelrequired
string
Image model slug; the list below shows what runs right now.
promptrequired
string
What to draw, up to 4,000 characters.
options.n
numberclamped to 4
Number of images. Values above 4 are clamped to 4; each image is a separate, separately billed run.Default 1
options.size
stringmodel-dependent
256x256, 512x512, 1024x1024, 1024x1792 or 1792x1024, sent as width and height. Models that take an aspect ratio instead ignore it.
options.quality
stringmodel-dependent
standard or hd.
options.style
stringmodel-dependent
vivid or natural.
options.negative_prompt
stringmodel-dependent
What to leave out.

Response

TypeScript
interface ImageResponse {
  created: number;
  data: {
    url: string;             // null while the run is still processing (HTTP 202)
    revised_prompt?: string; // your prompt, unchanged
    // also present at runtime, not in the 1.0.0 types:
    // job_id: string; status: "completed" | "processing"
  }[];
}

Keep the file, not the link

url can point to the provider's storage and expire after a while, so download images you want to keep. If a run takes longer than about 85 seconds, the answer comes back with url: null and a job_id; fetch the result later with rw.job().

Examples

Basic

TypeScript
import railwail from "railwail";

const rw = railwail(process.env.RAILWAIL_API_KEY);

const res = await rw.image("flux-1-schnell", "A beautiful sunset over Tokyo");
console.log(res.data[0].url);

Several images

TypeScript
const res = await rw.image("flux-1-schnell", "A cyberpunk cityscape, neon, rain", { n: 2 });

for (const img of res.data) {
  console.log(img.url ?? "still processing");
}

Other models

Use any slug from the list below. For models with extra inputs (styles, reference images, aspect ratios) the model page shows the full input form and API code; the REST reference is Image Generation.

TypeScript
const res = await rw.image("flux-1-1-pro", "Product photo of a ceramic mug, studio light");

Image models you can call