ElevenLabs Local Dev Loop
Overview
Set up a fast, cost-effective local development workflow for ElevenLabs audio
projects. The loop centers on three moves — mock the SDK so unit tests never
burn character quota, gate real API calls behind an explicit
ELEVENLABS_INTEGRATION=1 flag, and select a cheaper model in dev while keeping
the high-quality model for production — with tsx watch hot reload and a quota
checker to round out the cycle.
Follow the high-level flow below to scaffold the project, then drill into
references/implementation.md for the full code
of every step and references/examples.md for worked
end-to-end runs.
Prerequisites
Before starting, confirm your environment is ready:
- The
elevenlabs-install-auth setup is complete, so the SDK
(@elevenlabs/elevenlabs-js) is installed and ELEVENLABS_API_KEY is
available in .env.local.
- Node.js 18+ with
npm or pnpm.
vitest installed as the test runner (recommended) — it powers the mock
layer and the integration-test guard.
Instructions
Work through the six steps in order. Each is summarized here; the full code for
every step lives in references/implementation.md.
Project structure — lay out src/elevenlabs/ (client, config, tts),
tests/__mocks__/ and tests/fixtures/sample.mp3, a git-ignored output/,
and .env.local / .env.example. Full tree in the reference.
Environment configuration — write an environment-aware config.ts that
picks the model and output format by NODE_ENV. This is the essential
skeleton:
// src/elevenlabs/config.ts
export function loadConfig() {
const env = process.env.NODE_ENV || "development";
return {
apiKey: process.env.ELEVENLABS_API_KEY || "",
// cheaper/faster in dev, best quality in prod
modelId: env === "production"
? "eleven_multilingual_v2" // 1.0 credits/char
: "eleven_flash_v2_5", // 0.5 credits/char, ~75ms
defaultVoiceId: process.env.ELEVENLABS_VOICE_ID || "21m00Tcm4TlvDq8ikWAM",
outputFormat: "mp3_22050_32", // smaller files for dev
};
}
Mock the SDK — write tests/__mocks__/elevenlabs.ts that returns the
sample.mp3 fixture from textToSpeech.convert/stream and stubs
voices.getAll and user.get, so unit tests cost nothing.
Development scripts — add dev (tsx watch), test, test:watch,
test:integration, generate, and quota scripts to package.json.
Quota-aware development — add src/check-quota.ts that reads
user.subscription and exits non-zero when fewer than 1000 characters
remain, so a low balance fails fast.
Integration test guard — write tests/tts.test.ts where the real-API
test is it.skipIf(!useRealApi) and only runs under
ELEVENLABS_INTEGRATION=1; the mocked test always runs.
See references/implementation.md for the
complete, copy-pasteable code for each step.
Output
- Working development environment with hot reload via
tsx watch
- Mock layer that avoids API calls and character charges during dev
- Quota checker to prevent surprise billing
- Integration test guard pattern (
ELEVENLABS_INTEGRATION=1)
- Environment-aware model selection (cheap in dev, quality in prod)
Error Handling
| Error |
Cause |
Solution |
MODULE_NOT_FOUND |
SDK not installed |
npm install @elevenlabs/elevenlabs-js |
| Mock returns undefined |
Mock not wired |
Check vi.mock path matches import |
| Integration test fails |
No API key |
Set ELEVENLABS_API_KEY in .env.local |
| Quota exceeded in dev |
Running real API calls |
Use mock layer; run npm run quota first |
Examples
Four worked runs of the loop — full walkthroughs in
references/examples.md:
- Zero-cost unit tests —
npm run test drives the service through the mock
client, passes offline, and never touches the API or your quota.
- Quota preflight —
npm run quota prints Characters: 500 / 10,000 (5.0% used) and exits 1 when fewer than 1000 characters remain, blocking a paid
run before it starts.
- Opt-in integration run —
npm run test:integration sets
ELEVENLABS_INTEGRATION=1, flipping the it.skipIf(!useRealApi) test on so
the real API is hit only when you ask for it.
- Hot-reload iteration —
npm run dev (tsx watch) restarts on save; with
the dev model (eleven_flash_v2_5) and mocks, each loop stays fast and free.
Resources
Next Steps
Once the dev loop is running, move on to production-ready code: see the
elevenlabs-sdk-patterns skill for streaming, retries, and voice-management
patterns you can layer on top of this environment.
Source: jeremylongshore/claude-code-plugins-plus-skills → skills/.curated/elevenlabs-local-dev-loop/SKILL.md
Also appears in: jeremylongshore/claude-code-plugins-plus-skills/plugins/saas-packs/elevenlabs-pack/skills/elevenlabs-local-dev-loop/SKILL.md
1---2name: elevenlabs-local-dev-loop3description: "| Use when setting up a local ElevenLabs dev environment for a TTS/voice project and you need SDK mocking, hot reload, quota-aware iteration, and audio-output testing that does not burn character quota during development. Trigger with \"elevenlabs dev setup\", \"elevenlabs local development\", \"elevenlabs dev environment\", \"develop with elevenlabs\", \"test elevenlabs locally\"."4allowed-tools: "Read, Write, Edit, Bash(npm:*), Bash(pnpm:*)"5category: testing-and-qa6source_repo: jeremylongshore/claude-code-plugins-plus-skills7source_path: "skills/.curated/elevenlabs-local-dev-loop/SKILL.md"8source_url: https://github.com/jeremylongshore/claude-code-plugins-plus-skills/blob/HEAD/skills/.curated/elevenlabs-local-dev-loop/SKILL.md9metadata:10 source: https://skillmd.com/skills/thedixitjain/elevenlabs-local-dev-loop11---1213# ElevenLabs Local Dev Loop1415## Overview1617Set up a fast, cost-effective local development workflow for ElevenLabs audio18projects. The loop centers on three moves — mock the SDK so unit tests never19burn character quota, gate real API calls behind an explicit20`ELEVENLABS_INTEGRATION=1` flag, and select a cheaper model in dev while keeping21the high-quality model for production — with `tsx watch` hot reload and a quota22checker to round out the cycle.2324Follow the high-level flow below to scaffold the project, then drill into25[references/implementation.md](references/implementation.md) for the full code26of every step and [references/examples.md](references/examples.md) for worked27end-to-end runs.2829## Prerequisites3031Before starting, confirm your environment is ready:3233- The `elevenlabs-install-auth` setup is complete, so the SDK34 (`@elevenlabs/elevenlabs-js`) is installed and `ELEVENLABS_API_KEY` is35 available in `.env.local`.36- Node.js 18+ with `npm` or `pnpm`.37- `vitest` installed as the test runner (recommended) — it powers the mock38 layer and the integration-test guard.3940## Instructions4142Work through the six steps in order. Each is summarized here; the full code for43every step lives in [references/implementation.md](references/implementation.md).44451. **Project structure** — lay out `src/elevenlabs/` (client, config, tts),46 `tests/__mocks__/` and `tests/fixtures/sample.mp3`, a git-ignored `output/`,47 and `.env.local` / `.env.example`. Full tree in the reference.482. **Environment configuration** — write an environment-aware `config.ts` that49 picks the model and output format by `NODE_ENV`. This is the essential50 skeleton:5152 ```typescript53 // src/elevenlabs/config.ts54 export function loadConfig() {55 const env = process.env.NODE_ENV || "development";56 return {57 apiKey: process.env.ELEVENLABS_API_KEY || "",58 // cheaper/faster in dev, best quality in prod59 modelId: env === "production"60 ? "eleven_multilingual_v2" // 1.0 credits/char61 : "eleven_flash_v2_5", // 0.5 credits/char, ~75ms62 defaultVoiceId: process.env.ELEVENLABS_VOICE_ID || "21m00Tcm4TlvDq8ikWAM",63 outputFormat: "mp3_22050_32", // smaller files for dev64 };65 }66 ```67683. **Mock the SDK** — write `tests/__mocks__/elevenlabs.ts` that returns the69 `sample.mp3` fixture from `textToSpeech.convert`/`stream` and stubs70 `voices.getAll` and `user.get`, so unit tests cost nothing.714. **Development scripts** — add `dev` (`tsx watch`), `test`, `test:watch`,72 `test:integration`, `generate`, and `quota` scripts to `package.json`.735. **Quota-aware development** — add `src/check-quota.ts` that reads74 `user.subscription` and exits non-zero when fewer than 1000 characters75 remain, so a low balance fails fast.766. **Integration test guard** — write `tests/tts.test.ts` where the real-API77 test is `it.skipIf(!useRealApi)` and only runs under78 `ELEVENLABS_INTEGRATION=1`; the mocked test always runs.7980See [references/implementation.md](references/implementation.md) for the81complete, copy-pasteable code for each step.8283## Output8485- Working development environment with hot reload via `tsx watch`86- Mock layer that avoids API calls and character charges during dev87- Quota checker to prevent surprise billing88- Integration test guard pattern (`ELEVENLABS_INTEGRATION=1`)89- Environment-aware model selection (cheap in dev, quality in prod)9091## Error Handling9293| Error | Cause | Solution |94|-------|-------|----------|95| `MODULE_NOT_FOUND` | SDK not installed | `npm install @elevenlabs/elevenlabs-js` |96| Mock returns undefined | Mock not wired | Check vi.mock path matches import |97| Integration test fails | No API key | Set `ELEVENLABS_API_KEY` in `.env.local` |98| Quota exceeded in dev | Running real API calls | Use mock layer; run `npm run quota` first |99100## Examples101102Four worked runs of the loop — full walkthroughs in103[references/examples.md](references/examples.md):104105- **Zero-cost unit tests** — `npm run test` drives the service through the mock106 client, passes offline, and never touches the API or your quota.107- **Quota preflight** — `npm run quota` prints `Characters: 500 / 10,000 (5.0%108 used)` and exits `1` when fewer than 1000 characters remain, blocking a paid109 run before it starts.110- **Opt-in integration run** — `npm run test:integration` sets111 `ELEVENLABS_INTEGRATION=1`, flipping the `it.skipIf(!useRealApi)` test on so112 the real API is hit only when you ask for it.113- **Hot-reload iteration** — `npm run dev` (`tsx watch`) restarts on save; with114 the dev model (`eleven_flash_v2_5`) and mocks, each loop stays fast and free.115116## Resources117118- [ElevenLabs JS SDK](https://github.com/elevenlabs/elevenlabs-js)119- [Vitest Mocking](https://vitest.dev/guide/mocking.html)120- [tsx (TypeScript Execute)](https://github.com/privatenumber/tsx)121122## Next Steps123124Once the dev loop is running, move on to production-ready code: see the125`elevenlabs-sdk-patterns` skill for streaming, retries, and voice-management126patterns you can layer on top of this environment.127128---129130**Source:** [`jeremylongshore/claude-code-plugins-plus-skills`](https://github.com/jeremylongshore/claude-code-plugins-plus-skills) → `skills/.curated/elevenlabs-local-dev-loop/SKILL.md`131132**Also appears in:** `jeremylongshore/claude-code-plugins-plus-skills/plugins/saas-packs/elevenlabs-pack/skills/elevenlabs-local-dev-loop/SKILL.md`