Elevenlabs Custom Node

Hello. I am trying to create an Elevenlabs custom node but for some reason I can not get it to work. I’ve used the Generate Code feature and I can still not get it to work. If someone is able to help me figure out why this is that would be amazing.

Hey @Conrad! If you’re reporting an issue with a flow or an error in a run, please include the run link and make sure it’s shareable so we can take a look.

  1. Find your run link on the history page. Format: https://www.gumloop.com/pipeline?run_id={your_run_id}&workbook_id={workbook_id}

  2. Make it shareable by clicking “Share” → ‘Anyone with the link can view’ in the top-left corner of the flow screen.
    GIF guide

  3. Provide details about the issue—more context helps us troubleshoot faster.

You can find your run history here: https://www.gumloop.com/history

Do you mind sharing the code / workflow or the error you get? Though be careful with sharing the custom node if there are any secrets. Please obfuscate them before sharing.

Adding to Shrikar’s point above, if you’re facing issues with code (not the workflow) you can paste them in the AI chat within the custom node builder and it’ll edit/fix the code for you.

I’ve tried doing this multiple times and it is still having the same problem. The code I am using is this:
def main(Text, params):
import requests
import base64
import os

# Get API key from environment variables 
api_key = os.environ.get("ELEVENLABS_API_KEY")

if not api_key:
    raise ValueError("ELEVENLABS_API_KEY environment variable not found")

# ElevenLabs API endpoint for Matt voice
url = "https://api.elevenlabs.io/v1/text-to-speech/7EWjcP6c0ab2URx0YprH"

# Request headers
headers = {
    "Accept": "audio/mpeg",
    "Content-Type": "application/json", 
    "xi-api-key": api_key
}

# Request body
data = {
    "text": Text,
    "model_id": "eleven_monolingual_v1",
    "voice_settings": {
        "stability": 0.5,
        "similarity_boost": 0.5
    }
}

try:
    # Make the API request
    response = requests.post(url, json=data, headers=headers)
    
    if response.status_code != 200:
        raise Exception(f"API request failed with status code {response.status_code}")

    # Convert audio data to base64
    audio_base64 = base64.b64encode(response.content).decode('utf-8')
    
    return audio_base64

except Exception as e:
    raise Exception(f"Error calling ElevenLabs API: {str(e)}")
return MP3

This is the error code I get:
e[31m Eleven Labs Failed!
Command exited with code 1 and error:
Traceback (most recent call last):
File “/index.py”, line 47, in
print(‘FUNCTION_OUTPUT\n’ + str(main(‘Hello, this is a test.’, {})))
File “/index.py”, line 10, in main
raise ValueError(“ELEVENLABS_API_KEY environment variable not found”)
ValueError: ELEVENLABS_API_KEY environment variable not found
e[0m

Ya you have to get the key from elevenlabs and use it there ELEVENLABS_API_KEY. @Wasay-Gumloop @rahul-gumloop do we have a better way to share the credentials that including it as a part of the Custom Node?

I have done that but I replaced it just so I could send the code.

This is the error code I get:
e[31m Eleven Labs Failed!
Command exited with code 1 and error:
Traceback (most recent call last):
File “/index.py”, line 47, in
print(‘FUNCTION_OUTPUT \n’ + str(main(‘Hello, this is a test.’, {})))
File “/index.py”, line 10, in main
raise ValueError(“ELEVENLABS_API_KEY environment variable not found”)
ValueError: ELEVENLABS_API_KEY environment variable not found
e[0m

There are no environment variables right now so you’d have to pass the API key as an input or param. OR you can add it directly in the code. Note that only the owner of the custom node can view/edit the code so your credentials would be safe.

Ya you have to get the key from elevenlabs and use it there ELEVENLABS_API_KEY. @Wasay-Gumloop @rahul-gumloop do we have a better way to share the credentials that including it as a part of the Custom Node?

Not as of now but we do plan on adding this via https://www.gumloop.com/settings/profile/credentials in the future.

Instead of the above you should probably do. The os.environ.get is something when you read from the environment and I don’t think you have setup environment variables.

api_key = “Key”

1 Like

Thanks for this. Elevenlabs is now receiving the text and converting it. For some reason it is not sending back the MP3 file. Sorry if I am missing something obvious. First time messing around with anything like this.

No worries. Custom node can’t actually output file objects as of now unless you upload the file using https://docs.gumloop.com/api-reference/file-operations/upload-file and then reference that as a file name within the flow.

The easiest option here would be to upload the file on an external service within the code like Amazon S3 and then output the file link.

Let me know if this works for you.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.