Lumoswitch Docs
Client setup

OpenAI SDK setup

Use the OpenAI SDK when a Node.js service or script calls Lumoswitch directly. The API configuration must expose OpenAI-compatible output.

Install and configure

pnpm add openai

export LUMOSWITCH_BASE_URL="https://api.lumoswitch.com/v1"
export LUMOSWITCH_API_KEY="your-lumoswitch-access-key"
export LUMOSWITCH_MODEL="your-client-facing-model-name"

Send a request

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: process.env.LUMOSWITCH_BASE_URL,
  apiKey: process.env.LUMOSWITCH_API_KEY,
});

const response = await client.chat.completions.create({
  model: process.env.LUMOSWITCH_MODEL,
  messages: [{ role: "user", content: "Say hello in one sentence." }],
});

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

The model value is the client-facing model name from the API configuration, not an upstream provider model ID.

Stream output

const stream = await client.chat.completions.create({
  model: process.env.LUMOSWITCH_MODEL,
  messages: [{ role: "user", content: "Write a short welcome message." }],
  stream: true,
});

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

Troubleshooting

  • For 401, verify that apiKey is a Lumoswitch access key.
  • For 404, ensure baseURL ends in /v1 without /v1/v1.
  • If the model is missing, copy its client-facing model name from /models.
  • Do not expose the access key in browser code; call Lumoswitch from your backend.

On this page