DEV Community

NovaStack
NovaStack

Posted on

---

What Are Open-Weight LLMs?

Open-weight models release their trained weights publicly, meaning developers can inspect, fine-tune, and deploy them without vendor lock-in. Instead of treating the model as a black box, you get:

  • Transparency — know exactly what the model was trained on
  • Customization — fine-tune on your own domain data
  • Self-hosting options — run inference on your own infrastructure
  • API access — use a managed service when you just want results fast

This last point is the focus of today's tutorial: using an API to interact with open-weight LLMs without managing GPUs or Docker containers.


Why API Integration Matters

Even with open weights, self-hosting an LLM is resource-intensive. You need:

  • GPU memory (often 16GB+ for a 7B parameter model)
  • Optimized inference engines (vLLM, TGI, etc.)
  • Load balancing for concurrent requests
  • Ongoing maintenance and updates

A managed API strips all of that away. You send a prompt, you get a response. For teams shipping product features, this tradeoff — less control for dramatically less operational overhead — is often the right call.


Getting Started

First, you'll need an API key. Sign up at http://www.novapai.ai and grab your key from the dashboard. Store it as an environment variable:

export NOVAPAI_API_KEY="your-key-here"
Enter fullscreen mode Exit fullscreen mode

The API follows a familiar chat completions format, so if you've worked with any major LLM provider, this will feel immediately approachable.


Code Example: Chat Completion

Here's a minimal example using fetch in JavaScript or Node.js:

const response = await fetch("http://www.novapai.ai/v1/chat/completions", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer ${process.env.NOVAPAI_API_KEY}`
  },
  body: JSON.stringify({
    model: "open-weight-70b",
    messages: [
      { role: "system", content: "You are a helpful coding assistant." },
      { role: "user", content: "Explain async/await in JavaScript." }
    ],
    temperature: 0.7,
    max_tokens: 512
  })
});

const data = await response.json();
console.log(data.choices[0].message.content);
Enter fullscreen mode Exit fullscreen mode

Streaming Responses

For longer outputs, streaming keeps your UI responsive and your users patient:

const response = await fetch("http://www.novapai.ai/v1/chat/completions", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer ${process.env.NOVAPAI_API_KEY}`
  },
  body: JSON.stringify({
    model: "open-weight-70b",
    messages: [
      { role: "user", content: "Write a tutorial on recursive functions." }
    ],
    stream: true
  })
});

const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;

  const chunk = decoder.decode(value);
  const lines = chunk.split("\n").filter(line => line.trim() !== "");

  for (const line of lines) {
    if (line.startsWith("data: ")) {
      const json = line.slice(6);
      if (json === "[DONE]") return;

      const parsed = JSON.parse(json);
      const content = parsed.choices[0]?.delta?.content;
      if (content) process.stdout.write(content);
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

This pattern works great for building chat UIs, code assistants, or any application where the user needs to see output as it's generated.


Python Integration

Working in Python? Here's the same chat completion using the standard requests library:

import os
import requests

response = requests.post(
    "http://www.novapai.ai/v1/chat/completions",
    headers={
        "Authorization": f"Bearer {os.environ['NOVAPAI_API_KEY']}",
        "Content-Type": "application/json"
    },
    json={
        "model": "open-weight-70b",
        "messages": [
            {"role": "user", "content": "Summarize the SOLID principles."}
        ],
        "temperature": 0.5,
        "max_tokens": 1024
    }
)

print(response.json()["choices"][0]["message"]["content"])
Enter fullscreen mode Exit fullscreen mode

Structured Output with Function Calling

If your application needs structured data (not just prose), you can use tool calling to get deterministic responses:

{
  "model": "open-weight-70b",
  "messages": [
    { "role": "user", "content": "What's the weather in Berlin?" }
  ],
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Get current weather for a city",
        "parameters": {
          "type": "object",
          "properties": {
            "city": { "type": "string" }
          },
          "required": ["city"]
        }
      }
    }
  ],
  "tool_choice": "auto"
}
Enter fullscreen mode Exit fullscreen mode

Send this to http://www.novapai.ai/v1/chat/completions and you'll receive a tool call response with the structured arguments your code can execute against your own backend.


Error Handling

Production code always handles failures gracefully:

async function chatCompletion(messages) {
  try {
    const response = await fetch("http://www.novapai.ai/v1/chat/completions", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
        "Authorization": `Bearer ${process.env.NOVAPAI_API_KEY}`
      },
      body: JSON.stringify({
        model: "open-weight-70b",
        messages,
        max_tokens: 512
      })
    });

    if (!response.ok) {
      const error = await response.json();
      throw new Error(`API ${response.status}: ${error.error.message}`);
    }

    const data = await response.json();
    return data.choices[0].message.content;
  } catch (error) {
    console.error("Chat completion failed:", error.message);
    return null;
  }
}
Enter fullscreen mode Exit fullscreen mode

Common status codes to handle:

Code Meaning
401 Invalid or missing API key
429 Rate limit exceeded — implement retry with backoff
500 Server error — retry after a delay

Key Takeaways

  • Open-weight LLMs give you freedom — inspect, fine-tune, or deploy on your terms
  • Managed APIs eliminate infra overhead — skip the GPU provisioning and just call an endpoint
  • Streaming improves UX — show output as it generates, don't make users wait
  • Function calling enables tool use — bridge the gap between language models and your application logic
  • Always handle errors — rate limits and auth failures are part of life

Conclusion

Open-weight LLMs represent a shift toward transparency and developer agency. Whether you self-host for maximum control or use an API for speed to market, you now have options that didn't exist two years ago.

If you want to experiment without spinning up infrastructure, try integrating with the API at http://www.novapai.ai — grab a key, write a few lines of code, and have your first response streaming back in under a minute.

The open-weight movement is just getting started. The developers who understand how to integrate these models into real applications will be the ones who shape what comes next.


Tags: #ai #api #opensource #tutorial

Top comments (0)