The railwail SDK is JavaScript/TypeScript only; there is no Python package. Python tabs on this page use the official OpenAI SDK with base_url="https://railwail.com/api/v1". OpenAI compatibility
This page documents the railwail npm SDK. cURL tabs call the same REST endpoints directly; see the REST API reference.
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
import railwail from "railwail";
const rw = railwail(process.env.RAILWAIL_API_KEY);With options:
import railwail from "railwail";
const rw = railwail(process.env.RAILWAIL_API_KEY, {
timeout: 60000, // 1 minute
});Class constructor
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
apiKeyrequiredstring
Your key; it starts with
rw_live_. There are no test keys.options.baseUrlstring
The SDK appends /api/v1/… itself, so pass the site origin, not the API path.Default
"https://railwail.com"options.timeoutnumber
Milliseconds before the SDK gives up and throws an AbortError. The run itself continues on the server and is billed.Default
120000Keep 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_..."$env:RAILWAIL_API_KEY = "rw_live_..."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
| Runtime | Status |
|---|---|
| Node.js 18+ | Supported (ESM and CommonJS builds). Needs the global fetch that Node 18 provides. |
| Other runtimes with a global fetch | Should work, as the SDK has no dependencies; not tested by us. |
| Browser | Technically 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 throwAbortErrorand network failures aTypeError. - The SDK does not expose response headers such as
X-RateLimit-Remaining; use fetch or the OpenAI SDK if you need them.