Open Intelligence

Student Guide

Tutorials and project ideas for building with the API.

Prerequisites

  • Python 3.8+ or Node.js 18+
  • An API key from oi.bcworks.in.net
  • A code editor and terminal

Python Chatbot

bash
pip install requests python-dotenv

Create .env:

.env
OI_API_KEY=your_api_key_here
chatbot.py
import os, requests
from dotenv import load_dotenv

load_dotenv()
API_KEY = os.getenv("OI_API_KEY")
URL = "https://oiv1.bcworks.in.net/v1/chat/completions"

while True:
    q = input("\nYou: ")
    if q.lower() in ("quit", "exit"): break
    resp = requests.post(URL,
        headers={"Authorization": f"Bearer {API_KEY}"},
        json={"messages": [{"role": "user", "content": q}], "max_tokens": 150})
    if resp.ok:
        print("AI:", resp.json()["choices"][0]["message"]["content"])
    else:
        print("Error:", resp.status_code)

Image Analyzer

analyze.py
import os, base64, requests
from dotenv import load_dotenv

load_dotenv()
path = input("Image path: ")
mime = {"png":"png","jpg":"jpeg","jpeg":"jpeg","webp":"webp"}.get(path.rsplit(".",1)[-1].lower(),"jpeg")

with open(path, "rb") as f:
    img = base64.b64encode(f.read()).decode()

resp = requests.post("https://oiv1.bcworks.in.net/v1/chat/completions",
    headers={"Authorization": f"Bearer {os.getenv('OI_API_KEY')}"},
    json={"messages": [{"role":"user","content":"Describe this image in detail",
        "image": f"data:image/{mime};base64,{img}"}], "max_tokens": 200})
print(resp.json()["choices"][0]["message"]["content"])

JavaScript Chatbot

bash
npm install dotenv
chatbot.mjs
import "dotenv/config";
import * as readline from "readline";
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
const ask = p => new Promise(r => rl.question(p, r));

while (true) {
  const q = await ask("\nYou: ");
  if (q === "quit") { rl.close(); break; }
  const resp = await fetch("https://oiv1.bcworks.in.net/v1/chat/completions", {
    method: "POST",
    headers: { "Authorization": `Bearer ${process.env.OI_API_KEY}`, "Content-Type": "application/json" },
    body: JSON.stringify({ messages: [{ role: "user", content: q }], max_tokens: 150 })
  });
  const data = await resp.json();
  console.log("AI:", data.choices[0].message.content);
}

Project Ideas

LevelProjectDescription
BeginnerQ&A BotTerminal chatbot for a specific topic.
BeginnerImage CaptionerUpload image, show AI description.
IntermediateStudy HelperPaste notes, get summaries + quizzes.
IntermediatePhoto OrganizerScan folder of images, auto-tag each one.
AdvancedWeb Study PlatformFull-stack app with auth, chat, uploads.
AdvancedContent ModeratorAnalyze text and images for safety.

Troubleshooting

ProblemSolution
ModuleNotFoundErrorRun pip install requests python-dotenv
401 UnauthorizedCheck API key in .env.
Connection refusedVerify base URL is correct.
Image upload failsResize to under 1 MB.
Slow responsesNormal: text 1-3s, images 2-5s.

FAQ

Is this free?

Yes, free for all users including students.

Supported image formats?

JPEG, PNG, WebP. Max 10 MB; under 1 MB recommended.

Can I use it for class projects?

Yes. Cite as "Open Intelligence API by BC Works."