# JavaScript

> Call DeepSeek, MiniMax and Kimi from Node.js with the official OpenAI library: setup, streaming, and keeping your API key off the browser.

Source: https://srotgateway.com/docs/javascript/

Use the official `openai` package for Node.js. Only the base URL and the key change.

```bash
npm install openai
export SROT_API_KEY="sg-..."
```

## Simple call

```js
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.srotgateway.com/v1",
  apiKey: process.env.SROT_API_KEY,
});

const reply = await client.chat.completions.create({
  model: "deepseek-v4.1-flash-fast",
  messages: [{ role: "user", content: "What is an API?" }],
});
console.log(reply.choices[0].message.content);
console.log(reply.usage);
```

## Streaming

```js
const stream = await client.chat.completions.create({
  model: "deepseek-v4.1-flash-fast",
  messages: [{ role: "user", content: "Write a 500-word story." }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
```

## Plain fetch (no library)

```js
const res = await fetch("https://api.srotgateway.com/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SROT_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "deepseek-v4.1-flash-fast",
    messages: [{ role: "user", content: "Hello" }],
  }),
});
const data = await res.json();
console.log(data.choices[0].message.content);
```

Don't put your key in code that runs in a visitor's browser: anyone could copy it. Call the API from your server instead.
