███╗ ██╗██╗██╗ ██╗ ██████╗ ██╗ ██╗
████╗ ██║██║╚██╗ ██╔╝██╔═══██╗╚██╗██╔╝
██╔██╗ ██║██║ ╚████╔╝ ██║ ██║ ╚███╔╝
██║╚██╗██║██║ ╚██╔╝ ██║ ██║ ██╔██╗
██║ ╚████║██║ ██║ ╚██████╔╝██╔╝ ██╗
╚═╝ ╚═══╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
NiyoX is a full-featured AI SDK and CLI that wraps the NiyoX AI REST API. Chat with AI from your terminal, Node.js server, or browser — with optional MongoDB persistence and multi-turn conversation memory built in.
The package ships three layers you can use independently:
NiyoXClient— thin HTTP wrapper around the REST API, with in-memory historyNiyoXStorage— optional MongoDB persistence layer for messages, prefs, and statsNiyoXAI— high-level class combining both, plus the interactive CLI
Install · CLI · Node.js · Browser · MongoDB Storage · API Reference · Development
# Global — gives you the niyox command everywhere
npm install -g niyox
# Local — use in your project
npm install niyoxRequires Node.js ≥ 18 (uses native
fetch). On older Node, installnode-fetchand it will be picked up automatically.
Launch the interactive REPL:
niyoxOne-shot question — get the answer and exit:
niyox "what is the speed of light?"
niyox "explain async/await in JavaScript"Flags:
niyox --version # print version (alias: -v)
niyox --help # show banner + command reference (alias: -h) ╭──────────────────────────────────────────────────────────╮
│ │
│ ✦ NIYOX AI v0.0.1 │
│ Powered by DanuZz · @niyox │
│ │
│ ◇ Commands │
│ │
│ › /help → show all commands │
│ › /new → fresh conversation thread │
│ › /history → in-memory chat log │
│ › /stats → usage stats (MongoDB) │
│ › /convs → stored conversation list │
│ › /mongo → enable persistent storage │
│ › /user <id> → set your user ID │
│ › /clear → clear the screen │
│ › /version → show version │
│ › /exit → quit (Ctrl+C also works) │
│ │
╰──────────────────────────────────────────────────────────╯
AI responses render in a colour-framed box with inline syntax highlighting, markdown-style headers and bold, and a live response-time badge. Your MongoDB preference (
/mongo) is remembered between sessions viaconf.
const { NiyoXAI } = require("niyox");
const ai = new NiyoXAI();
const { result, responseTime } = await ai.chat("Tell me something interesting.");
console.log(result); // → "Did you know that honey never spoils…"
console.log(responseTime + "ms");import { NiyoXAI } from "niyox";
const ai = new NiyoXAI({ userId: "alice" });
const res = await ai.ask("Explain quantum entanglement.");
console.log(res.result);const ai = new NiyoXAI();
await ai.chat("My name is Bob.");
const r = await ai.chat("What is my name?");
console.log(r.result); // → remembers "Bob" via conversationId
ai.newConversation(); // reset thread + in-memory historyconst { NiyoXClient } = require("niyox");
const client = new NiyoXClient({ sessionId: "my-session", timeout: 15000 });
const res = await client.chat("Hello!");
console.log(res.result);
console.log(client.getHistory()); // array of { role, content, timestamp }The SDK ships a self-contained browser client at html/index.html. You can also inline the NiyoXAI.Client class directly — it uses the native browser fetch with no build step needed.
<script>
// Paste the NiyoXAI browser class from html/index.html, then:
const ai = new NiyoXAI.Client();
const res = await ai.chat("Hello!");
console.log(res.result);
console.log(res.responseTime + "ms");
</script>Open
html/index.htmlfor a fully styled dark-theme chat UI — zero dependencies, zero bundler.
Browser client API mirrors the Node.js NiyoXClient:
const ai = new NiyoXAI.Client({ sessionId: "browser-tab" });
await ai.chat("First message");
await ai.chat("Second message"); // same conversationId reused
ai.newConversation(); // clear thread
const history = ai.getHistory(); // [{ role, content, ts, ms? }, …]Storage is completely optional — the SDK works fully offline without it. Opt in with one call.
const { NiyoXAI } = require("niyox");
const ai = new NiyoXAI({ userId: "alice" });
await ai.enableStorage(); // connects to the NiyoX cloud MongoDB
// every subsequent chat() call is automatically persisted
const res = await ai.chat("Hello!");
// retrieve full message history for a conversation
const msgs = await ai.getPersistentHistory(res.conversationId);
// list all stored conversation IDs for this user
const ids = await ai.listConversations();
// delete a conversation
const deleted = await ai.deleteConversation(ids[0]);
// usage statistics
const stats = await ai.getStats();
// { totalMessages: 42, totalConversations: 7, avgResponseTimeMs: "834" }
// per-user key/value preferences
await ai.setPref("language", "en");
const lang = await ai.getPref("language", "en"); // second arg = default
// graceful shutdown (closes MongoDB connection)
await ai.close();CLI shortcut: type
/mongoinside the REPL — the preference is saved and reconnects automatically on the next launch.
const { NiyoXStorage } = require("niyox");
const store = new NiyoXStorage("bob");
await store.connect(); // store.enabled === true
await store.saveTurn({
conversationId: "abc-123",
userMessage: "Hi!",
assistantMessage: "Hello, Bob!",
responseTime: 412,
});
const turns = await store.getConversation("abc-123");
await store.disconnect();| Option | Type | Default | Description |
|---|---|---|---|
userId |
string |
"anonymous" |
MongoDB user identifier |
sessionId |
string |
"default" |
API session ID passed to the REST endpoint |
conversationId |
string |
null |
Resume an existing conversation thread |
timeout |
number |
30000 |
Request timeout in milliseconds |
| Method | Returns | Description |
|---|---|---|
chat(message) |
Promise<Response> |
Send a message; auto-persists if storage is enabled |
ask(message) |
Promise<Response> |
Alias for chat() |
enableStorage(userId?) |
Promise<this> |
Connect to MongoDB and enable persistence |
newConversation() |
void |
Reset conversationId and clear in-memory history |
getHistory() |
Turn[] |
Returns a copy of the in-memory history for this session |
getPersistentHistory(convId?) |
Promise<Turn[]> |
Load stored turns from MongoDB |
listConversations() |
Promise<string[]> |
All conversation IDs stored for this user |
deleteConversation(id) |
Promise<number> |
Delete a conversation; returns deleted message count |
getStats() |
Promise<Stats | null> |
Usage statistics (requires storage) |
setPref(key, value) |
Promise<void> |
Persist a user preference in MongoDB |
getPref(key, default?) |
Promise<any> |
Retrieve a user preference |
close() |
Promise<void> |
Gracefully close the MongoDB connection |
Same as NiyoXAI options. Direct methods: chat(message), ask(message), newConversation(), getHistory().
{
result: string // AI reply text
conversationId: string // thread ID — reused automatically in subsequent calls
sessionId: string
responseTime: number // milliseconds
attempts: number
}| Method | Description |
|---|---|
connect(userId?) |
Connect to MongoDB; sets enabled = true |
saveTurn({ conversationId, userMessage, assistantMessage, responseTime }) |
Persist a full user+assistant turn |
saveMessage({ conversationId, role, content, responseTime? }) |
Persist a single message |
getConversation(conversationId) |
All messages for a conversation, sorted oldest-first |
listConversations() |
All distinct conversation IDs for this user |
deleteConversation(id) |
Delete all messages in a conversation |
setPref(key, value) / getPref(key, default?) |
Key/value user preferences |
getStats() |
{ totalMessages, totalConversations, avgResponseTimeMs } |
disconnect() |
Close the MongoDB connection |
All storage methods are no-ops (returning
null,[],0, orundefined) whenenabledisfalse, so you never need to guard calls yourself.
git clone https://github.com/dnuzi/niyox
cd niyox
npm install
# Build lib/index.cjs and lib/index.mjs from src/
node scripts/build.js
# Run the test suite
npm test
# With coverage report
npx jest --coverage --forceExitProject layout:
niyox/
├── bin/
│ └── cli.js # CLI entry point (--version, --help, REPL, one-shot)
├── src/
│ ├── client.js # NiyoXClient — HTTP wrapper + in-memory history
│ └── storage.js # NiyoXStorage — MongoDB persistence layer
├── lib/ # auto-generated by scripts/build.js
│ ├── index.cjs # CommonJS bundle (NiyoXAI + NiyoXClient + NiyoXStorage)
│ └── index.mjs # ESM re-export wrapper
├── html/
│ └── index.html # standalone browser chat UI
├── test/
│ ├── client.test.js # NiyoXClient unit tests (fetch-mocked)
│ ├── sdk.test.js # NiyoXAI + NiyoXStorage integration tests
│ └── cli.test.js # CLI binary smoke tests
└── scripts/
└── build.js # assembles lib/ from src/
Expected test output:
PASS test/client.test.js
PASS test/sdk.test.js
PASS test/cli.test.js
Tests: 28 passed, 28 total
Coverage: statements 94% | branches 88% | functions 100%

