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

gpt4o

gpt4o amba free

Note

yh

Creator

qrtz

Language

javascript

Views

1

Copies

0

Base

https://api.overchat.ai

Updated

24 Jun 2026

#ai

Code

10
gpt4o.js
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";

const API = "https://api.overchat.ai/v1/chat/completions";
const SESSION_DIR = path.join(process.env.HOME, "overchat-sessions");
if (!fs.existsSync(SESSION_DIR)) fs.mkdirSync(SESSION_DIR, { recursive: true });

const UAS = [
  "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Mobile Safari/537.36",
  "Mozilla/5.0 (Linux; Android 14; Pixel 8 Pro) AppleWebKit/537.36 (KHTML, like Gecko) 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 (KHTML, like Gecko) Version/18.2 Mobile/15E148 Safari/604.1",
  "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36"
];

const LANGS = ["id","en","es","fr","de","ja","ko"];
const pick = arr => arr[Math.floor(Math.random() * arr.length)];
const sleep = ms => new Promise(r => setTimeout(r, ms));

function loadSession(name) {
  const file = path.join(SESSION_DIR, `${name || "default"}.json`);
  try { return JSON.parse(fs.readFileSync(file, "utf8")); }
  catch {
    const s = { chatId: crypto.randomUUID(), deviceId: crypto.randomUUID(), messages: [], model: "openai/gpt-4o" };
    fs.writeFileSync(file, JSON.stringify(s, null, 2));
    return s;
  }
}

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

async function chat(prompt, sessionName = null) {
  await sleep(200 + Math.random() * 600);

  const session = loadSession(sessionName);
  const messages = [
    ...session.messages.slice(-10),
    { id: crypto.randomUUID(), role: "user", content: prompt },
    { id: crypto.randomUUID(), role: "system", content: "Ikuti bahasa user dan jawab dengan gaya natural, singkat, dan jelas." }
  ];

  const res = await fetch(API, {
    method: "POST",
    headers: {
      "sec-ch-ua-platform": `"Android"`,
      "x-device-uuid": session.deviceId,
      "sec-ch-ua": `"Google Chrome";v="147", "Not.A/Brand";v="8", "Chromium";v="147"`,
      "sec-ch-ua-mobile": "?1",
      "x-device-language": pick(LANGS),
      "x-device-platform": "web",
      "x-device-version": "1.0.44",
      "user-agent": pick(UAS),
      accept: "*/*",
      "content-type": "application/json",
      origin: "https://overchat.ai",
      referer: "https://overchat.ai/",
      "accept-language": "id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7",
      priority: "u=1, i"
    },
    body: JSON.stringify({
      chatId: session.chatId,
      model: session.model || "openai/gpt-4o",
      messages,
      personaId: "gpt-4o-landing",
      frequency_penalty: 0,
      max_tokens: 4000,
      presence_penalty: 0,
      stream: true,
      temperature: 0.5,
      top_p: 0.95
    })
  });

  if (!res.ok) {
    const errText = await res.text().catch(() => "");
    return { creator: "rynaqrtz", status: false, code: res.status, model: "openai/gpt-4o", error: errText };
  }

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

  while (true) {
    const { value, done } = await reader.read();
    if (done) break;
    buf += decoder.decode(value, { stream: true });
    const lines = buf.split("\n");
    buf = lines.pop() || "";
    for (const rawLine of lines) {
      const line = rawLine.trim();
      if (!line.startsWith("data:")) continue;
      const data = line.slice(5).trim();
      if (!data || data === "[DONE]") continue;
      try {
        const json = JSON.parse(data);
        if (json.model) detectedModel = json.model;
        const content = json.choices?.[0]?.delta?.content;
        if (typeof content === "string") answer += content;
      } catch {}
    }
  }

  session.messages.push(
    { id: crypto.randomUUID(), role: "user", content: prompt },
    { id: crypto.randomUUID(), role: "assistant", content: answer }
  );
  if (session.messages.length > 20) session.messages = session.messages.slice(-20);
  if (detectedModel) session.model = detectedModel;
  saveSession(sessionName, session);

  return {
    creator: "rynaqrtz",
    status: true,
    model: detectedModel || session.model || "openai/gpt-4o",
    answer: answer.trim(),
    session: sessionName || "default"
  };
}

if (process.argv[1]?.includes("gpt4o")) {
  const args = process.argv.slice(2);
  if (!args[0]) {
    console.log(JSON.stringify({
      usage: {
        basic: 'node gpt4o.js "<prompt>"',
        with_memory: 'node gpt4o.js "<prompt>" <session_name>',
        example: 'node gpt4o.js "Nama saya Budi" budi'
      },
      model: "openai/gpt-4o",
      note: "Hanya GPT-4o yang berfungsi (model lain 403)",
      creator: "rynaqrtz"
    }, null, 2));
    process.exit(0);
  }
  const result = await chat(args[0], args[1] || null);
  console.log(JSON.stringify(result, null, 2));
}

Rating

—(0)

Gimana snippet ini menurutmu?

</> Embed

Embed ke website / blog

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

Related Snippets

claude haiku

claude haiku 4.5 ambafree

14
5

perplexity

yh.

2
0

unlimited eay

Ada ambabreaknya

2
0