Skip to content

Node.js SDK ​

SDKMAX is fully OpenAI-compatible, so in Node.js/TypeScript you can use the official openai package directly.

Install ​

bash
npm install openai

Initialize the client ​

javascript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: "sk-your-key", // created in the SDKMAX console
  baseURL: "https://api.sdkmax.com/v1",
});

Prefer environment variables

bash
export OPENAI_API_KEY="sk-your-key"
export OPENAI_BASE_URL="https://api.sdkmax.com/v1"

With these set, new OpenAI() picks them up automatically — no hardcoded secrets.

Chat completions ​

javascript
const resp = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Explain SDKMAX's core capabilities." },
  ],
});

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

Streaming ​

javascript
const stream = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Write a short poem about an AI gateway." }],
  stream: true,
});

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

Switching models ​

javascript
for (const model of ["gpt-4o", "claude-opus-4-8", "deepseek-chat"]) {
  const resp = await client.chat.completions.create({
    model,
    messages: [{ role: "user", content: "What's 1+1?" }],
  });
  console.log(model, "->", resp.choices[0].message.content);
}

Embeddings ​

javascript
const resp = await client.embeddings.create({
  model: "text-embedding-3-small",
  input: "SDKMAX is an enterprise AI gateway",
});

console.log(resp.data[0].embedding.length);

Generating images ​

javascript
const resp = await client.images.generate({
  model: "dall-e-3",
  prompt: "A cat riding a motorcycle through a cyberpunk city",
  size: "1024x1024",
});

console.log(resp.data[0].url);

See Images API.

Error handling ​

javascript
import OpenAI from "openai";

try {
  await client.chat.completions.create({ model: "gpt-4o", messages: [] });
} catch (err) {
  if (err instanceof OpenAI.RateLimitError) {
    // 429: quota exhausted or rate-limited — back off and retry
  } else if (err instanceof OpenAI.APIError) {
    console.error(err.status, err.message);
  } else {
    throw err;
  }
}

Full error code reference: Error Codes.

Calling from the browser? ​

Don't embed your API key in frontend code. Have the browser call your own backend, which holds the key and forwards the request to SDKMAX — this keeps the key out of end-user hands.

SDKMAX — Enterprise AI Gateway, Aggregating Global AI Resources