SDK · universal method

rw.run()

The shortest way to call a model: a string back for chat, an array of images for image models, vectors for embeddings. The SDK picks the endpoint from the model slug; the type option overrides it.

Signature

TypeScript
rw.run(model: string, input: string | ChatMessage[], options?: RunOptions): Promise<RunResult>

Parameters

modelrequired
string
Model slug, e.g. gpt-4o-mini, flux-1-schnell.
inputrequired
string | ChatMessage[]
A prompt, or chat messages with role and content.
options.type
"chat" | "image" | "embed"
Force an endpoint. Needed for image slugs the SDK does not recognise (see below).
options.max_tokens
number
Chat only. Caps the answer and the credits reserved for it; set it.
options.temperature
numbermodel-dependent
Chat only, 0–2. Some models ignore it (reasoning models, some Claude models).
options.top_p
numbermodel-dependent
Chat only.
options.n
numberclamped to 4
Images only. Values above 4 are clamped to 4; every image is billed.
options.size
stringmodel-dependent
Images only: 256x256, 512x512, 1024x1024, 1024x1792 or 1792x1024. Models that use an aspect ratio instead ignore it.
options.negative_prompt
stringmodel-dependent
Images only, where the model has such an input.

Return value

EndpointReturnsNotes
ChatstringThe assistant's text. Use rw.chat() for usage and finish_reason.
ImageImageResult[]Objects with url. At runtime they also carry job_id and status; url is null while a slow run is still processing (see rw.job()).
Embeddingnumber[][]One vector per input, in input order.

Examples

All examples assume const rw = railwail(process.env.RAILWAIL_API_KEY) in an ES module (see Overview).

Text from a prompt

TypeScript
const text = await rw.run("gpt-4o-mini", "Explain quantum computing simply.", { max_tokens: 300 });
console.log(text);

Chat with a system prompt

TypeScript
const reply = await rw.run(
  "claude-sonnet-4-6",
  [
    { role: "system", content: "You are a pirate." },
    { role: "user", content: "Tell me a joke." },
  ],
  { max_tokens: 200 },
);
console.log(reply);

Image generation

The key needs the images scope.

TypeScript
const images = await rw.run("flux-1-schnell", "A cat in space, watercolor");
console.log(images[0].url); // may be a temporary provider URL: download it to keep it

Force the endpoint

The SDK recognises image models by a built-in list and the substrings flux, dall-e, stable-diffusion, ideogram and recraft; embeddings by embed. Anything else goes to chat, so tell it:

TypeScript
const imgs = await rw.run("imagen-4-flagship", "A lighthouse at dusk", { type: "image" });

Not for video or speech

Video and speech models have no SDK method. With rw.run() they would go to chat and fail with 400 model_not_supported. Use video generation or audio speech.
rw.run() — Railwail Docs