Proxy AI API Request
Sending anonymous requests to any AI providers API over Anyone socks5 proxy using npm
npm install @anyone-protocol/anyone-clientconst { 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();
Last updated