# Proxy AI API Request

{% tabs %}
{% tab title="JavaScript" %}

1. Install the anyone-client [npm](https://www.npmjs.com/package/@anyone-protocol/anyone-client) package:

{% code overflow="wrap" %}

```bash
npm install @anyone-protocol/anyone-client
```

{% endcode %}

2. 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';`&#x20;
   2. `const PROVIDER_API_KEY = 'PROVIDER_API_KEY';`
   3. `const MODEL = 'asi1-mini';`
   4. `const MESSAGE = 'Hello Anyone!';`

{% code expandable="true" %}

```js
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();
```

{% endcode %}

3. Run the script: `node sendrequest.js`

<figure><img src="https://3545050655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FAA9P3lN6X0LnMGWCOpyt%2Fuploads%2F4SUobDIGL8k27038TiMx%2FAI%20API%20proxy.png?alt=media&#x26;token=dc4bb38e-a38c-43c4-bb8c-6327936933d5" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}
