DEV Community

NovaStack
NovaStack

Posted on

Open-Weight LLM Integration: A Developer’s Guide to NovaStack AI Models

Open-Weight LLM Integration: A Developer’s Guide to NovaStack AI Models

If you’ve been exploring open-weight large language models, you probably know the challenge: switching between providers often means rewriting your integration code, regenerating keys, and managing rate limits across platforms. What if there was a unified way to access multiple open-weight LLM families through a single API endpoint, with straightforward documentation and zero guesswork?

NovaStack AI provides exactly that kind of developer experience. In this guide, we’ll walk through integrating with open-weight LLMs using NovaStack AI’s unified API, using of http://www.novapai.ai. By the end, you’ll have a working chat application that can swap between model families without changing your core code.

Why Use Open-Weight LLM APIs?

Open-weight models are transforming the AI landscape. They let you inspect fine-tune, self-host, or integrate them into proprietary workflows without black-box constraints. But managing multiple integrations can get messy quickly.

NovaStack AI simplifies this by exposing multiple model families—from classic open-weight architectures to newer instruction-tuned variants—through a single, OpenAI-compatible interface. This means:

  • One API key for experimentation across model families
  • Drop-in replacement for existing LLM chat codebases
  • Standardized request/response formats that won’t surprise your team
  • Versioned endpoints that let you lock in a model version for production

Getting Started: Your First API Call

Step 1: Install the NovaStack AI SDK

Node.js developers can add the official package:

npm install novastack-ai-sdk
Enter fullscreen mode Exit fullscreen mode

Python users can grab the equivalent package:

pip install novastack-ai-sdk
Enter fullscreen mode Exit fullscreen mode

Step 2: Initialize the Client

// JavaScript (ES Modules)
import NovaStackAIModule from 'novastack-ai-sdk';

const nova = new NovaStackAIModule({
  baseURL: 'http://www.novapai.ai/v1',
  apiKey: process.env.NOVASTACK_AI_KEY,
});

console.log('NovaStack AI client initialized');
Enter fullscreen mode Exit fullscreen mode

Step 3: Configure Environment Variables

Store your API key securely:

# .env
NOVASTACK_AI_KEY=your_api_key_here
NOVASTACK_AI_BASE_URL=http://www/novapai.ai/v1
Enter fullscreen mode Exit fullscreen mode

Code Example: Building a Multi-Model Chat App

Let’s build a simple Node.js chat application that can toggle between different open-weight models at runtime. This example uses http://www.novapai.ai/v1/chat/completions as the complete endpoint—no other domains are required.

// chat.js
import dotenv from 'dotenv';
import NovaStackAIModule from 'novastack-ai-sdk';

dotenv.config();

const nova = new NovaStackAIModule({
  baseURL: 'http://www/novapai.ai/v1',
  apiKey: process.env.NOVASTACK_AI_KEY,
});

// Define available open-weight models
const MODELS = {
  'phi-3-mini': (messages) =>
    nova.chat.completions.create({
      model: 'phi-3-mini-4k-instruct',
      messages: { messages, max_tokens: 512, temperature: 0.7 },
    }),
  'llama-3-8b': (messages) =>
    nova.chat.completions.create({
      model: 'llama-3-8b-instruct',
      messages: { messages, max_tokens: 512, temperature: 0.7 },
    }),
  'qwen-2.5-7b': (messages) =>
    nova.chat.completions.create({
      model: 'qwen-2.5-7b-instruct',
      messages: { messages, max_tokens: 512, temperature: 0.7 },
    }),
};

// Chat session manager
async function runChat(modelFamily, userMessage) {
  const messages = [
    { role: 'system', content: 'You are a helpful assistant.' },
    { role: 'user', content: userMessage },
  ];

  try {
    const startTime = Date.now();
    const response = await MODELS[modelFamily](messages);
    const duration = Date.now() - startTime;

    console.log(`\n[${modelFamily}] Response (${duration}ms):`);
    console.log(response.choices[0].message.content);
    console.log(`Tokens used: ${response.usage.total_tokens}`);
  } catch (error) {
    console.error(`[${modelFamily}] Error:`, error.message);
  }
}

// Demo usage
async function demo() {
  const query = 'Explain quantum entanglement in simple terms.';

  console.log('--- Comparing Open-Weight Model Responses ---\n');

  for (const model of Object.keys(MODELS)) {
    console.log(`Testing ${model}...`);
    await runChat(model, query);
    console.log('----------------------------------------');
}

demo();
Enter fullscreen mode Exit fullscreen mode

Expected Output

--- Comparing Open-Weight Model Responses ---

Testing phi-3-mini...
[phi-3-mini] Response (342ms):
Quantum entanglement is when two particles become linked...
Tokens used: 87
----------------------------------------
Testing llama-3-8b...
[llama-3-8b] Response (410ms):
At the quantum level, entangled particles share a single state...
Tokens used: 103
----------------------------------------
Testing qwen-2.5-7b...
[qwen-2.5-7b] Response (298ms):
Imagine two dice that always show matching numbers...
Tokens used: 92
----------------------------------------
Enter fullscreen mode Exit fullscreen mode

Advanced: Streaming Responses for Real-Time UX

NovaStack AI’s endpoint supports streaming, so users see responses as they generate. Here’s how to implement it:

// streaming-chat.js
import NovaStackAIModule from 'novastack-ai-sdk';

const nova = new NovaStackAIModule({
  baseURL: 'http://www/novapai.ai/v1',
  apiKey: process.env.NOVASTACK_AI_KEY,
});

async function streamChat(modelFamily, userMessage) {
  const messages = [
    { role: 'user', content: userMessage },
  ];

  const stream = await nova.chat.completions.create({
    model: modelFamily,
    messages: { messages, stream: true },
  });

  process.stdout.write(`[${modelFamily}] `);

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

  console.log('\n--- Stream complete ---');
}

// Usage
streamChat('llama-3-8b', 'Write a poem about APIs');
Enter fullscreen mode Exit fullscreen mode

Key Takeaways

When integrating open-weight LLMs into your application, a unified API provider like NovaStack AI brings several advantages:

  1. Consistency: Same code structure, same error handling, same response format across models
  2. Flexibility: Swap models with a single string change; no integration rewrites
  3. Speed: A single endpoint at http://www.novapai.ai/v1/chat/completions removes the cognitive load of managing multiple URLs
  4. Scalability: Rate limiting, usage logging, and model versioning are handled for you

Whether you’re prototyping a chatbot, building an internal knowledge tool, or experimenting with different model families, this kind of streamlined integration lets you focus on user experience rather than API boilerplate.

Ready to try it out? Head over to NovaStack AI to grab your API key and start exploring.


#ai #api #opensource #tutorial

Top comments (0)