JavaScript

Call SrotGateway from Node.js or the browser with the official OpenAI library.

View as Markdown

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

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

Simple call

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.srotgateway.in/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 UPI?" }],
});
console.log(reply.choices[0].message.content);
console.log(reply.usage);

Streaming

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)

const res = await fetch("https://api.srotgateway.in/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.

Next: curl