Config
Configuration
Configure the Railwail client with custom base URL, timeout, and other options.
Factory Function
The recommended way to create a client. Returns a fully configured Railwail instance.
TypeScript
import railwail from "railwail";
const rw = railwail("rw_live_xxxxx");
// With options
const rw = railwail("rw_live_xxxxx", {
timeout: 60000, // 1 minute
});Class Constructor
For more control, import and instantiate the Railwail class directly.
TypeScript
import { Railwail } from "railwail";
const rw = new Railwail("rw_live_xxxxx", {
baseUrl: "https://railwail.com", // default
timeout: 120000, // 2 min default (ms)
});Options
| Parameter | Type | Description |
|---|---|---|
apiKeyrequired | string | Your Railwail API key (starts with "rw_live_" or "rw_test_"). |
options.baseUrl | string | Base URL for API requests.Default: "https://railwail.com" |
options.timeout | number | Request timeout in milliseconds.Default: 120000 |
Environment Variables
We recommend using environment variables for your API key.
.env
RAILWAIL_API_KEY=rw_live_xxxxxTypeScript
import railwail from "railwail";
const rw = railwail(process.env.RAILWAIL_API_KEY!);Never expose your API key
Don't hardcode API keys in your source code or commit them to version control. Always use environment variables or a secrets manager.
Runtime Compatibility
| Runtime | Supported | Module Format |
|---|---|---|
| Node.js 18+ | Yes | ESM + CJS |
| Bun | Yes | ESM + CJS |
| Deno | Yes | ESM |
| Browser | Partial | ESM (use a backend proxy to protect your API key) |