/elevenlabs-pack:elevenlabs-sdk-patternsfrom elevenlabs-pack
Applies production-ready ElevenLabs SDK patterns for TypeScript and Python: singleton client, type-safe TTS wrapper, error classification, retry with concurrency queue, and multi-tenant client factory.
Ships in elevenlabs-pack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Production-ready patterns for the ElevenLabs TypeScript and Python SDKs. Covers singleton clients, type-safe TTS wrappers, error classification, retry with a concurrency queue, and multi-tenant client factories. Adopt them incrementally — the singleton client alone fixes the most common mistakes; add error classification and the queue as throughput grows.
The full, copy-ready code for all six patterns lives in references/implementation.md. This file gives the high-level workflow plus the essential skeleton so you can follow it end to end, then drill into the reference for depth.
@elevenlabs/elevenlabs-js installed (TypeScript) or elevenlabs (Python)ELEVENLABS_API_KEY exported in the environment (never hardcode the key)Apply the patterns in order — each builds on the previous one:
Singleton client. Create one lazily-initialized ElevenLabsClient guarded by an
ELEVENLABS_API_KEY check so misconfiguration fails fast at startup. Expose a resetClient()
for tests. This is the skeleton every other pattern imports:
let instance: ElevenLabsClient | null = null;
export function getClient(): ElevenLabsClient {
if (!instance) {
if (!process.env.ELEVENLABS_API_KEY) {
throw new Error("ELEVENLABS_API_KEY environment variable is required");
}
instance = new ElevenLabsClient({
apiKey: process.env.ELEVENLABS_API_KEY,
maxRetries: 3,
timeoutInSeconds: 60,
});
}
return instance;
}
Type-safe TTS service. Wrap textToSpeech.convert behind a typed TTSOptions interface
and named VoicePreset records (narration / conversational / dramatic / neutral) so voice
settings are compile-time checked and consistent across the codebase.
Error classification. Map raw SDK errors to an ElevenLabsServiceError carrying a stable
code (auth_failed, quota_exceeded, rate_limited, concurrent_limit, voice_not_found,
invalid_request, server_error, network_error) and a retryable flag driven by HTTP status.
Retry with a concurrency queue. Route calls through a p-queue sized to your plan's
concurrent-request limit, retrying only retryable errors with exponential backoff + jitter.
Multi-tenant factory. For SaaS platforms, key one client per tenant in a Map so each
customer's API key stays isolated.
Python async. Mirror the singleton + streaming-to-file pattern with AsyncElevenLabsClient
for non-blocking Python backends.
See references/implementation.md for the complete code for every step above.
Applying these patterns produces a small set of focused SDK modules in the target project:
src/elevenlabs/client.ts — singleton client with config + resetClient()src/elevenlabs/tts-service.ts — typed generateSpeech() / generateToFile() with voice presetssrc/elevenlabs/errors.ts — ElevenLabsServiceError + classifyError()src/elevenlabs/queue.ts — queuedRequest() with backoff and plan-aware concurrencysrc/elevenlabs/multi-tenant.ts — per-tenant client factory (SaaS only)elevenlabs_service.py — async singleton + streaming generator (Python backends)TTS calls return an audio stream you pipe to a file or HTTP response; mp3_44100_128 is the
default output format.
| Pattern | Error Type | Benefit |
|---|---|---|
classifyError() | All API errors | Maps HTTP status to actionable codes |
queuedRequest() | 429, 5xx | Auto-retry with exponential backoff + jitter |
| Singleton guard | Missing env var | Fails fast at startup, not at first call |
Only retryable codes (rate_limited, concurrent_limit, server_error, network_error) are
retried; auth_failed, quota_exceeded, voice_not_found, and invalid_request throw
immediately so callers surface a real problem instead of looping.
Generate speech to a file (TypeScript):
import { generateToFile } from "./elevenlabs/tts-service";
await generateToFile(
{ voiceId: "21m00Tcm4TlvDq8ikWAM", text: "Welcome aboard.", preset: "narration" },
"welcome.mp3"
);
Wrap a call in the retry queue:
import { queuedRequest } from "./elevenlabs/queue";
import { generateSpeech } from "./elevenlabs/tts-service";
const audio = await queuedRequest(() =>
generateSpeech({ voiceId: "21m00Tcm4TlvDq8ikWAM", text: "High-throughput job." })
);
Full runnable examples — including the Python async path and multi-tenant usage — are in references/implementation.md.
Apply these patterns in elevenlabs-core-workflow-a for TTS generation, or see
elevenlabs-rate-limits for advanced throttling and plan-aware concurrency tuning.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
18 skills in this plugin
/elevenlabs-ci-integrationConfigure CI/CD pipelines for ElevenLabs with mocked unit tests and gated
integration tests.
Use when setting up GitHub Actions for TTS projects, configuring CI test
strategies, or automating ElevenLabs integration validation without burning
character quota on every PR.
Trigger with "elevenlabs CI", "elevenlabs GitHub Actions",
"elevenlabs automated tests", "CI elevenlabs", "elevenlabs pipeline".
/elevenlabs-common-errorsDiagnose and fix ElevenLabs API errors by HTTP status code.
Use when encountering ElevenLabs errors, debugging failed TTS/STS requests,
or troubleshooting voice cloning and streaming issues.
Trigger with "elevenlabs error", "fix elevenlabs", "elevenlabs not working",
"debug elevenlabs", "elevenlabs 401", "elevenlabs 429", "elevenlabs 400".
/elevenlabs-core-workflow-aImplement ElevenLabs text-to-speech and voice cloning workflows.
Use when building TTS features, cloning voices from audio samples, streaming
speech to a chatbot, or implementing the primary ElevenLabs money-path: voice
generation.
Trigger with "elevenlabs TTS", "text to speech", "voice cloning elevenlabs",
"clone a voice", "generate speech", "elevenlabs voice".
/elevenlabs-core-workflow-bImplement ElevenLabs speech-to-speech, sound effects, audio isolation, and
speech-to-text.
Use when converting one voice to another, generating sound effects from a text
description, removing background noise from a recording, or transcribing audio.
Trigger with "elevenlabs speech to speech", "voice changer", "sound effects",
"audio isolation", "remove background noise", "elevenlabs transcribe".
/elevenlabs-cost-tuningOptimize ElevenLabs costs through model selection, character-efficient patterns,
caching, and usage monitoring with budget alerts.
Use when analyzing ElevenLabs billing, reducing character usage, hunting down bill
shock, or implementing quota monitoring for TTS workloads.
Trigger with "elevenlabs cost", "elevenlabs billing", "reduce elevenlabs costs",
"elevenlabs pricing", "elevenlabs expensive", "elevenlabs budget",
"elevenlabs characters", "elevenlabs quota".
/elevenlabs-debug-bundleCollect ElevenLabs debug evidence for support tickets and troubleshooting.
Use when encountering persistent issues, preparing a support ticket, or
gathering diagnostic information (SDK version, API connectivity, quota, voice
inventory, model availability) for an ElevenLabs problem, with secrets
redacted automatically. Trigger with "elevenlabs debug", "elevenlabs support
bundle", "collect elevenlabs logs", "elevenlabs diagnostic", "elevenlabs
support ticket".
npx claudepluginhub jeremylongshore/tons-of-skills-marketplace --plugin elevenlabs-packOther plugins' skills for the same job