kyuurzy

Venice AI Chat

Oct 10th, 2025 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.91 KB | Source Code | 0 0
  1. // venice.js
  2. const fetch = require("node-fetch")
  3.  
  4. async function chatVeniceAI(prompt, modelId = "zai-org-glm-4.6") {
  5.     const url = 'https://outerface.venice.ai/api/inference/chat';
  6.    
  7.     const timestamp = new Date().toISOString().slice(0, 19) + '+08:00';
  8.     const requestId = Math.random().toString(36).substring(2, 10);
  9.     const conversationId = Math.random().toString(36).substring(2, 10).toUpperCase();
  10.    
  11.     const data = {
  12.         conversationId: conversationId,
  13.         characterId: "",
  14.         clientProcessingTime: 1618,
  15.         conversationType: "text",
  16.         includeVeniceSystemPrompt: true,
  17.         isCharacter: false,
  18.         modelId: modelId,
  19.         prompt: [{
  20.             content: prompt,
  21.             role: "user"
  22.         }],
  23.         reasoning: false,
  24.         requestId: requestId,
  25.         systemPrompt: "",
  26.         temperature: 0.7,
  27.         topP: 0.9,
  28.         userId: "user_anon_1234568910",
  29.         webEnabled: true,
  30.         webScrapeEnabled: false
  31.     };
  32.  
  33.     const headers = {
  34.         'Host': 'outerface.venice.ai',
  35.         'sec-ch-ua': '"Chromium";v="139", "Not;A=Brand";v="99"',
  36.         'x-venice-locale': 'en',
  37.         'sec-ch-ua-mobile': '?1',
  38.         'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Mobile Safari/537.36',
  39.         'content-type': 'application/json',
  40.         'x-venice-version': '[email protected]+b2d4cb6',
  41.         'x-venice-timestamp': timestamp,
  42.         'sec-ch-ua-platform': '"Android"',
  43.         'accept': '*/*',
  44.         'origin': 'https://venice.ai',
  45.         'sec-fetch-site': 'same-site',
  46.         'sec-fetch-mode': 'cors',
  47.         'sec-fetch-dest': 'empty',
  48.         'referer': 'https://venice.ai/',
  49.         'accept-encoding': 'gzip, deflate, br',
  50.         'accept-language': 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7'
  51.     };
  52.  
  53.     const response = await fetch(url, {
  54.         method: 'POST',
  55.         headers: headers,
  56.         body: JSON.stringify(data)
  57.     });
  58.  
  59.     if (!response.ok) {
  60.         const errorText = await response.text();
  61.         throw new Error(`HTTP ${response.status}: ${errorText}`);
  62.     }
  63.  
  64.     const reader = response.body.getReader();
  65.     const decoder = new TextDecoder();
  66.     let fullResponse = '';
  67.  
  68.     while (true) {
  69.         const { done, value } = await reader.read();
  70.         if (done) break;
  71.        
  72.         const chunk = decoder.decode(value);
  73.         const lines = chunk.split('\n');
  74.        
  75.         for (const line of lines) {
  76.             if (line.trim()) {
  77.                 try {
  78.                     const data = JSON.parse(line);
  79.                     if (data.kind === 'content' && data.content) {
  80.                         fullResponse += data.content;
  81.                     }
  82.                 } catch (e) {
  83.                     continue;
  84.                 }
  85.             }
  86.         }
  87.     }
  88.    
  89.     return { success: true, response: fullResponse };
  90. }
  91.  
Advertisement
Add Comment
Please, Sign In to add comment