#Response in POST Request -Failed to convert text. 401 Unauthorized
1 messages · Page 1 of 1 (latest)
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.
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
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.
That is what I had did, print the response.status and status text
or are you talking about something else?
If so, how could i log the response body?
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?
so just print response.json 😅
yep, I believe this does have API access though correct?
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.
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.
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}`
}
}
],
};
} ```