How to Get Your ElevenLabs API Key (and Keep It Safe)

How to Get Your ElevenLabs API Key (and Keep It Safe)

Written by

in

Quick answer: Sign in to ElevenLabs, open your account settings, go to API Keys, click Create API key, name it, optionally restrict its permissions and credit usage, then copy it and store it safely — for example in a .env file as ELEVENLABS_API_KEY. Never put your key in browser code or public GitHub repositories.

Create an API key (step by step)

  1. Log in at elevenlabs.io.
  2. Open your account/developer settings and find API Keys.
  3. Click Create API key.
  4. Name it after the project.
  5. Set restrictions if available (endpoints, credit limits).
  6. Copy the key and save it securely.

API key security settings explained

SettingWhat it doesOur advice
Scope (endpoint) restrictionsLimits which API features the key can use. New keys start restricted — you choose what to enable.Enable only what your app needs (e.g. text to speech)
Credit quotaSets a maximum number of credits the key can spendAlways set one — it stops runaway costs
IP allowlistingOnly lets requests come from your serversEnterprise feature (in preview)
Service account keysKeys owned by the workspace, not a personUse for production so keys don’t break if someone leaves

From the official ElevenLabs API keys documentation, October 2026.

What happens if your key leaks on GitHub?

ElevenLabs says that if a key is committed to a public GitHub repository, it is automatically disabled to prevent misuse. To fix it, create (rotate) a new key, update your app and hosting settings, and remove the old key from your code history.

Store your key safely

ELEVENLABS_API_KEY=your_api_key_here
  • Add .env to .gitignore.
  • Use one key per project.
  • Call the API from your server, never the browser.
  • Revoke any leaked key immediately.

Test your key (Python)

pip install elevenlabs python-dotenv
import os
from dotenv import load_dotenv
from elevenlabs.client import ElevenLabs

load_dotenv()
client = ElevenLabs(api_key=os.getenv("ELEVENLABS_API_KEY"))
audio = client.text_to_speech.convert(
    voice_id="YOUR_VOICE_ID",
    model_id="eleven_v4",
    text="My API key works!",
)

Full walkthrough: ElevenLabs API for beginners.

Test your key with curl

All requests send the key in the xi-api-key header. A quick test that lists your account details:

curl https://api.elevenlabs.io/v1/user -H "xi-api-key: YOUR_API_KEY"

If you get your account data back, the key works. If you get a 401, the key is wrong or missing; a permission error means the key’s scope doesn’t include that endpoint.

Adding the key to your hosting

  • Vercel / Netlify: Project settings → Environment variables → add ELEVENLABS_API_KEY.
  • Docker: pass it with an env file, not inside the image.
  • Serverless functions: read it from the environment at runtime.
  • No-code tools (Zapier, Make): paste it into the connection settings — and set a credit quota on that key.

Common key errors

ErrorCauseFix
401Missing or wrong keyCheck the key and variable name
403 / permissionKey restrictedEdit key permissions
Quota exceededOut of credits or key limitRaise limit or upgrade
Works locally onlyEnv var missing on serverAdd it to your hosting settings

Personal keys vs service account keys

Personal keyService account key
Owned byOne userThe workspace
If the person leavesKey can stop workingKeeps working
Best forTesting and personal scriptsProduction apps and automations

How to rotate a key safely

  1. Create a new key with the same restrictions.
  2. Update the environment variable in every place your app runs.
  3. Deploy and check that requests work.
  4. Delete the old key.
  5. Repeat every few months, or immediately if a key may have leaked.

Is the API free?

The free plan includes API access with its monthly credits, but some features need a paid plan, and commercial use needs Starter or higher. Estimate usage with our credit calculator.

API key checklist for a new project

  1. Create a new key just for this project, with a clear name such as “blog-audio-production”.
  2. Limit permissions to the features the project needs, if your account allows it.
  3. Set a credit limit on the key so a bug cannot use your whole balance.
  4. Store it in an environment variable or your hosting provider’s secret settings.
  5. Add the .env file to .gitignore before your first commit.
  6. Test with one short request to confirm it works.
  7. Write down where the key is used so you can update it later.

Where to store keys on popular platforms

PlatformWhere to put the key
Local developmentA .env file loaded by your app (never committed)
Vercel or NetlifyProject settings, environment variables
WordPressA plugin setting or wp-config.php constant, never in theme files shown to visitors
Zapier or MakeThe app connection settings inside the automation tool
Mobile appsOn your own server, never inside the app itself

Signs your key may be compromised

  • Credit usage spikes when you are not generating anything.
  • Requests appear at unusual times in your usage history.
  • You find the key in a public repository, screenshot or shared document.
  • A teammate who had the key has left the project.

If you notice any of these, delete the key, create a new one and update your apps straight away.

Building with keys in a team

Give each environment (development, staging, production) its own key, and avoid sharing one personal key across a team. Service-style keys tied to a project are easier to manage and rotate than personal keys. Document who owns each key and review the list every few months, deleting anything no longer used.

Common beginner mistakes with API keys

  1. Pasting the key directly into code and then sharing the code on GitHub or in a forum.
  2. Using the key in front-end JavaScript, where anyone can see it in the browser.
  3. Sharing one key with friends or clients instead of creating separate keys.
  4. Never rotating keys, even after team changes.
  5. Ignoring usage alerts until the balance runs out.

Testing safely

When you test a new key, send a very short text, such as one sentence, and check that the audio file plays correctly. Then look at your usage page to confirm the characters were recorded as expected. Only after this small test should you connect the key to larger scripts, automations or live websites. This approach keeps costs low and makes it easy to spot setup problems early.

Good key habits take a few minutes to set up and can save you from surprise bills later.

Related guides

Frequently asked questions

Where is my ElevenLabs API key?

In account settings under API Keys. If lost, create a new one and delete the old.

Can I view my key again?

Keys may be shown only once — create a new key if needed.

Is it safe to share my key?

No, anyone with it can use your credits.

What header does the ElevenLabs API use?

The xi-api-key header. The official SDKs add it for you when you set ELEVENLABS_API_KEY.

Why does my new key get a permission error?

New keys start restricted. Edit the key and enable the endpoints your app needs.

Can I limit how much a key can spend?

Yes — set a credit quota on the key.

Final thoughts

One key per project, stored in .env, kept on the server and limited — and you’re ready to build.

ElevenLabsAIVoice.com is an independent guide and is not affiliated with ElevenLabs. Plans, prices and models change, so always check the official ElevenLabs website for the latest details.

About the author

Every guide on this site is researched against official sources and fact-checked before publishing. Read our editorial policy.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *