Universal
rw.run()
The main method. Automatically routes to the right endpoint based on the model name. Returns a string for text, an array for images, or vectors for embeddings.
Signature
TypeScript
rw.run(model: string, input: string | ChatMessage[], options?: RunOptions): Promise<RunResult>Parameters
| Parameter | Type | Description |
|---|---|---|
modelrequired | string | Model slug, e.g. "gpt-4o", "flux-schnell", "text-embedding-3-small" |
inputrequired | string | ChatMessage[] | A prompt string or array of chat messages with role and content. |
options.type | "chat" | "image" | "embed" | Force a specific endpoint. By default, auto-detected from the model name. |
options.temperature | number | Sampling temperature (0-2). Only for chat models. |
options.max_tokens | number | Maximum output tokens. Only for chat models. |
options.top_p | number | Nucleus sampling threshold. Only for chat models. |
options.n | number | Number of images to generate (1-4). Only for image models. |
options.size | string | Image size: "256x256", "512x512", "1024x1024", "1024x1792", "1792x1024". Only for image models. |
options.negative_prompt | string | Things to exclude from generated images. Only for image models. |
Return Value
The return type depends on the model type:
| Model Type | Return Type | Description |
|---|---|---|
| Chat / Text | string | The assistant's text response |
| Image | ImageResult[] | Array of objects with .url and optional .revised_prompt |
| Embedding | number[][] | Array of embedding vectors |
Examples
Text generation with a simple prompt
TypeScript
const text = await rw.run("gpt-4o", "Explain quantum computing simply");
console.log(text); // "Quantum computing uses quantum bits..."Chat with message history
TypeScript
const reply = await rw.run("claude-sonnet-4-5-20250929", [
{ role: "system", content: "You are a pirate." },
{ role: "user", content: "Tell me a joke" },
]);
console.log(reply); // "Arrr, why did the pirate..."Image generation
TypeScript
const images = await rw.run("flux-schnell", "A cat in space");
console.log(images[0].url); // "https://..."Embeddings
TypeScript
const vecs = await rw.run("text-embedding-3-small", "Hello", { type: "embed" });
console.log(vecs[0].length); // 1536Force a specific endpoint
If the SDK doesn't recognize your model, use the type option:
TypeScript
// Force chat endpoint for a custom model
const reply = await rw.run("my-custom-model", "Hello!", { type: "chat" });
// Force image endpoint
const imgs = await rw.run("my-image-model", "A sunset", { type: "image" });When to use rw.run() vs specific methods
Use
rw.run() for quick prototyping and simple use cases. Use the specific methods (rw.chat(), rw.image(), rw.embed()) when you need the full response object with usage stats, token counts, or additional metadata.