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

chatgptfree

copy ajh.

Note

copy ajh.

Creator

qrtz

Language

python

Views

3

Copies

2

Base

https://chatgptfree.ai

Updated

22 Jun 2026

#ai

Code

32
chatgptfree.py
import json, uuid, time, sys, argparse, codecs
from curl_cffi import requests

BASE = "https://chatgptfree.ai"
AJAX = f"{BASE}/wp-admin/admin-ajax.php"
CREATOR = "rynaqrtz"

MODELS = {
    "chatgpt":    {"bot_id": 25871, "name": "ChatGPT 5 Nano"},
    "gemini":     {"bot_id": 25874, "name": "Gemini"},
    "deepseek":   {"bot_id": 25873, "name": "DeepSeek"},
    "claude":     {"bot_id": 25875, "name": "Claude"},
    "grok":       {"bot_id": 25872, "name": "Xai (Grok)"},
    "perplexity": {"bot_id": 29624, "name": "Perplexity Sonar"},
    "llama":      {"bot_id": 25870, "name": "Meta: Llama 4 Maverick"},
    "qwen":       {"bot_id": 25869, "name": "Qwen 3 30B A3B"},
}

def get_session():
    s = requests.Session()
    s.get(f"{BASE}/chat/", impersonate="chrome124")
    return s

def get_nonce(session):
    r = session.post(AJAX, data={
        "action": "aipkit_get_frontend_chat_nonce",
        "bot_id": "25871",
        "post_id": "261"
    }, impersonate="chrome124", headers={"Referer": f"{BASE}/chat/"})
    return r.json()["data"]["nonce"]

def iter_sse_lines(response):
    decoder = codecs.getincrementaldecoder('utf-8')()
    buffer = ""
    for chunk in response.iter_content(chunk_size=1):
        text = decoder.decode(chunk)
        if text:
            buffer += text
            while '\n' in buffer:
                line, buffer = buffer.split('\n', 1)
                yield line

def chat(prompt, model="chatgpt", stream=True):
    if model not in MODELS:
        return {"success": False, "error": f"Model '{model}' tidak valid. Pilih: {', '.join(MODELS.keys())}"}

    config = MODELS[model]
    session = get_session()
    nonce = get_nonce(session)

    session_uuid = str(uuid.uuid4())
    conv_uuid = str(uuid.uuid4())
    msg_id = str(uuid.uuid4())
    cache_key = str(uuid.uuid4())
    ts = str(int(time.time() * 1000))

    cache_data = {
        "action": "aipkit_cache_sse_message",
        "bot_id": config["bot_id"],
        "message": prompt,
        "_ajax_nonce": nonce,
        "post_id": "261",
        "user_client_message_id": msg_id,
        "cache_key": cache_key,
        "session_id": session_uuid,
        "conversation_uuid": conv_uuid,
        "_ts": ts,
    }

    cr = session.post(AJAX, data=cache_data, impersonate="chrome124",
                      headers={"Referer": f"{BASE}/chat/"})
    cache_result = cr.json()

    if not cache_result.get("success"):
        return {"success": False, "error": f"Cache failed: {cache_result}"}

    sse_cache_key = cache_result["data"]["cache_key"]

    stream_url = (
        f"{AJAX}?action=aipkit_frontend_chat_stream"
        f"&cache_key={sse_cache_key}"
        f"&bot_id={config['bot_id']}"
        f"&session_id={session_uuid}"
        f"&conversation_uuid={conv_uuid}"
        f"&post_id=261"
        f"&_ajax_nonce={nonce}"
        f"&_ts={ts}"
    )

    sr = session.get(stream_url, impersonate="chrome124", stream=True, headers={
        "Referer": f"{BASE}/chat/",
        "Accept": "text/event-stream",
        "X-Requested-With": "XMLHttpRequest",
    })

    full_text = ""
    last_error = None

    for line in iter_sse_lines(sr):
        if not line.strip() or line.startswith(":"):
            continue
        if line.startswith("data: "):
            data = line[6:]
            try:
                obj = json.loads(data)
                if "delta" in obj and obj["delta"]:
                    full_text += obj["delta"]
                    if stream:
                        print(obj["delta"], end="", flush=True)
                if "error" in obj and obj["error"]:
                    last_error = obj["error"]
                if "finished" in obj and obj.get("finished") == True:
                    break
            except json.JSONDecodeError:
                pass

    if stream:
        print()

    if last_error and not full_text:
        return {"success": False, "error": last_error, "creator": CREATOR}

    return {
        "success": True,
        "model": config["name"],
        "content": full_text,
        "creator": CREATOR,
    }

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=f"ChatGPT Free AI - {CREATOR}")
    parser.add_argument("prompt", nargs="*", help="Prompt")
    parser.add_argument("--model", "-m", default="chatgpt", help=f"Model ({', '.join(MODELS.keys())})")
    parser.add_argument("--json", "-j", action="store_true", help="Output JSON")
    parser.add_argument("--list-models", action="store_true", help="List models")
    parser.add_argument("--no-stream", action="store_true", help="Non-streaming")

    args = parser.parse_args()

    if args.list_models:
        print("Model yang tersedia:")
        for key, cfg in MODELS.items():
            print(f"  {key}: {cfg['name']}")
        sys.exit(0)

    if not args.prompt:
        parser.print_help()
        sys.exit(0)

    prompt = " ".join(args.prompt)
    result = chat(prompt, model=args.model, stream=not args.no_stream)

    if args.json:
        print(json.dumps(result, indent=2, ensure_ascii=False))

Rating

—(0)

Gimana snippet ini menurutmu?

</> Embed

Embed ke website / blog

<iframe src="https://qrtzcode.vercel.app/api/embed/ai/chatgptfree" 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