Skip to content

Quickstarts

From API key to first answer

Call Redrob with the official OpenAI SDKs for Python and JavaScript, or with curl: first answer, streaming, and answers in the language the question was asked in.

1. Get an API key

  1. Create a workspace, or sign in to one you already have.
  2. Open API keys and create a key.
  3. Copy it there and then. The full key is shown once and never again.
  4. Keep it server-side as REDROB_API_KEY.

2. Point the OpenAI SDK at Redrob

The completion API speaks OpenAI’s chat completions protocol, so the official SDKs work unchanged. There is no Redrob package to install: set the base URL and the key.

Python
# pip install openai
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["REDROB_API_KEY"],
    base_url="https://console.redrob.ai/api/backend/v1",
)

answer = client.chat.completions.create(
    model="auto",
    messages=[{"role": "user", "content": "What is a robot?"}],
)

print(answer.choices[0].message.content)
JavaScript and TypeScript
// npm install openai
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.REDROB_API_KEY,
  baseURL: "https://console.redrob.ai/api/backend/v1",
});

const answer = await client.chat.completions.create({
  model: "auto",
  messages: [{ role: "user", content: "What is a robot?" }],
});

console.log(answer.choices[0].message.content);

Anything built on those SDKs works the same way - LangChain, LlamaIndex, the Vercel AI SDK - wherever an OpenAI-compatible base URL can be configured.

Or use curl

Worth doing once to confirm the key before any application code is involved.

curl
export REDROB_API_KEY="rrk_…"

curl https://console.redrob.ai/api/backend/v1/chat/completions \
  -H "Authorization: Bearer $REDROB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "auto",
    "messages": [{ "role": "user", "content": "What is a robot?" }]
  }'

3. Work in more than one language

A completion needs nothing special for this: ask in Tamil and the answer comes back in Tamil. Translating is a separate call, so you decide what gets translated and pay for exactly that, rather than every non-English request quietly costing two.

Python
import httpx

# The completion itself needs nothing special: ask in Tamil, get Tamil back.
answer = client.chat.completions.create(
    model="auto",
    messages=[{"role": "user", "content": "தமிழில் சென்னையைப் பற்றி சொல்லுங்கள்."}],
)

# Translate when you want to, and pay for just that.
english = httpx.post(
    "https://console.redrob.ai/api/backend/v1/translate",
    headers={"Authorization": f"Bearer {REDROB_API_KEY}"},
    json={
        "input": answer.choices[0].message.content,
        "sourceLanguage": "auto",
        "targetLanguage": "en",
    },
).json()

print(english["text"])
JavaScript and TypeScript
const answer = await client.chat.completions.create({
  model: "auto",
  messages: [{ role: "user", content: "हिंदी में जयपुर के बारे में बताइए।" }],
});

const translated = await fetch(
  "https://console.redrob.ai/api/backend/v1/translate",
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.REDROB_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      input: answer.choices[0].message.content,
      sourceLanguage: "auto",
      targetLanguage: "en",
    }),
  }
).then(r => r.json());

Fifteen languages: en, ko, hi, bn, pa, gu, or, ta, te, kn, ml, ur, mr, ne, as. Pass auto as the source and the language is detected by script, which costs nothing.

4. Stream the answer

Python
stream = client.chat.completions.create(
    model="auto",
    messages=[{"role": "user", "content": "Explain the Indian monsoon."}],
    stream=True,
)

for chunk in stream:
    piece = chunk.choices[0].delta.content
    if piece:
        print(piece, end="", flush=True)
JavaScript and TypeScript
const stream = await client.chat.completions.create({
  model: "auto",
  messages: [{ role: "user", content: "Explain the Indian monsoon." }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

One caveat worth knowing: an answer that has to be translated back into the language it was asked in arrives as a single chunk, because there is nothing to show until the whole answer exists.

Where to go next

  • Every field and status code is in the API reference.
  • Try prompts without writing code in the playground.
  • Issue a key per environment in API keys, so one can be revoked without taking the others down.
  • Watch tokens, cost, and latency per call in request logs.