Node.js SSE Client Example

This example shows how to call the Bitseek Chat SSE service using the official openai Node.js library.

Installation

npm install openai

Code Example

import OpenAI from "openai";

// 1. Initialize the client
// Point the baseURL to the Bitseek Chat service address
// Use your authentication key for apiKey
const client = new OpenAI({
    baseURL: "https://chat-proxy.bitseek.ai/v1",
    apiKey: "<API-KEY>",
});

async function main() {
    // 2. Make a streaming request
    // Set the stream parameter to true
    const stream = await client.chat.completions.create({
        messages: [
            {
                role: "user",
                content: "Write a short poem about the starry sky",
            },
        ],
        stream: true,
    });

    // 3. Process the streaming response
    // Iterate through the event stream and print the content
    process.stdout.write("AI: ");
    for await (const chunk of stream) {
        process.stdout.write(chunk.choices[0]?.delta?.content || "");
    }
    process.stdout.write("\n"); // Newline at the end
}

main();

Key Parameters

  • baseURL: Set to https://chat-proxy.bitseek.ai/v1
  • apiKey: Your valid API key for authentication
  • stream: true: Enables SSE streaming response

results matching ""

    No results matching ""