#Response in POST Request -Failed to convert text. 401 Unauthorized

1 messages · Page 1 of 1 (latest)

royal mortar
#

For context, I am using VoiceFlow, hence the code structure.

#


        const response = await fetch(`https://api.elevenlabs.io/v1/text-to-speech/${VoiceID}`, options);

        if (!response.ok) {
            return {
                outputVars: {
                    error: `Error: Failed to convert text. Status: ${response.status} ${response.statusText}`
                },
                next: {
                    path: 'error'
                },
                trace: [
                    {
                        type: 'debug',
                        payload: {
                            message: `Error: Failed to convert text. Status: ${response.status} ${response.statusText}`
                        }
                    }
                ],
            };
        }

the main problem arises in this part of the code

#

This is a POST request

#

My main issue

#

Ive checked the API key and voiceID that I use and its correct. Ive even tried changing my API keys and still the issue arises.

royal mortar
#

I do believe this is related to the body of my POST request

#

I have referred to documentation multiple times, including the FAQ above aswell

void cradle
#

The easiest way to know what the problem is will be to log the response body when the API call is unsuccessful. It will contain the error detail.

royal mortar
#

or are you talking about something else?

#

If so, how could i log the response body?

void cradle
#

The actual response body. Like if the API call is successful the body is the bytes to an mp3 file. But if it’s not successful it will contain the error detail in json format.

#

Are you using a free account?

royal mortar
royal mortar
void cradle
#

Yes, but there are IP restrictions to prevent abuse. If multiple free accounts use the same IP address that IP gets blocked from free usage.

I’m not familiar with VoiceFlow but if the API call is being made by one of their IPs rather than your own then that is probably the issue. Any service that makes the API calls on their servers usually don’t work with a free account since other free accounts have already used their IP.

royal mortar
#

Thanks for letting me know, how can I print the error json?

#

@void cradle my bad but currently having issues with this as this is stated to not be a function for some reason.

void cradle
#

What is not a function?

#

You can also use response.text() if don’t need to parse the json

        const response = await fetch(`https://api.elevenlabs.io/v1/text-to-speech/${VoiceID}`, options);

        if (!response.ok) {
            const responseBody = await response.text();
            return {
                outputVars: {
                    error: `Error: Failed to convert text. Status: ${response.status} ${response.statusText}, Details: ${responseBody}`
                },
                next: {
                    path: 'error'
                },
                trace: [
                    {
                        type: 'debug',
                        payload: {
                            message: `Error: Failed to convert text. Status: ${response.status} ${response.statusText}, Details: ${responseBody}`
                        }
                    }
                ],
            };
        } ```
royal mortar
#

Is this an endpoint related issue? the endpoint I am currently using renders this issue

#

"Method not allowed"

#

dont know why