SDK · setup

Configuration

Create the client with your key and, if needed, a different base URL or timeout. There are two equivalent ways: the factory (default export) and the Railwail class.

Factory function

client.mjs
import railwail from "railwail";

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

With options:

client.mjs
import railwail from "railwail";

const rw = railwail(process.env.RAILWAIL_API_KEY, {
  timeout: 60000, // 1 minute
});

Class constructor

client.mjs
import { Railwail } from "railwail";

const rw = new Railwail(process.env.RAILWAIL_API_KEY, {
  baseUrl: "https://railwail.com", // default
  timeout: 120000,                 // ms, default 2 minutes
});

Options

apiKeyrequired
string
Your key; it starts with rw_live_. There are no test keys.
options.baseUrl
string
The SDK appends /api/v1/… itself, so pass the site origin, not the API path.Default "https://railwail.com"
options.timeout
number
Milliseconds before the SDK gives up and throws an AbortError. The run itself continues on the server and is billed.Default 120000

Keep the key in the environment

The SDK does not read environment variables on its own; pass process.env.RAILWAIL_API_KEY explicitly.

export RAILWAIL_API_KEY="rw_live_..."

Never ship the key to a browser

Anyone who can read the key can spend your balance. Keep it in server code or a secrets manager, never in client bundles or version control. For testing, create a separate key with only the scopes you need and set a monthly spending limit.

Runtimes

RuntimeStatus
Node.js 18+Supported (ESM and CommonJS builds). Needs the global fetch that Node 18 provides.
Other runtimes with a global fetchShould work, as the SDK has no dependencies; not tested by us.
BrowserTechnically possible (the API allows CORS), but it exposes your key. Call the API from your backend.

Behaviour worth knowing

  • No automatic retries. Wrap calls yourself and retry only the codes that are safe to retry (see RailwailError).
  • API errors with a JSON body throw RailwailError; timeouts throw AbortError and network failures a TypeError.
  • The SDK does not expose response headers such as X-RateLimit-Remaining; use fetch or the OpenAI SDK if you need them.
Configuration — Railwail Docs