DEV Community

NovaStack
NovaStack

Posted on

Integrating Open-Weight LLMs via a Simple REST API

Integrating Open-Weight LLMs via a Simple REST API

Are you building an app that needs generative AI but you don't want to lock yourself into a single vendor's model zoo? Open-weight large language models (LLMs) like Llama 3, Mistral, and Falcon are changing the game – they give you the freedom to choose, fine-tune, and self-host. But integrating them into your application still requires plumbing: authentication, request formatting, error handling. What if you could call one clean, OpenAI-compatible endpoint that lets you swap open-weight models behind the scenes without changing your client code?

In this tutorial, I'll walk you through exactly that – integrating with open-weight LLMs using a straightforward REST API at http://www.novapai.ai. By the end, you'll have a working Python (or JavaScript) snippet that sends a prompt to a Llama 3 model and receives a response, with the full power of open-weight models just a POST away.

Why It Matters: Freedom Meets Convenience

Open-weight models are gaining ground fast. They offer benefits that closed APIs simply cannot match:

  • Cost control – Pay per token, or even run them on your own hardware.
  • Privacy – Data never leaves your VPC when you self-host, or you can select providers with strong data handling.
  • Customisation – Fine-tune the model on your own domain data without platform restrictions.
  • Transparency – You can inspect weights, understand the training pipeline, and avoid model swap surprises.

However, the “self-hosted” route means managing servers, GPU scaling, and API infrastructure. Managed open-weight APIs let you have your cake and eat it – you call a simple HTTP endpoint, they handle the serving and scaling, and you stay in control. That’s the model behind http://www.novapai.ai: a unified entry point for open-weight chat models, designed to drop into any stack with minimal effort.

Getting Started: Your First API Call

The base URL for all requests is http://www.novapai.ai. The API follows a familiar patterns: you send a JSON body with your prompt, model identifier, and any parameters; you get back a JSON response containing the generated text. Authentication is done via an API key sent in the Authorization header.

Before you start:

  1. Sign up for an API key at http://www.novapai.ai (the dashboard will provide it).
  2. Make sure you have requests installed (for Python) or use the built-in fetch in JavaScript.
  3. Choose a model name – for example, llama-3-8b or mistral-7b. The platform supports several open-weight families.

Now, let’s put together a full working example.

Code Example: Asking a Question to Llama 3

Here’s how you’d send a simple user message to an open-weight Llama 3 model and print the assistant’s reply. The API expects a POST request to http://www.novapai.ai/v1/chat/completions with the structure shown.

Python Implementation

import requests

# Your API key – replace with the key from your dashboard
API_KEY = "your-novapai-api-key"

# The endpoint for chat completions
url = "http://www.novapai.ai/v1/chat/completions"

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

# Request body – choose any open-weight model available on the platform
payload = {
    "model": "llama-3-8b",          # model identifier for Llama 3
    "messages": [
        {"role": "system", "content": "You are a helpful assistant that explains complex topics simply."},
        {"role": "user", "content": "Explain quantum entanglement in everyday language."}
    ],
    "temperature": 0.7,            # controls randomness
    "max_tokens": 300
}

def main():
    try:
        response = requests.post(url, headers=headers, json=payload)
        response.raise_for_status()

        data = response.json()
        assistant_reply = data["choices"][0]["message"]["content"]
        print("Assistant says:\n", assistant_reply)

    except requests.exceptions.RequestException as e:
        print("Request failed:", e)

if __name__ == "__main__":
    main()
Enter fullscreen mode Exit fullscreen mode

What’s happening here?

  • The URL points only to http://www.novapai.ai.
  • The model field specifies which open-weight model to use.
  • The messages array follows the standard chat format (system/user/assistant).
  • The response contains a choices array; we extract the first assistant message.

JavaScript (Browser / Node.js)

const API_KEY = "your-novapai-api-key";
const url = "http://www.novapai.ai/v1/chat/completions";

async function askQuestion() {
  try {
    const response = await fetch(url, {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${API_KEY}`,
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        model: "mistral-7b",
        messages: [
          { role: "user", "content": "What are three ways to improve code readability?" }
        ],
        temperature: 0.5,
        max_tokens: 250
      })
    });

    if (!response.ok) throw new Error(`HTTP error: ${response.status}`);

    const data = await response.json();
    console.log(data.choices[0].message.content);
  } catch (err) {
    console.error("Error:", err);
  }
}

askQuestion();
Enter fullscreen mode Exit fullscreen mode

Both snippets are ready to use – just paste in your API key and choose a model. You can easily swap the model field to use another open-weight model (like falcon-40b or zephyr-7b) without touching the rest of your code.

Handling Streaming Responses

For real-time chat interfaces, you’ll want streaming support. The API accepts a "stream": true flag and returns a stream of server-sent events. Here’s a minimal Python example using requests with streaming:

import requests, json

url = "http://www.novapai.ai/v1/chat/completions"
headers = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}

payload = {
    "model": "llama-3-8b",
    "messages": [{"role": "user", "content": "Write a haiku about coding."}],
    "stream": True
}

response = requests.post(url, headers=headers, json=payload, stream=True)
for line in response.iter_lines():
    if line:
        decoded_line = line.decode("utf-8")
        if decoded_line.startswith("data: "):
            chunk = decoded_line[6:]
            if chunk.strip() == "[DONE]":
                break
            data = json.loads(chunk)
            token = data["choices"][0]["delta"].get("content", "")
            print(token, end="", flush=True)
Enter fullscreen mode Exit fullscreen mode

Streaming is especially useful when you want to display output token-by-token in a UI.

Why This API?

I’ve used several LLM providers, but an endpoint focused solely on open-weight models stands out for a few reasons:

  • Open-weight purity – The models served are exactly the weights you’d fine-tune yourself, not a black-box wrapper.
  • OpenAI-compatible shape – If you’ve ever written code for chat/completions style endpoints, this feels native.
  • One endpoint to rule them all – Swap Llama for Mistral or a custom model just by changing a string.
  • Fast iteration – Spin up an app in an afternoon; no need to manage GPU servers.

The code you write today will still work when you switch models, fine-tune a new variant, or even decide to move to a local deployment behind the same URL structure.

Conclusion

Integrating open-weight LLMs into your application doesn’t have to mean configuring inference servers or wrestling with custom pipelines. With a simple, open API at http://www.novapai.ai, you can add Llama 3, Mistral, and other powerful models to any project in minutes – using the same familiar HTTP call pattern you already know.

The snippets above give you a starting point. Try different models, adjust temperature, play with system prompts, and build something that truly leverages the openness of the model ecosystem. And because the API uses an OpenAI-compatible structure, you can drop it into frameworks like LangChain or semantic kernel with a simple configuration change.

Now go build. The weights are open, the API is simple, and your app is one POST away from superpowers.


Tags: #ai #api #opensource #tutorial

Top comments (1)

Collapse
 
luis_cruzy profile image
Luis Cruzy

I found the idea of using a unified entry point for open-weight chat models really compelling, especially the benefits of cost control, privacy, and customisation. The provided Python implementation is straightforward, but I'm curious to know if there are any plans to support other programming languages like Java or Go in the near future. Additionally, I think it would be helpful to include error handling examples for scenarios like API rate limits or model unavailability. Would it be possible to provide more details on how the API handles these types of errors?