Getting started

Quick Start

From zero to a first answer in three steps. The examples use the official OpenAI SDKs, plain cURL or the railwail npm package; pick your language in the tabs.

  1. 1

    Create an API key

    Sign in and open API keys. Keys start with rw_live_ and are shown once, so copy yours right away.

    A new key has the scopes read and chat. That is enough for this page. For images, video, audio or embeddings tick those scopes (or all) when you create the key; otherwise those calls return 403 insufficient_scope.

  2. 2

    Put the key in your environment

    Every example in these docs reads the key from RAILWAIL_API_KEY, so they run as copied.

    export RAILWAIL_API_KEY="rw_live_..."

    Check the key for free: listing one model costs nothing and answers 401 if the key is wrong.

    bash
    curl -s "https://railwail.com/api/v1/models?limit=1" \
      -H "Authorization: Bearer $RAILWAIL_API_KEY"
  3. 3

    Make your first request

    Chat with gpt-4o-mini. max_tokens caps the answer, and with it the credits the API reserves for the call.

    // npm i openai   (ESM: save as quickstart.mjs)
    import OpenAI from "openai";
    
    const client = new OpenAI({
      apiKey: process.env.RAILWAIL_API_KEY,
      baseURL: "https://railwail.com/api/v1",
    });
    
    const completion = await client.chat.completions.create({
      model: "gpt-4o-mini",
      messages: [{ role: "user", content: "Explain quantum computing in one paragraph." }],
      max_tokens: 300,
    });
    console.log(completion.choices[0].message.content);

Testing on the free trial

Signing in with Google gives 10 free credits ($0.10), usable 24 hours after sign-up. Until the first top-up, a single run may reserve at most 2 credits and an account runs at most 5 jobs per 24 hours. A chat call without max_tokens reserves credits for 4,096 output tokens (or the model's limit if lower) and can hit that cap (429 trial_limit), so keep max_tokens small. What a model costs is on its model page and on the pricing page.

More examples

Chat with a system prompt and history

Pass the whole conversation; the model sees every message.

const completion = await client.chat.completions.create({
  model: "claude-sonnet-4-6",
  max_tokens: 400,
  messages: [
    { role: "system", content: "You are a helpful coding assistant." },
    { role: "user", content: "How do I reverse a string in Python?" },
  ],
});
console.log(completion.choices[0].message.content);

Generate an image

Needs a key with the images scope. The response carries a URL per image; it can be a temporary provider link, so download the file if you want to keep it.

const image = await client.images.generate({
  model: "flux-1-schnell",
  prompt: "A cyberpunk cityscape at dusk, neon reflections on wet streets",
});
console.log(image.data[0].url); // null while a slow run is still processing (HTTP 202)

Embeddings

Vectors for search and retrieval, with the same key (it needs the embeddings scope). Limits and errors are on the embeddings page.

const res = await client.embeddings.create({ model: "text-embedding-3-small", input: ["first text", "second text"] });
console.log(res.data.length, res.data[0].embedding.length); // 2 1536

Next steps

Quick Start — Railwail Docs