Migration Guides

Migrate from OpenAI to Railwail in 2 Minutes

Step-by-step guide to switching from OpenAI to Railwail. Same SDK, same code, just change two lines. Get access to 200+ models through one API key.

Railwail4 min read

Created with AI assistance.

Migrate from OpenAI to Railwail in 2 Minutes
01 ยท Key takeaways

TL;DR โ€” Switch in Under 2 Minutes

  • Railwail is OpenAI-API-compatible โ€” your existing openai SDK works unchanged
  • Migration = change two values: baseURL and apiKey. No code refactor
  • Same chat completions endpoint, same streaming, same tool calling, same JSON mode
  • Bonus: instantly unlock 200+ models from Anthropic, Google, DeepSeek and more behind the same SDK

Try it on Railwail

Run GPT-4o

OpenAI$3.00/1M inBilled by actual usage

OpenAI's most capable multimodal model. Excellent for complex reasoning, coding, and creative tasks.

02

Why Move Off OpenAI Direct?

OpenAI's API is excellent โ€” but it locks you into a single vendor. When GPT-4o costs spike or a competitor releases a better model, you cannot switch without rewriting integration code. Railwail solves this by exposing major frontier models behind the OpenAI-compatible Chat Completions schema. You get the OpenAI developer experience plus the freedom to swap providers with a single string change.

In addition to portability, teams move to Railwail for the ability to test Claude, Gemini, Llama, DeepSeek and 200+ more models without managing separate accounts. This guide walks through the full migration end to end.

03

Step 1 โ€” Get a Railwail API Key

Sign up at railwail.com, go to Dashboard โ†’ API Keys, and click Create New Key. Keys are prefixed with rw_live_ and look like rw_live_xxxxxxxxxxxxxxxxxxxxxxxx. Sign up with Google to get 10 free credits ($0.10), usable 24 hours after sign-up.

Copy the key into your environment file. The convention in most projects is to keep the existing OPENAI_API_KEY name so you do not have to touch your config-loading code โ€” Railwail keys work in that variable transparently because the SDK does not validate the prefix.

04

Step 2 โ€” Change the Base URL

Before (OpenAI direct):

import OpenAI from "openai";

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
});

const res = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Hello" }],
});

After (Railwail):

import OpenAI from "openai";

const openai = new OpenAI({
  apiKey: process.env.RAILWAIL_API_KEY,
  baseURL: "https://railwail.com/api/v1",
});

const res = await openai.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Hello" }],
});

That is the entire diff. The rest of your app โ€” streaming, function calling, vision, JSON mode, retries โ€” works unchanged.

05

Step 3 โ€” Verify Streaming, Tools, Vision

Run your existing test suite. Because Railwail proxies the upstream OpenAI API directly when you call OpenAI model IDs, streaming SSE chunks, function/tool-call deltas, vision messages with image_url, and the response_format JSON mode all behave identically.

06

Step 4 โ€” Try a Non-OpenAI Model

This is where the migration starts paying off. With the same SDK and the same client object, you can route a request to Claude or Gemini just by changing the model string. There is no second SDK to install, no second API key, no separate billing.

JavaScript
// Same client, different model
const claude = await openai.chat.completions.create({
  model: "claude-sonnet-4-6",
  messages: [{ role: "user", content: "Hello from Claude" }],
});

const gemini = await openai.chat.completions.create({
  model: "gemini-2.5-pro",
  messages: [{ role: "user", content: "Hello from Gemini" }],
});
07

API Endpoint Mapping

OpenAI endpoint โ†’ Railwail endpoint
OpenAI directLive on RailwailRailwail equivalentNotes
POST /v1/chat/completionsโ€”POST /api/v1/chat/completionsIdentical schema
POST /v1/embeddingsโ€”POST /api/v1/embeddingsSame request shape
POST /v1/images/generations$0.042/imagestable-diffusion-3POST /api/v1/images/generationsFlux, SDXL, Stable Diffusion 3 via model param
POST /v1/audio/transcriptionsโ‰ˆ $0.0034/runwhisper-replicatePOST /api/v1/audio/transcriptionsWhisper via model param
POST /v1/audio/speechโ€”POST /api/v1/audio/speechOpenAI TTS via model param
GET /v1/modelsโ€”GET /api/v1/modelsReturns all Railwail models, OpenAI-format response
08

Model ID Mapping

You only need to change the model string if you want to try a different provider โ€” and even then, you can keep the OpenAI SDK.

OpenAI model โ†’ Railwail model ID
OpenAILive on RailwailRailwail (drop-in)Equivalent non-OpenAI alternative
gpt-4o$3.00/1M ingpt-4ogpt-4oclaude-sonnet-4-6 or gemini-2.5-pro
gpt-4o-mini$0.18/1M ingpt-4o-minigpt-4o-miniclaude-haiku-4-5 or gemini-3-flash
gpt-4-turbo$2.40/1M ingpt-4-1gpt-4-1claude-opus-4-8
o1-preview / o1-mini$2.40/1M inopenai-o3openai-o3 / openai-o4-minideepseek-v4-pro (open-weight reasoning)
text-embedding-3-small$0.024/1M intext-embedding-3-smalltext-embedding-3-smallโ€”
whisper-1โ‰ˆ $0.0034/runwhisper-replicatewhisper-replicateโ€”
tts-1 / tts-1-hd$0.018/1k charsopenai-tts-1openai-tts-1 / openai-tts-1-hdโ€”
09

Why Railwail Over OpenAI Direct

  • 200+ models behind one API key โ€” Claude, Gemini, DeepSeek, Flux
  • Single SDK โ€” keep the OpenAI client your team already knows
  • Built-in playground at railwail.com/models โ€” test any model before shipping
  • Spend caps and per-key rate limits to prevent runaway bills
  • Transparent per-token pricing โ€” no minimum monthly fees, no enterprise gating
10

FAQ

Do I need to change my code at all?

Only two values: the API key and the base URL. Everything else โ€” message format, streaming, tool calling, vision, JSON mode, retries, error codes โ€” is identical because Railwail implements the same OpenAI Chat Completions schema.

Will my OpenAI prompts still work the same way?

Yes. When you call an OpenAI model ID through Railwail, the request is forwarded to OpenAI's upstream API.

What about Assistants, Threads, and the OpenAI Files API?

The Assistants API is OpenAI-proprietary state management. Railwail supports the stateless Chat Completions surface โ€” which is what 95% of production apps use. For Assistants-style workflows, we recommend porting to the Chat Completions schema (it is simpler and more portable).

How do I handle billing during the migration?

Run both providers in parallel for a week. Send 10% of traffic to Railwail via a feature flag, verify output quality and latency, then ramp to 100%. Railwail bills in USD credits with itemized per-model usage so you can compare costs line-by-line.

Can I use OpenAI fine-tuned models through Railwail?

Custom OpenAI fine-tunes (ft:gpt-4o-mini:...) require your OpenAI account because the weights live in OpenAI's tenancy. You can keep calling them via the OpenAI SDK with the OpenAI base URL while routing everything else through Railwail in the same codebase.

Is there a rate limit on Railwail?

Default is 600 requests per minute per API key, configurable from 60 to 6,000 RPM when you create a key. There is no daily token cap โ€” you only stop hitting the API when your credit balance hits zero (or your monthly spend cap, if you have set one).

What if my data must never leave the EU?

Railwail does not offer EU data residency; the models run at the providers, mostly in the US.

11

Next Steps

  • Create your free account at railwail.com
  • Generate an API key in Dashboard โ†’ API Keys
  • Change two values in your code: baseURL and apiKey
  • Read the full API reference at railwail.com/docs
  • Browse all 200+ available models at railwail.com/models
  • Compare per-token pricing at railwail.com/pricing
  • Check the provider catalog at railwail.com/providers
Live

Models in this article

Live prices from Railwail's current rules, October 7, 2026.

  • GPT-4oOpenAI
    $3.00 / 1M input tokens$12.00/1M out
    1K in + 500 out tokens: โ‰ˆ $0.0090
    Try
  • $3.60 / 1M input tokens$18.00/1M out
    1K in + 500 out tokens: โ‰ˆ $0.0126
    Try
  • Gemini 2.5 ProGoogle DeepMind
    $1.50 / 1M input tokens$12.00/1M out
    1K in + 500 out tokens: โ‰ˆ $0.0075
    Try
  • $0.18 / 1M input tokens$0.72/1M out
    1K in + 500 out tokens: โ‰ˆ $0.00060
    Try
  • WhisperOpenAI
    โ‰ˆ $0.0034 per run
    Try
  • $0.024 / 1M input tokens
    1K in + 500 out tokens: โ‰ˆ $0.00010
    Try

โ‰ˆ billed by actual tokens or GPU time

Next step

Try GPT-4o on Railwail

Sign in with Google for 10 free credits (usable 24 hours after sign-up, runs up to 2 credits), or top up from $5.00. Unused balance does not expire.

TopicsOpenAIMigrationAPISDKChat CompletionsGPT-4o