Sylvatica.

Back to Library

DeepAI

js 1/27/2026
20
const crypto = require('crypto');
const axios = require('axios');
const FormData = require('form-data');

function getApiKey() {
    const prefix = 'tryit';
    const id = Math.floor(1e10 + Math.random() * 9e10).toString();
    const hash = crypto.randomBytes(16).toString('hex');
    return `${prefix}-${id}-${hash}`;
}

function cleanResponse(text) {
    if (!text) return '';
    let cleaned = text.replace(/[\/\\]/g, '');
    cleaned = cleaned.replace(/\n\s*\n/g, '\n\n');
    cleaned = cleaned.replace(/([^\n])\n([^\n])/g, '$1 $2');
    cleaned = cleaned.replace(/([^`])\s{2,}([^`])/g, '$1 $2');
    return cleaned.trim();
}

function formatCodeBlocks(text) {
    return text.replace(/```(\w+)?\s*([^`]+)```/g, (match, lang, code) => {
        const cleanedCode = code.replace(/\s{2,}/g, ' ');
        return `\`\`\`${lang || ''}\n${cleanedCode}\n\`\`\``;
    });
}

async function deepai(input) {
    try {
        const form = new FormData();
        form.append('chat_style', 'chat');
        form.append('chatHistory', JSON.stringify([{ role: 'user', content: input }]));
        form.append('model', 'standard');
        form.append('hacker_is_stinky', 'very_stinky');

        const headers = {
            ...form.getHeaders(),
            'api-key': getApiKey(),
            'User-Agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Mobile Safari/537.36',
            'sec-ch-ua': '"Not)A;Brand";v="8", "Chromium";v="138", "Google Chrome";v="138"',
            'sec-ch-ua-platform': '"Android"',
            'Accept': '*/*',
            'Origin': 'https://deepai.org',
            'Referer': 'https://deepai.org/'
        };

        const res = await axios.post('https://api.deepai.org/hacking_is_a_serious_crime', form, { 
            headers,
            timeout: 30000 
        });

        let rawResponse = '';
        if (res.data?.output) rawResponse = res.data.output;
        else if (res.data?.text) rawResponse = res.data.text;
        else if (typeof res.data === 'string') rawResponse = res.data;

        if (!rawResponse) throw new Error("No response from DeepAI");

        let cleaned = cleanResponse(rawResponse);
        cleaned = formatCodeBlocks(cleaned);
        
        return cleaned;

    } catch (error) {
        throw new Error(error.message);
    }
}

module.exports = { deepai };