aijavascript4012
NaxaChat AI Client & Scraper (Guest & Sessions)
Scraper dan client API lengkap untuk NaxaChat (naxachat.com). Mendukung mode Guest (tanpa login) dan mode Sessions (Supabase Auth token) dengan multi-turn chat memory, pemilihan model AI (GPT-4.1 mini / Gemini), persona, dan deteksi limit kuota.
Vamz Spectre24 Okt 2026333 baris kode
Jalankan via Terminal / CLI:
# 1. Download file script
curl -sL "https://code.vamxapi.my.id/snippet/raw/naxachat-scraper" -o naxachat-scraper.js
# 2. Jalankan script
node naxachat-scraper.js
Dependencies npm yang Dibutuhkan:
npm install none (zero-dependency native Node.js)Panduan Penggunaan:
Cara Penggunaan:
1. Download script:
curl -sL "https://code.vamxapi.my.id/snippet/raw/naxachat-scraper" -o naxachat-scraper.js
2. Eksekusi via terminal:
# Mode Guest (tanpa token):
node naxachat-scraper.js "Halo, siapa kamu?"
# Mode Session (menggunakan session token Supabase):
node naxachat-scraper.js --session "YOUR_ACCESS_TOKEN" "Halo"
# Cek daftar model AI yang tersedia:
node naxachat-scraper.js --models
3. Integrasi Kode (Module / Script):
const { naxaChat, NaxaChatSession, getModels } = require("./naxachat-scraper.js");
// Single-shot chat (Guest)
const res = await naxaChat("Ceritakan lelucon pendek");
console.log(res.reply);
// Stateful multi-turn session
const session = new NaxaChatSession({ session: "OPTIONAL_TOKEN" });
const r1 = await session.chat("Namaku Budi");
const r2 = await session.chat("Siapa namaku?");
console.log(r2.reply);naxachat-scraper.js(333 lines)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
/**
* ========================================================
* Name: NaxaChat Scraper & API Client (Guest & Sessions)
*
* Cara Download:
* curl -sL "https://code.vamxapi.my.id/snippet/raw/naxachat-scraper" -o naxachat-scraper.js
*
* Cara Eksekusi:
* node naxachat-scraper.js "Halo, siapa kamu?"
* node naxachat-scraper.js --session "YOUR_TOKEN" "Halo"
* node naxachat-scraper.js --models
*
* Author: Vamz Spectre
* Source: https://vamxapi.my.id
* ========================================================
*/
const NAXA_BASE_URL = "https://www.naxachat.com";
const DEFAULT_USER_AGENT =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36";
/**
* Mengambil daftar model AI yang tersedia di NaxaChat
* @param {object} options
* @returns {Promise<object>}
*/
async function getModels(options = {}) {
const timeoutMs = options.timeout || 10000;
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeoutMs);
try {
const res = await fetch(`${NAXA_BASE_URL}/api/chat/models`, {
method: "GET",
headers: {
"User-Agent": DEFAULT_USER_AGENT,
Referer: `${NAXA_BASE_URL}/`,
Accept: "application/json",
},
signal: controller.signal,
});
clearTimeout(timer);
if (!res.ok) {
throw new Error(`Gagal mengambil model AI (HTTP ${res.status})`);
}
const data = await res.json();
return {
status: true,
defaultModel: data.defaultModel || "azure",
models: data.models || [],
};
} catch (err) {
clearTimeout(timer);
return {
status: false,
error: err.message,
};
}
}
/**
* Mengirim pesan ke NaxaChat (Mendukung mode Guest maupun Session)
* @param {string|object} input Pesan teks atau konfigurasi objek
* @param {object} [options] Konfigurasi tambahan
* @returns {Promise<object>}
*/
async function naxaChat(input, options = {}) {
let prompt = "";
let config = {};
if (typeof input === "string") {
prompt = input.trim();
config = { ...options };
} else if (typeof input === "object" && input !== null) {
prompt = (input.prompt || input.message || input.text || "").trim();
config = { ...input, ...options };
}
if (!prompt && (!config.history || config.history.length === 0)) {
throw new Error("Pesan atau riwayat percakapan tidak boleh kosong.");
}
const sessionToken = config.session || config.token || config.accessToken || null;
const model = config.model || config.chatModel || "azure";
const conversationMode = config.conversationMode || "chat"; // 'chat' | 'roleplay'
const replyMode = config.replyMode || "text"; // 'text' | 'voice'
const personaId = config.personaId || null;
const chatId = config.chatId || null;
const timeoutMs = config.timeout || 60000;
// Format pesan ke dalam history
let history = Array.isArray(config.history) ? [...config.history] : [];
if (prompt) {
history.push({
role: "user",
content: prompt,
});
}
const payload = {
history,
chatId,
personaId,
memoryEnabled: Boolean(config.memoryEnabled),
imageMode: null,
imageQuality: null,
referenceImage: null,
imageMetadata: null,
image: null,
imagePath: null,
replyMode,
conversationMode,
chatModel: model,
};
const headers = {
"Content-Type": "application/json",
"User-Agent": DEFAULT_USER_AGENT,
Referer: `${NAXA_BASE_URL}/`,
Origin: NAXA_BASE_URL,
Accept: "text/plain, text/event-stream, */*",
};
if (sessionToken) {
headers["Authorization"] = sessionToken.startsWith("Bearer ")
? sessionToken
: `Bearer ${sessionToken}`;
}
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), timeoutMs);
try {
const res = await fetch(`${NAXA_BASE_URL}/api/chat`, {
method: "POST",
headers,
body: JSON.stringify(payload),
signal: controller.signal,
});
clearTimeout(timer);
const contentType = res.headers.get("content-type") || "";
const tier = res.headers.get("x-naxa-tier") || (sessionToken ? "User" : "Guest");
const chatModelUsed = res.headers.get("x-naxa-chat-model") || model;
const usageUsed = res.headers.get("x-naxa-usage-used");
const usageLimit = res.headers.get("x-naxa-usage-limit");
const requestId = res.headers.get("x-naxa-request-id");
if (!res.ok) {
let errData = {};
try {
errData = await res.json();
} catch {
const text = await res.text();
errData = { error: text || `HTTP ${res.status}` };
}
const isGuestLimit = errData.code === "GUEST_LIMIT_REACHED" || res.status === 429;
return {
status: false,
statusCode: res.status,
code: errData.code || "REQUEST_FAILED",
error: errData.error || "Gagal memproses permintaan chat.",
tier,
used: errData.used || usageUsed || null,
limit: errData.limit || usageLimit || null,
resetsAt: errData.resetsAt || null,
hint: isGuestLimit
? "Kuota Guest pada IP ini telah habis. Gunakan parameter 'session' (Supabase session token) untuk akses tanpa batas."
: undefined,
};
}
let replyText = "";
if (contentType.includes("application/json")) {
const jsonRes = await res.json();
replyText = jsonRes.text || jsonRes.content || JSON.stringify(jsonRes);
} else {
replyText = await res.text();
}
return {
status: true,
mode: sessionToken ? "session" : "guest",
model: chatModelUsed,
tier,
usage: {
used: usageUsed ? parseInt(usageUsed, 10) : null,
limit: usageLimit ? parseInt(usageLimit, 10) : null,
},
requestId: requestId || null,
reply: replyText.trim(),
history: [
...history,
{
role: "assistant",
content: replyText.trim(),
},
],
};
} catch (err) {
clearTimeout(timer);
return {
status: false,
error: err.name === "AbortError" ? "Request timeout ke server NaxaChat." : err.message,
};
}
}
/**
* Class Session Stateful untuk memelihara obrolan multi-turn / chat beruntun
*/
class NaxaChatSession {
/**
* @param {object} [options]
*/
constructor(options = {}) {
this.sessionToken = options.session || options.token || null;
this.model = options.model || "azure";
this.personaId = options.personaId || null;
this.conversationMode = options.conversationMode || "chat";
this.history = Array.isArray(options.history) ? [...options.history] : [];
this.tier = null;
this.lastUsage = null;
}
/**
* Kirim pesan baru dalam sesi percakapan saat ini
* @param {string} message Pesan yang dikirim
* @param {object} [customOptions]
*/
async chat(message, customOptions = {}) {
const res = await naxaChat(message, {
session: this.sessionToken,
model: this.model,
personaId: this.personaId,
conversationMode: this.conversationMode,
history: this.history,
...customOptions,
});
if (res.status && res.history) {
this.history = res.history;
this.tier = res.tier;
this.lastUsage = res.usage;
}
return res;
}
/**
* Mengambil seluruh riwayat obrolan dalam sesi
*/
getHistory() {
return this.history;
}
/**
* Reset riwayat percakapan sesi
*/
clear() {
this.history = [];
}
}
// Module export
if (typeof module !== "undefined" && module.exports) {
module.exports = {
naxaChat,
getModels,
NaxaChatSession,
};
}
// CLI Runner
if (require.main === module) {
(async () => {
const args = process.argv.slice(2);
if (args.length === 0 || args.includes("-h") || args.includes("--help")) {
console.log(`
NaxaChat Scraper & Client CLI
-----------------------------
Penggunaan:
node naxachat-scraper.js "<pesan>"
node naxachat-scraper.js --session "<token>" "<pesan>"
node naxachat-scraper.js --models
Contoh:
node naxachat-scraper.js "Halo, siapa kamu?"
node naxachat-scraper.js --models
`);
return;
}
if (args.includes("--models") || args.includes("-m")) {
const models = await getModels();
console.log(JSON.stringify(models, null, 2));
return;
}
let sessionToken = null;
let model = "azure";
let messageParts = [];
for (let i = 0; i < args.length; i++) {
if (args[i] === "--session" || args[i] === "-s") {
sessionToken = args[++i];
} else if (args[i] === "--model") {
model = args[++i];
} else {
messageParts.push(args[i]);
}
}
const message = messageParts.join(" ").trim();
if (!message) {
console.error(JSON.stringify({ status: false, error: "Pesan tidak boleh kosong." }, null, 2));
process.exit(1);
}
const result = await naxaChat(message, {
session: sessionToken,
model,
});
console.log(JSON.stringify(result, null, 2));
})();
}