How to format 'Post' for Elevenlabs.api (Text to speech api)

I would like to use POST with to create a voice from a text file. I don’t know how to format the request. I got stuck on the Headers, never mind that I can’t figure out how to format the body. I get confused by where to put or remove characters like : and ’ . Basically, what goes where and how to format it.

The API is here: Text to Speech - ElevenLabs

curl -X 'POST' \
  '<voice-id>' \
  --header 'accept: audio/mpeg' \
  --header 'xi-api-key: <xi-api-key>' \
  --header 'Content-Type: application/json' \
  --data '{
    "text": "string",
    "model_id": "eleven_monolingual_v1",
    "voice_settings": {
      "stability": 0.5,
      "similarity_boost": 0.5

And here is as far as I got:

Any guidance much appreciated!

Hi Nicolai,

Good to see that you trying to work with HTTP requests! as soon as you get the hang of it you will love it.

The start could be though as there are many things to double, triple check…

Let’s start from the top!

Your URL should refer to a specific voice-id as that is mentioned in the example. Unfortunately for you, “matilda” is the name and not the ID. i do believe : XrExE9yKIg1WjnnlVkGX is the correct ID for Matilda. So please change “matilda” for “XrExE9yKIg1WjnnlVkGX”, and remove the apostrophes.

This is also the reason the output is an invalid http token.


Remove the : as you do not need those. those will be added by the AP system. The rest seems to look fine.

Paste this in your Body part including the opening and closing brackets:

“text”: “PUT YOUR TEXT HERE!!!”,
“model_id”: “eleven_monolingual_v1”,
“voice_settings”: {
“stability”: 0.5,
“similarity_boost”: 0.5

I do think this should resolve your issue. Let me know how this worked out!

1 Like

Wow, thanks for the amazing response.
I got this error on the body: “Body is not a valid JSON object.”


Getting closer! Any ideas on that error?
I can definitely see the power in getting this to work. Thanks again Bram.

Hi @Nicolai

I’ve taken a look at the JSON body you’re working with, and I think I’ve spotted the issue. It seems the JSON structure is missing a closing curly brace.

Here’s the corrected format:

  "text": "PUT YOUR TEXT HERE!!!",
  "model_id": "eleven_monolingual_v1",
  "voice_settings": {
    "stability": 0.5,
    "similarity_boost": 0.5
1 Like

@Dennis is right, keep in mind to always close what you opened with the same character.

I think this should sovle the issue

1 Like

Another issue might be that @Nicolai copied your JSON, which appears to use typographic quotes which are curly and are not valid in JSON.

JSON requires the use of straight quotes.

vs "

Didn’t even notice this at first :sweat_smile:

Yes, thank you both!
Fixing both the typographic quotes (learned a new term today) and the closing curly brace got rid of the “…not a valid JSON object error”

That allowed me to submit the POST. Now I have some new errors to fix, but this time from the API response itself. Almost there.

{"headers":{"normalizedNames":{},"lazyUpdate":null},"status":500,"statusText":"OK","url":"","ok":false,"name":"HttpErrorResponse","message":"Http failure response for 500 OK","error":{"statusCode":500,"code":"22P05","error":"Internal Server Error","message":"unsupported Unicode escape sequence"}}

Well, that’s one step closer at least :sweat_smile:

The message “unsupported Unicode escape sequence” suggests there might be an issue with the way characters are being encoded or interpreted by the server.

To pinpoint the issue, I suggest simplifying your data. Before diving deep, let’s start by simplifying the data you’re sending. Instead of the dynamic data, try sending a very basic JSON with a single word, like:

  "text": "test"
1 Like

Ok. Done. I think I got the same response:

  "headers": {
    "normalizedNames": {},
    "lazyUpdate": null
  "status": 500,
  "statusText": "OK",
  "url": "",
  "ok": false,
  "name": "HttpErrorResponse",
  "message": "Http failure response for 500 OK",
  "error": {
    "statusCode": 500,
    "code": "22P05",
    "error": "Internal Server Error",
    "message": "unsupported Unicode escape sequence"

Could you try removing the colons in your header keys?

If there are any in the POST, they are not in my setup:

Interesting development…I went to my ElevenLabs account to check the error log History and the expected MP3 file was actually created, so the POST actually succeeded, despite the error report.

Now I need to figure out if I can get the url of the created file from the API. I imagine that should have been in the response instead of the error message.

1 Like