Skip to main content
Build a complete streaming chat in the terminal using just Node.js and the General Compute SDK. No frameworks, no build tools. Clone the full example project:
git clone https://github.com/generalcompute/docs
cd docs/examples/node-streaming
npm install

1. Set up the project

mkdir my-chat && cd my-chat
npm init -y
npm install @generalcompute/sdk

2. Write the chat loop

This creates a multi-turn chat that streams responses token-by-token:
index.ts
import GeneralCompute from "@generalcompute/sdk";
import * as readline from "readline";

const client = new GeneralCompute();

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
});

const messages: { role: "system" | "user" | "assistant"; content: string }[] = [
  { role: "system", content: "You are a helpful assistant." },
];

async function chat(userMessage: string) {
  messages.push({ role: "user", content: userMessage });

  const stream = await client.chat.completions.create({
    model: "minimax-m2.5",
    messages,
    stream: true,
  });

  let assistantMessage = "";

  process.stdout.write("\nAssistant: ");
  for await (const chunk of stream) {
    const content = chunk.choices[0]?.delta?.content;
    if (content) {
      process.stdout.write(content);
      assistantMessage += content;
    }
  }
  console.log("\n");

  messages.push({ role: "assistant", content: assistantMessage });
}

function prompt() {
  rl.question("You: ", async (input) => {
    if (input.toLowerCase() === "exit") {
      rl.close();
      return;
    }
    await chat(input);
    prompt();
  });
}

console.log('Chat with General Compute (type "exit" to quit)\n');
prompt();
We’re using minimax-m2.5 — our best general-purpose model. For complex reasoning tasks, try deepseek-v3.2. See all models on the Models & Pricing page.

3. Add your API key

export GENERALCOMPUTE_API_KEY=gc_your_api_key_here

4. Run it

npx tsx index.ts
You’ll get an interactive chat in your terminal with streaming responses:
Chat with General Compute (type "exit" to quit)

You: What is General Compute?