Proxy AI API Request

Sending anonymous requests to any AI providers API over Anyone socks5 proxy using npm

  1. Install the anyone-client npmarrow-up-right package:

npm install @anyone-protocol/anyone-client
  1. Save the code to file sendrequest.js and edit highlighted const variables to match your API.

    1. const API_URL = 'https://inference.asicloud.cudos.org/v1/chat/completions';

    2. const PROVIDER_API_KEY = 'PROVIDER_API_KEY';

    3. const MODEL = 'asi1-mini';

    4. const MESSAGE = 'Hello Anyone!';

const { Process, Socks } = require('@anyone-protocol/anyone-client');

async function main() {
    try {
        // Start the anyone-client proxy
        const anon = new Process({ displayLog: false, socksPort: 9050 });
        const socks = new Socks(anon);
        await anon.start();

        const API_URL = 'https://inference.asicloud.cudos.org/v1/chat/completions';
        const PROVIDER_API_KEY = 'PROVIDER_API_KEY';
        const MODEL = 'asi1-mini';
        const MESSAGE = 'Hello Anyone!';

        // Create the JSON payload
        const payload = {
            model: MODEL,
            messages: [
                {
                    role: 'user',
                    content: MESSAGE,
                },
            ],
        };

        // Set up the API request headers
        const headers = {
            Authorization: `Bearer ${PROVIDER_API_KEY}`,
            'Content-Type': 'application/json',
        };

        // Make the request
        const response = await socks.post(API_URL, payload, { headers });
        console.log(`\nSending: ${payload.content, ( MESSAGE )}`);

        // Extract and log the response
        console.log(`\nResponse: ${JSON.stringify(response.data.choices[0].message.content, null, 2)}\n`);

        // Stop the anyone-client proxy
        await anon.stop();

    } catch (error) {
        console.error('Error:', error);
    }
}

main();
  1. Run the script: node sendrequest.js

Last updated