qrtzcode
HomeDocsAPILeaderboardChangelog
Contribute
Docs

qrtzcode

Kumpulan gist & snippet pribadi — anime, AI tools, scraper, dan randomness.

Navigate

HomeDocsAPI Reference

Links

© 2026 qrtz. All snippets welcome.

ESC

Navigate

Links

AI

aichatting

gpt4o juga tapi supp vision rek

Note

yh.

Creator

qrtz

Language

javascript

Views

1

Copies

1

Base

https://api.overchat.ai

Updated

24 Jun 2026

#ai

Code

11
aichatting.js
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";

const API = "https://aga-api.aichatting.net/aigc/chat/v2/professional/stream";
const SESSION_DIR = path.join(process.env.HOME, "aichatting-sessions");
if (!fs.existsSync(SESSION_DIR)) fs.mkdirSync(SESSION_DIR, { recursive: true });

const UAS = [
  "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 Chrome/147.0.0.0 Mobile Safari/537.36",
  "Mozilla/5.0 (Linux; Android 14; Pixel 8 Pro) AppleWebKit/537.36 Chrome/149.0.0.0 Mobile Safari/537.36",
  "Mozilla/5.0 (iPhone; CPU iPhone OS 18_2 like Mac OS X) AppleWebKit/605.1.15 Version/18.2 Mobile/15E148 Safari/604.1",
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 Chrome/149.0.0.0 Safari/537.36",
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 14_7_1) AppleWebKit/605.1.15 Version/18.2 Safari/605.1.15",
  "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 Chrome/148.0.0.0 Safari/537.36"
];

const MODEL = "gpt-4o-mini";
const PUBLIC_KEY_B64 = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDCAdf/EyIbLBxjGqmh7qLU6/CPCzru+75+82OSPZ+nf4BFvg88drpZ6KigNW0J8TNgxe6Yms1irCZNVDyu+RXsl4y/7c2KOHc4OGTzHB5fUMiMasFUvcEs2P70e6yA/sKHZfBLG1XPhlb84Ibs3nhD3W5e2SuC+4EuVkaqzN08LQIDAQAB";

const pick = arr => arr[Math.floor(Math.random() * arr.length)];
const sleep = ms => new Promise(r => setTimeout(r, ms));

function getPublicKey() {
  const wrapped = PUBLIC_KEY_B64.match(/.{1,64}/g).join("\n");
  return `-----BEGIN PUBLIC KEY-----\n${wrapped}\n-----END PUBLIC KEY-----`;
}

function encryptVisitorId(id) {
  return crypto.publicEncrypt({ key: getPublicKey(), padding: crypto.constants.RSA_PKCS1_PADDING }, Buffer.from(id)).toString("base64");
}

function createVisitorId() { return crypto.randomBytes(16).toString("hex"); }
function createConvId() { return crypto.randomInt(10000000, 99999999); }

function loadSession(name) {
  const file = path.join(SESSION_DIR, `${name || "default"}.json`);
  try {
    const s = JSON.parse(fs.readFileSync(file, "utf8"));
    if (!s.visitorId) s.visitorId = createVisitorId();
    if (!s.vtoken) s.vtoken = encryptVisitorId(s.visitorId);
    if (!s.conversationId) s.conversationId = createConvId();
    if (!Array.isArray(s.messages)) s.messages = [];
    return s;
  } catch {
    const vid = createVisitorId();
    const s = { visitorId: vid, vtoken: encryptVisitorId(vid), conversationId: createConvId(), messages: [] };
    fs.writeFileSync(file, JSON.stringify(s, null, 2));
    return s;
  }
}

function saveSession(name, s) {
  fs.writeFileSync(path.join(SESSION_DIR, `${name || "default"}.json`), JSON.stringify(s, null, 2));
}

async function imageToDataUrl(url) {
  if (!url) return null;
  try {
    const r = await fetch(url, {
      headers: { "user-agent": pick(UAS), accept: "image/jpeg,image/png,image/webp,*/*;q=0.8" },
      signal: AbortSignal.timeout(15000)
    });
    if (!r.ok) return null;
    const ct = r.headers.get("content-type") || "image/jpeg";
    const buf = Buffer.from(await r.arrayBuffer());
    return `data:${ct};base64,${buf.toString("base64")}`;
  } catch { return null; }
}

function clean(t) {
  return (t || "").replace(/-=-\s*--/g, " ").replace(/--@DONE@--/g, "").replace(/\s+/g, " ").trim();
}

export async function chat(prompt, sessionName = null, imageUrl = null) {
  await sleep(100 + Math.random() * 500);
  const session = loadSession(sessionName);
  const content = [{ type: "text", text: prompt }];
  let hasVision = false;

  if (imageUrl) {
    const dataUrl = await imageToDataUrl(imageUrl);
    if (dataUrl) {
      content.push({ type: "image_url", image_url: { url: dataUrl } });
      hasVision = true;
    }
  }

  const messages = [...session.messages.slice(-10), { role: "user", content }];

  const res = await fetch(API, {
    method: "POST",
    headers: {
      "sec-ch-ua-platform": '"Android"',
      lang: "en",
      "sec-ch-ua": '"Google Chrome";v="147", "Not.A/Brand";v="8", "Chromium";v="147"',
      "sec-ch-ua-mobile": "?1",
      vtoken: session.vtoken,
      source: "web",
      "user-agent": pick(UAS),
      accept: "text/event-stream",
      "content-type": "application/json",
      origin: "https://www.aichatting.net",
      referer: "https://www.aichatting.net/",
      "sec-fetch-site": "same-site",
      "sec-fetch-mode": "cors",
      "sec-fetch-dest": "empty",
      "accept-language": "id-ID,id;q=0.9,en-US;q=0.8"
    },
    body: JSON.stringify({ spaceHandle: true, roleId: 0, messages, conversationId: session.conversationId, model: MODEL })
  });

  if (!res.ok || !res.body) return { creator: "rynaqrtz", status: false, code: res.status, model: MODEL, answer: "" };

  const reader = res.body.getReader();
  const decoder = new TextDecoder();
  let buf = "", answer = "";

  while (true) {
    const { value, done } = await reader.read();
    if (done) break;
    buf += decoder.decode(value, { stream: true });
    const lines = buf.split(/\r?\n/);
    buf = lines.pop() || "";
    for (const line of lines) {
      const l = line.trim();
      if (!l.startsWith("data:")) continue;
      const d = l.slice(5).trim();
      if (!d || d.includes("--@DONE@--")) continue;
      answer += d;
    }
  }

  answer = clean(answer);
  session.messages.push(
    { role: "user", content },
    { role: "assistant", content: [{ type: "text", text: answer }] }
  );
  if (session.messages.length > 20) session.messages = session.messages.slice(-20);
  saveSession(sessionName, session);

  return { creator: "rynaqrtz", status: true, model: MODEL, answer, vision: hasVision || undefined, session: sessionName || "default" };
}

if (process.argv[1]?.includes("aichatting")) {
  const [prompt, sessionName, imageUrl] = process.argv.slice(2);
  if (!prompt) {
    console.log(JSON.stringify({
      usage: "node aichatting.js \"<prompt>\" [session] [image_url]",
      examples: [
        'node aichatting.js "Yahoo><"',
        'node aichatting.js "Nama saya Ryna" Ryna',
        'node aichatting.js "Deskripsikan gambar ini" vis "https://example.com/img.jpg"'
      ],
      model: MODEL,
      features: "Chat + Vision + Memory + Rotating UA",
      creator: "rynaqrtz"
    }, null, 2));
    process.exit(0);
  }
  chat(prompt, sessionName || null, imageUrl || null).then(r => console.log(JSON.stringify(r, null, 2)));
}

Rating

—(0)

Gimana snippet ini menurutmu?

</> Embed

Embed ke website / blog

<iframe src="https://qrtzcode.vercel.app/api/embed/ai/aichatting" style="width:100%;height:400px;border:none;border-radius:12px;"></iframe>

Related Snippets

claude haiku

claude haiku 4.5 ambafree

14
5

qwen

Eay fav admin qwen😍

8
4

perplexity

yh.

2
0