ElevenLabs API key setup: scopes, credit limits and where the key lives
Create an ElevenLabs API key, limit what it can reach and spend, keep it on your server as ELEVENLABS_API_KEY, and read the errors new apps hit first.
The short version
Create a key on the API Keys page of the ElevenLabs app (the developer quickstart links straight to elevenlabs.io/app/api/api-keys). While you create it, limit it to the endpoints your app actually calls and give it its own credit limit. Store it on your host as ELEVENLABS_API_KEY, which is the name ElevenLabs uses in its own quickstart, and send it only from server code in the xi-api-key header. Browsers never see it.
If part of your app has to talk to ElevenLabs straight from the browser, for example live transcription from the microphone, your server hands the browser a single-use token instead of the key.
Each key can carry its own limits
ElevenLabs lets you narrow a key in three ways, and all three are worth using for a key that lives on a production server. You can limit which API endpoints the key can access, so a key made for text to speech cannot also clone voices or manage your account. You can set a custom credit limit on the key, so one runaway feature or one leaked key cannot use up the whole plan. And you can restrict the key to specific IP addresses or CIDR ranges, between 1 and 100 entries, with requests from anywhere else rejected with a 403. Private IP ranges are not accepted, and IP lists only help when your host gives you a fixed outbound address.
Personal keys need a Full Seat in the workspace. On multi-seat plans, workspace admins can also create service accounts under Workspace settings, Service Accounts. A service account key keeps working when people join or leave the team, which makes it the better owner for a production key than any single person.
Create the key, step by step
- Sign in to ElevenLabs and open the API Keys page. On a team plan, decide first whether the key should belong to you or to a service account.
- Create a key named after the app and the environment, such as
myapp-prod. Restrict it to the endpoints the app uses and set a credit limit that matches what you expect to spend. - Copy the key once, straight into your host's variables as
ELEVENLABS_API_KEY. Make a second key for local development and keep it in a.envfile that git ignores. - Keep the voice ID and model ID in variables too, such as
ELEVENLABS_VOICE_IDandELEVENLABS_MODEL_ID, so changing either is a settings edit rather than a code change.
Call it from the server
The official Node package is @elevenlabs/elevenlabs-js and the Python package is elevenlabs. ElevenLabs' authentication page says plainly that the key is a secret and must not be exposed in any client-side code, browsers or apps. A small server route that checks the user and then calls ElevenLabs keeps it that way, and it is also where you add a per-user limit so one account cannot burn through your credits.
// app/api/speak/route.ts
import { ElevenLabsClient } from '@elevenlabs/elevenlabs-js'
const elevenlabs = new ElevenLabsClient({ apiKey: process.env.ELEVENLABS_API_KEY })
export async function POST(req: Request) {
// Check the session and a per-user limit here.
const { text } = await req.json()
const audio = await elevenlabs.textToSpeech.convert(process.env.ELEVENLABS_VOICE_ID!, {
text,
modelId: process.env.ELEVENLABS_MODEL_ID!,
outputFormat: 'mp3_44100_128',
})
return new Response(audio, { headers: { 'Content-Type': 'audio/mpeg' } })
}Browser features use single-use tokens
Some features feel better when the browser connects directly, such as realtime speech to text. For those, ElevenLabs documents single-use tokens: your server, holding the real key, asks for a token and passes it to the browser. A token expires after 15 minutes and is consumed when it is used. The documented token types today are realtime_scribe, batch_scribe and tts_websocket. Put the route that issues tokens behind your own login, or anyone on the internet can mint them on your account.
Free plan rules that matter for an app
The pricing page lists the Free plan at 10k credits per month, with the commercial license starting on the Starter plan. ElevenLabs' help centre is direct about it: the free plan has no commercial license and cannot be used for any commercial purpose, and anything you publish from it must credit ElevenLabs by putting elevenlabs.io or 11.ai in the title. All paid plans include a commercial license, except for content made with Beta Services. So if your app charges money or serves real customers, budget for a paid plan before launch, not after.
The errors you are most likely to see
Most first-day problems are one of these. The error names come from ElevenLabs' error reference and help centre.
| Error | What it means | What to do |
|---|---|---|
401 invalid_api_key | The key is wrong or was sent incorrectly | Check the header is spelled exactly xi-api-key and the variable holds the full key |
401 missing_api_key | No key reached ElevenLabs | The variable is empty on the host, often because it was added without a redeploy |
quota_exceeded or 402 insufficient_credits | Not enough credits for the request | Add credits or move up a plan, and check the key's own credit limit |
| 403 from an IP the key does not allow | The key is locked to an IP list and the request came from somewhere else | Add your host's fixed outbound IP to the key's list, or remove the IP restriction |
429 rate_limit_exceeded or concurrent_limit_exceeded | Too many requests, or too many at once | Retry with backoff and queue requests; higher plans allow more at once |
| Unusual activity detected. Free Tier usage disabled. | The free tier abuse check flagged your IP, often a shared VPN or office network | A paid plan is not affected; ElevenLabs says it cannot reverse the flag once set |
Set it on Railway or Vercel
On Railway, open your service, go to the Variables tab and add ELEVENLABS_API_KEY. Railway stages variable changes, so nothing happens until you review and deploy them. You can also seal the variable, which hides its value in the dashboard and the API while still passing it to deployments.
On Vercel, open the project, choose Environment Variables, add the name and value, pick Production (and Preview if you want it there) and save. Vercel's docs say changes only apply to new deployments, so redeploy afterwards. If the key still seems missing, the redeploy and scope checklist below covers the usual causes.
Never prefix the name with NEXT_PUBLIC_ or VITE_. Those prefixes exist to put values into browser code, which is the one place this key must not go.
If the key leaks
Rotate it the way ElevenLabs suggests: create a new key, switch your app over to it, then delete the old one. For a service account, create the replacement on the same service account. Then look at usage for the days the key was exposed. A per-key credit limit is what keeps a leak from becoming a large bill, which is one more reason to set it on day one.
What Shipyard does here
Shipyard's AI step writes keys for Anthropic, OpenAI and OpenRouter into your host today, on the server side only. It does not write ElevenLabs keys yet. To add voice to an app Shipyard set up, create the key as above and add ELEVENLABS_API_KEY to your Railway or Vercel project yourself, then redeploy. Everything else Shipyard configured keeps working as it is.
Sources
- ElevenLabs API reference: authenticationelevenlabs.io
- ElevenLabs: API keys (workspaces)elevenlabs.io
- ElevenLabs developer quickstartelevenlabs.io
- ElevenLabs: realtime speech to text, client-side streamingelevenlabs.io
- ElevenLabs API reference: create single-use tokenelevenlabs.io
- ElevenLabs: errorselevenlabs.io
- ElevenLabs help: API error code 400 or 401elevenlabs.io
- ElevenLabs help: unusual activity detected, free tier usage disabledelevenlabs.io
- ElevenLabs help: can I publish the content I generate?elevenlabs.io
- ElevenLabs pricingelevenlabs.io
- Railway docs: variablesdocs.railway.com
- Vercel docs: managing environment variablesvercel.com
Launch in an hour, not a weekend
Shipyard connects your accounts once, then sets up the domain, hosting, database, email and payments for every new product.