Routara
OPENAI SDK · NODE.JS / PRACTICAL GUIDE

Use the OpenAI Node.js SDK with Routara

The OpenAI JavaScript client accepts a custom baseURL. That means an existing Node.js service can test Routara without replacing its SDK. Make the first call from a server process: a browser bundle must never contain your API key.

01

Prepare a server-side project

Install the SDK and set the key in the process environment. Keep .env files and credentials out of Git.

npm install openai
export ROUTARA_API_KEY="your-key"
02

Run one chat completion

Save this as first-request.mjs and run node first-request.mjs. The model alibaba-qwen-turbo is an example; confirm it in the live catalog first.

import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.ROUTARA_API_KEY,
  baseURL: "https://api.routara.ai/v1",
});
const response = await client.chat.completions.create({
  model: "alibaba-qwen-turbo",
  messages: [{ role: "user", content: "Reply with one short integration tip." }],
  max_tokens: 64,
});
console.log(response.id, response.model, response.usage);
console.log(response.choices[0]?.message?.content);
03

Move traffic gradually

Inspect the first response, usage, and account balance. Keep your existing provider configuration available while testing. A 401 points to key setup; a 403 to policy or account access; a billing error to trial eligibility or wallet balance.

Before you ship

  • Run on the server, never in public JavaScript.
  • Use one small request before changing production traffic.
  • Check your account’s actual usage after the response.