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
| Level | Project | Description |
|---|---|---|
| Beginner | Q&A Bot | Terminal chatbot for a specific topic. |
| Beginner | Image Captioner | Upload image, show AI description. |
| Intermediate | Study Helper | Paste notes, get summaries + quizzes. |
| Intermediate | Photo Organizer | Scan folder of images, auto-tag each one. |
| Advanced | Web Study Platform | Full-stack app with auth, chat, uploads. |
| Advanced | Content Moderator | Analyze text and images for safety. |
Troubleshooting
| Problem | Solution |
|---|---|
ModuleNotFoundError | Run pip install requests python-dotenv |
| 401 Unauthorized | Check API key in .env. |
| Connection refused | Verify base URL is correct. |
| Image upload fails | Resize to under 1 MB. |
| Slow responses | Normal: 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."