Authentication
All API requests require authentication via an API key. Here's how to get and use yours.
API Keys
Generate API keys from your Settings page. Each key is unique to your account and has a specific prefix.
| Prefix | Environment | Description |
|---|---|---|
rw_live_ | Production | For production applications. Requests are billed normally. |
rw_test_ | Testing | For development and testing. Limited functionality. |
Keep your key secret
Never expose your API key in client-side code, public repositories, or frontend bundles. Always use environment variables or a backend proxy.
Using the SDK
Pass your API key when creating the Railwail client. The SDK automatically includes it in all requests.
TypeScript
import railwail from "railwail";
// Pass your key directly
const rw = railwail("rw_live_xxxxx");
// Or use an environment variable (recommended)
const rw = railwail(process.env.RAILWAIL_API_KEY!);Using the REST API
For direct HTTP requests, include your API key as a Bearer token in the Authorization header.
HTTP Header
Authorization: Bearer rw_live_xxxxxjavascript
const response = await fetch("https://railwail.com/api/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": "Bearer rw_live_xxxxx",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello!" }],
}),
});
const data = await response.json();
console.log(data.choices[0].message.content);With the OpenAI SDK
The Railwail API is fully OpenAI-compatible. Just point the OpenAI SDK to our base URL.
javascript
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "rw_live_xxxxx",
baseURL: "https://railwail.com/api/v1",
});
const response = await client.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);Learn more
See the OpenAI Compatibility guide for details on supported features and endpoints.