Railwail SDK
The simplest way to use every AI model. One function call — no boilerplate, no configuration, no base URLs to remember.
Installation
npm install railwailZero dependencies. Works with Node.js 18+, Bun, and Deno. Supports both ESM and CommonJS.
Initialization
Create a client using the factory function or the class constructor.
import railwail from "railwail";
// Factory function (recommended)
const rw = railwail("rw_live_xxxxx");
// Or import the class directly
import { Railwail } from "railwail";
const rw = new Railwail("rw_live_xxxxx", {
baseUrl: "https://railwail.com", // default
timeout: 120000, // 2 min default (ms)
});Methods Overview
The SDK provides these methods for interacting with AI models.
| Method | Description | Returns |
|---|---|---|
| rw.run() | Universal method — auto-detects endpoint | string | ImageResult[] | number[][] |
| rw.chat() | Chat completions with full response | ChatResponse |
| rw.image() | Image generation from text | ImageResponse |
| rw.embed() | Vector embeddings | EmbeddingResponse |
| rw.models() | List available models | ModelListResponse |
| rw.model() | Get specific model details | Model |
| rw.job() | Check async job status | Job |
Start with rw.run()
Automatic Type Inference
The SDK automatically detects the right endpoint based on the model name. Image models (Flux, DALL-E, Stable Diffusion) route to the image endpoint, embedding models route to the embedding endpoint, and everything else goes to chat completions.
You can override this with the type option:
// Auto-detected as "image"
await rw.run("flux-schnell", "A cat");
// Auto-detected as "embed"
await rw.run("text-embedding-3-small", "Hello");
// Force specific endpoint
await rw.run("my-custom-model", "Hello", { type: "chat" });
await rw.run("my-custom-model", "A cat", { type: "image" });
await rw.run("my-custom-model", "Hello", { type: "embed" });Explore Methods
rw.run()
Universal method — the simplest way to use any model.
rw.chat()
Full chat completions with usage stats.
rw.image()
Generate images with size, count, and prompt options.
rw.embed()
Create vector embeddings for search and RAG.
rw.models()
List and filter available models.
rw.job()
Check async job status and results.
RailwailError
Error handling with status codes.
Configuration
Constructor options and class usage.