aijavascript3612
Perchance AI Text-to-Image Generator (100% Native API - No Puppeteer)
Scraper resmi 100% nembak cluster server Perchance (image-generation.perchance.org) tanpa browser/Puppeteer menggunakan verifikasi userKey.
Vamz Spectre26 Okt 2026249 baris kode
Jalankan via Terminal / CLI:
# 1. Download file script
curl -sL "https://code.vamxapi.my.id/snippet/raw/perchance-image" -o perchance-image.js
# 2. Jalankan script
node perchance-image.js
Panduan Penggunaan:
curl -sL "https://code.vamxapi.my.id/snippet/raw/perchance-image" -o perchance-image.js && node perchance-image.js "A futuristic cyberpunk samurai in Tokyo" "YOUR_USER_KEY"
perchance-image.js(249 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
/**
* Scraper: Perchance AI Text-to-Image Generator (100% Official API - No Puppeteer)
* Author: Vamz Spectre (vamxapi.my.id)
* Description: Scraper murni 100% nembak cluster server resmi Perchance (image-generation.perchance.org) tanpa browser headless / Puppeteer. Menggunakan TLS Chrome Impersonation agar tidak terkena Cloudflare 403.
*
* Usage:
* curl -sL "https://code.vamxapi.my.id/snippet/raw/perchance-image" -o perchance-image.js
* node perchance-image.js "A futuristic cyberpunk samurai in Tokyo neon rain, 8k" "USER_KEY_KAMU"
*/
const fs = require('fs');
const path = require('path');
const os = require('os');
const { execSync } = require('child_process');
const KEY_PATHS = [
path.join(process.cwd(), '.perchance_user_key.txt'),
path.join(os.homedir(), '.perchance_user_key.txt')
];
/**
* Baca userKey dari argumen, env, atau file cache
*/
function resolveUserKey(explicitKey) {
if (explicitKey && typeof explicitKey === 'string' && /^[a-f0-9]{64}$/i.test(explicitKey.trim())) {
return explicitKey.trim();
}
if (process.env.PERCHANCE_USER_KEY && /^[a-f0-9]{64}$/i.test(process.env.PERCHANCE_USER_KEY.trim())) {
return process.env.PERCHANCE_USER_KEY.trim();
}
for (const p of KEY_PATHS) {
try {
if (fs.existsSync(p)) {
const k = fs.readFileSync(p, 'utf8').trim();
if (/^[a-f0-9]{64}$/i.test(k)) return k;
}
} catch (_) {}
}
return null;
}
/**
* Simpan userKey ke disk untuk penggunaan berikutnya
*/
function saveUserKey(key) {
try {
if (key && /^[a-f0-9]{64}$/i.test(key.trim())) {
fs.writeFileSync(KEY_PATHS[1], key.trim(), 'utf8');
return true;
}
} catch (_) {}
return false;
}
/**
* Generate gambar 100% murni nembak cluster Perchance via TLS Impersonation (No Puppeteer)
* @param {string} prompt
* @param {Object} options
* @returns {Promise<Object>}
*/
async function generatePerchanceImage(prompt, options = {}) {
if (!prompt || typeof prompt !== 'string') {
throw new Error('Prompt deskripsi gambar wajib disertakan.');
}
const userKey = resolveUserKey(options.userKey);
if (!userKey) {
throw new Error(
'userKey wajib disertakan untuk nembak server resmi Perchance 100% tanpa Puppeteer.\n' +
'Cara dapatkan userKey (di tab Network):\n' +
'1. Buka https://perchance.org/ai-text-to-image-generator di browser HP / PC.\n' +
'2. Tekan F12 > Tab Network > filter: generate\n' +
'3. Klik tombol Generate di web.\n' +
'4. Klik request generate?... lalu salin parameter userKey (64 karakter hex).\n' +
' Catatan: Pastikan yang disalin adalah userKey, bukan adAccessCode!\n' +
'5. Jalankan: node perchance-image.js "prompt kamu" "USER_KEY_KAMU"'
);
}
if (options.userKey) {
saveUserKey(options.userKey);
}
const shape = options.shape || 'square';
const resolutions = {
square: '512x512',
portrait: '512x768',
landscape: '768x512'
};
const resolution = resolutions[shape] || resolutions.square;
const negativePrompt = options.negativePrompt || '';
const guidanceScale = options.guidanceScale || 7.0;
const seed = options.seed === undefined ? -1 : options.seed;
// Eksekusi direct TLS request via python curl_cffi (bypass Cloudflare TLS 403 tanpa butuh browser)
const pyScript = `
import json
import secrets
import random
from curl_cffi import requests
user_key = "${user_key}"
prompt = """${prompt.replace(/"/g, '\\"')}"""
negative_prompt = """${negativePrompt.replace(/"/g, '\\"')}"""
resolution = "${resolution}"
guidance_scale = float(${guidanceScale})
seed = int(${seed})
# 1. Ambil ad access code resmi
cache_bust = int(random.random() * 100000)
ad_res = requests.get(
f"https://perchance.org/api/getAccessCodeForAdPoweredStuff?__cacheBust={cache_bust}",
impersonate="chrome124",
headers={
"Referer": "https://perchance.org/ai-text-to-image-generator",
"Origin": "https://perchance.org"
},
timeout=15
)
ad_code = ad_res.text.strip() if ad_res.status_code == 200 else secrets.token_hex(32)
# 2. Generate image ke cluster Perchance
req_id = f"0.{secrets.randbits(30)}"
params = {
"userKey": user_key,
"requestId": req_id,
"adAccessCode": ad_code,
"__cacheBust": random.random()
}
body = {
"prompt": prompt,
"negativePrompt": negative_prompt,
"seed": seed,
"resolution": resolution,
"guidanceScale": guidance_scale,
"channel": "ai-text-to-image-generator",
"subChannel": "public",
"userKey": user_key,
"adAccessCode": ad_code,
"requestId": req_id
}
r = requests.post(
"https://image-generation.perchance.org/api/generate",
params=params,
json=body,
impersonate="chrome124",
headers={
"Referer": "https://image-generation.perchance.org/embed",
"Origin": "https://image-generation.perchance.org",
"Content-Type": "application/json"
},
timeout=60
)
if r.status_code != 200:
print(json.dumps({"error": f"HTTP {r.status_code} - {r.text[:200]}"}))
exit(0)
try:
data = r.json()
except Exception:
print(json.dumps({"error": f"Invalid JSON response: {r.text[:200]}"}))
exit(0)
if data.get("status") == "invalid_key":
print(json.dumps({"error": "userKey tidak valid atau sudah kedaluwarsa di server Perchance."}))
exit(0)
if data.get("status") != "success":
print(json.dumps({"error": f"Perchance error: {data.get('status', 'unknown')}"}))
exit(0)
# Resolve download
dl_url = ""
if data.get("imageDownloadUrl"):
dl_url = data["imageDownloadUrl"] if data["imageDownloadUrl"].startswith("http") else f"https://image-generation.perchance.org{data['imageDownloadUrl']}"
elif data.get("imageId"):
dl_url = f"https://image-generation.perchance.org/api/downloadTemporaryImage?imageId={data['imageId']}"
print(json.dumps({
"success": True,
"data": {
"server": "https://image-generation.perchance.org (Official Native)",
"prompt": data.get("prompt", prompt),
"negativePrompt": data.get("negativePrompt", negative_prompt),
"resolution": f"{data.get('width', 512)}x{data.get('height', 512)}",
"seed": data.get("seed"),
"guidanceScale": data.get("guidanceScale", guidance_scale),
"imageId": data.get("imageId"),
"imageUrl": dl_url,
"format": data.get("fileExtension", "jpeg")
}
}))
`;
let outputRaw;
try {
outputRaw = execSync(`python3 -c '${pyScript}'`, {
encoding: 'utf8',
timeout: 70000,
stdio: ['pipe', 'pipe', 'pipe']
});
} catch (e) {
throw new Error(`Gagal eksekusi request Perchance: ${e.message}`);
}
let parsed;
try {
parsed = JSON.parse(outputRaw.trim());
} catch (_) {
throw new Error(`Respons tidak valid dari runner: ${outputRaw.slice(0, 150)}`);
}
if (parsed.error) {
throw new Error(parsed.error);
}
return {
status: true,
creator: 'Vamz Spectre',
result: parsed.data
};
}
module.exports = {
generatePerchanceImage,
saveUserKey,
resolveUserKey
};
// CLI Runner
if (require.main === module) {
const promptInput = process.argv[2] || 'A futuristic cyberpunk samurai standing on a skyscraper in Tokyo, 8k, hyperrealistic';
const userKeyInput = process.argv[3] || '';
const shapeInput = process.argv[4] || 'square'; // square | portrait | landscape
generatePerchanceImage(promptInput, { userKey: userKeyInput, shape: shapeInput })
.then(res => console.log(JSON.stringify(res, null, 2)))
.catch(err => {
console.error(JSON.stringify({
status: false,
creator: 'Vamz Spectre',
error: err.message || 'Gagal mengeksekusi Perchance Image'
}, null, 2));
process.exit(1);
});
}