wolfyflutter

free gemini 2.5 flash no apikey

Aug 18th, 2025 (edited)
1,094
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 3.21 KB | Source Code | 0 0
  1. // by wolep
  2.  
  3. const gemini = {
  4.     getNewCookie: async function () {
  5.         const r = await fetch("https://gemini.google.com/_/BardChatUi/data/batchexecute?rpcids=maGuAc&source-path=%2F&bl=boq_assistant-bard-web-server_20250814.06_p1&f.sid=-7816331052118000090&hl=en-US&_reqid=173780&rt=c", {
  6.             "headers": {
  7.                 "content-type": "application/x-www-form-urlencoded;charset=UTF-8",
  8.             },
  9.             "body": "f.req=%5B%5B%5B%22maGuAc%22%2C%22%5B0%5D%22%2Cnull%2C%22generic%22%5D%5D%5D&",
  10.             "method": "POST"
  11.         });
  12.         console.log('get new cookie')
  13.         return r.headers.getSetCookie()[0].split("; ")[0]
  14.     },
  15.  
  16.     ask: async function (prompt, previousId = null) {
  17.         if (typeof (prompt) !== "string" || !prompt?.trim()?.length) throw Error(`mana prompt nya?`)
  18.         let resumeArray = null
  19.         let cookie = null
  20.         if (previousId) {
  21.             const s = atob(previousId)
  22.             const j = JSON.parse(s)
  23.             resumeArray = j.newResumeArray
  24.             cookie = j.cookie
  25.  
  26.         }
  27.         const headers = {
  28.             "content-type": "application/x-www-form-urlencoded;charset=UTF-8",
  29.             "x-goog-ext-525001261-jspb": "[1,null,null,null,\"9ec249fc9ad08861\",null,null,null,[4]]",
  30.             cookie: cookie || await this.getNewCookie()
  31.         }
  32.         const b = [[prompt], ["en-US"], resumeArray]
  33.         const a = [null, JSON.stringify(b)]
  34.         const obj = { "f.req": JSON.stringify(a) }
  35.         const body = new URLSearchParams(obj)
  36.         const response = await fetch(`https://gemini.google.com/_/BardChatUi/data/assistant.lamda.BardFrontendService/StreamGenerate?bl=boq_assistant-bard-web-server_20250729.06_p0&f.sid=4206607810970164620&hl=en-US&_reqid=2813378&rt=c`, {
  37.             headers,
  38.             body,
  39.             'method': 'post'
  40.         })
  41.         if (!response.ok) throw Error(`${response.status} ${response.statusText} ${await response.text() || `(body response kosong)`}`)
  42.         const data = await response.text()
  43.         const match = data.matchAll(/^\d+\n(.+?)\n/gm)
  44.         const array = Array.from(match).reverse()
  45.         const selectedArray = array[3][1]
  46.         const realArray = JSON.parse(selectedArray)
  47.         const parse1 = JSON.parse(realArray[0][2])
  48.         const newResumeArray = [...parse1[1], parse1[4][0][0]]
  49.         const text = parse1[4][0][1][0].replace(/\*\*(.+?)\*\*/g, `*$1*`)
  50.         const id = btoa(JSON.stringify({ newResumeArray, cookie: headers.cookie }))
  51.         const result = { text, id }
  52.         return result
  53.     }
  54.  
  55.  
  56. }
  57.  
  58.  
  59. // cara pakai
  60.  
  61.  
  62. gemini.ask('kenalin aku wolep')
  63.     .then(console.log)
  64.     .catch(err => { console.log(err.message) })
  65.  
  66. /* output
  67. {
  68.   text: 'Halo Wolep! Senang berkenalan denganmu. Ada yang bisa saya bantu?',
  69.   id: 'eyJuZXdSZXN1bWV....V4Rk5ydS1adjhRIn0='
  70. }
  71.  
  72. untuk resume cukup lampirkan id dari chat sebelumnya
  73.  
  74. gemini.ask('siapa namaku?', 'eyJuZXdSZXN1bWV....V4Rk5ydS1adjhRIn0=')
  75.     .then(console.log)
  76.     .catch(err => { console.log(err.message) })
  77.  
  78. output
  79. {
  80.   text: 'Kamu mengenalkan dirimu sebagai *Wolep*.',
  81.   id: 'eyJuZXdSZXN1bWV.....ItUTV4Rk5ydS1adjhRIn0=' <-- kalau mau resume lampirin lagi id baru ini
  82. }
  83.  
  84. dan lanjutkan
  85.  
  86. */
Tags: ai Gemini
Advertisement
Add Comment
Please, Sign In to add comment