agentsclimarketplace

Elevenlabs reference architecture

Skill ComeOnOliver/skillshub/skills/jeremylongshore/claude-code-plugins-plus-skills/elevenlabs-reference-architecture

🧠 The right skill, one API call. AI agent skills registry with token-efficient skill resolution. 5,000+ skills from 500+ top repos.

Install
npx -y skills add ComeOnOliver/skillshub --skill elevenlabs-reference-architecture

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

What its author says it does

Copied from the file, not written here

Implement ElevenLabs reference architecture for production TTS/voice applications. Use when designing new ElevenLabs integrations, reviewing project structure, or building a scalable audio generation service. Trigger: "elevenlabs architecture", "elevenlabs project structure", "how to organize elevenlabs", "TTS service architecture", "elevenlabs design patterns", "voice API architecture".

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

13.4 KB, ~3.1k tokens by cl100k_base, as published. Nobody here has run it

ElevenLabs Reference Architecture

Overview

Production-ready architecture for ElevenLabs TTS/voice applications. Covers project layout, service layers, caching, streaming, and multi-model orchestration.

Prerequisites

  • Understanding of layered architecture patterns
  • ElevenLabs SDK knowledge (see elevenlabs-sdk-patterns)
  • TypeScript project with async patterns
  • Redis (optional, for distributed caching)

Instructions

Step 1: Project Structure

my-elevenlabs-service/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ elevenlabs/
β”‚   β”‚   β”œβ”€β”€ client.ts            # Singleton client with retry config
β”‚   β”‚   β”œβ”€β”€ config.ts            # Environment-aware configuration
β”‚   β”‚   β”œβ”€β”€ models.ts            # Model selection logic
β”‚   β”‚   β”œβ”€β”€ errors.ts            # Error classification (see sdk-patterns)
β”‚   β”‚   └── types.ts             # TypeScript interfaces
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”œβ”€β”€ tts-service.ts       # Text-to-Speech orchestration
β”‚   β”‚   β”œβ”€β”€ voice-service.ts     # Voice management (clone, list, settings)
β”‚   β”‚   β”œβ”€β”€ audio-service.ts     # SFX, isolation, transcription
β”‚   β”‚   └── cache-service.ts     # Audio caching layer
β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”‚   β”œβ”€β”€ tts.ts           # POST /api/tts
β”‚   β”‚   β”‚   β”œβ”€β”€ voices.ts        # GET/POST /api/voices
β”‚   β”‚   β”‚   β”œβ”€β”€ webhooks.ts      # POST /webhooks/elevenlabs
β”‚   β”‚   β”‚   └── health.ts        # GET /health
β”‚   β”‚   └── middleware/
β”‚   β”‚       β”œβ”€β”€ rate-limit.ts    # Request throttling
β”‚   β”‚       └── auth.ts          # Your app's auth (not ElevenLabs auth)
β”‚   β”œβ”€β”€ queue/
β”‚   β”‚   β”œβ”€β”€ tts-queue.ts         # Async TTS job processing
β”‚   β”‚   └── workers.ts           # Queue workers
β”‚   └── monitoring/
β”‚       β”œβ”€β”€ metrics.ts           # Latency, error rate, quota tracking
β”‚       └── alerts.ts            # Budget and health alerts
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ unit/
β”‚   β”‚   β”œβ”€β”€ tts-service.test.ts
β”‚   β”‚   └── cache-service.test.ts
β”‚   └── integration/
β”‚       └── tts-smoke.test.ts
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ development.json
β”‚   β”œβ”€β”€ staging.json
β”‚   └── production.json
└── .env.example

Step 2: Configuration Layer

// src/elevenlabs/config.ts
export interface ElevenLabsConfig {
  apiKey: string;
  environment: "development" | "staging" | "production";
  defaults: {
    modelId: string;
    voiceId: string;
    outputFormat: string;
    voiceSettings: {
      stability: number;
      similarity_boost: number;
      style: number;
      speed: number;
    };
  };
  performance: {
    maxConcurrency: number;
    timeoutMs: number;
    maxRetries: number;
  };
  cache: {
    enabled: boolean;
    maxSizeMB: number;
    ttlSeconds: number;
  };
}

const ENV_CONFIGS: Record<string, Partial<ElevenLabsConfig>> = {
  development: {
    defaults: {
      modelId: "eleven_flash_v2_5",    // Cheap + fast for dev
      voiceId: "21m00Tcm4TlvDq8ikWAM", // Rachel
      outputFormat: "mp3_22050_32",     // Small files
      voiceSettings: { stability: 0.5, similarity_boost: 0.75, style: 0, speed: 1 },
    },
    performance: { maxConcurrency: 2, timeoutMs: 30_000, maxRetries: 1 },
    cache: { enabled: true, maxSizeMB: 50, ttlSeconds: 3600 },
  },
  production: {
    defaults: {
      modelId: "eleven_multilingual_v2", // High quality for prod
      voiceId: "21m00Tcm4TlvDq8ikWAM",
      outputFormat: "mp3_44100_128",     // High quality
      voiceSettings: { stability: 0.5, similarity_boost: 0.75, style: 0, speed: 1 },
    },
    performance: { maxConcurrency: 10, timeoutMs: 60_000, maxRetries: 3 },
    cache: { enabled: true, maxSizeMB: 500, ttlSeconds: 86_400 },
  },
};

export function loadConfig(): ElevenLabsConfig {
  const env = process.env.NODE_ENV || "development";
  const envConfig = ENV_CONFIGS[env] || ENV_CONFIGS.development;

  return {
    apiKey: process.env.ELEVENLABS_API_KEY!,
    environment: env as any,
    ...envConfig,
  } as ElevenLabsConfig;
}

Step 3: TTS Service Layer

// src/services/tts-service.ts
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";
import PQueue from "p-queue";
import { loadConfig } from "../elevenlabs/config";
import { classifyError } from "../elevenlabs/errors";

export class TTSService {
  private client: ElevenLabsClient;
  private queue: PQueue;
  private config: ReturnType<typeof loadConfig>;

  constructor() {
    this.config = loadConfig();
    this.client = new ElevenLabsClient({
      apiKey: this.config.apiKey,
      maxRetries: this.config.performance.maxRetries,
      timeoutInSeconds: this.config.performance.timeoutMs / 1000,
    });
    this.queue = new PQueue({
      concurrency: this.config.performance.maxConcurrency,
    });
  }

  async generate(text: string, options?: {
    voiceId?: string;
    modelId?: string;
    outputFormat?: string;
    streaming?: boolean;
  }): Promise<ReadableStream | Buffer> {
    const voiceId = options?.voiceId || this.config.defaults.voiceId;
    const modelId = options?.modelId || this.config.defaults.modelId;
    const format = options?.outputFormat || this.config.defaults.outputFormat;

    return this.queue.add(async () => {
      const start = performance.now();

      try {
        if (options?.streaming) {
          return await this.client.textToSpeech.stream(voiceId, {
            text,
            model_id: modelId,
            output_format: format,
            voice_settings: this.config.defaults.voiceSettings,
          });
        }

        const audio = await this.client.textToSpeech.convert(voiceId, {
          text,
          model_id: modelId,
          output_format: format,
          voice_settings: this.config.defaults.voiceSettings,
        });

        const latency = performance.now() - start;
        console.log(`[TTS] ${text.length} chars, ${modelId}, ${latency.toFixed(0)}ms`);
        return audio;
      } catch (error) {
        throw classifyError(error);
      }
    }) as Promise<ReadableStream | Buffer>;
  }

  // Split long text into chunks with prosody context
  async generateLongText(text: string, voiceId?: string): Promise<Buffer[]> {
    const chunks = this.splitText(text, 4500); // Stay under 5000 limit
    const results: Buffer[] = [];

    for (let i = 0; i < chunks.length; i++) {
      const audio = await this.generate(chunks[i], {
        voiceId,
        // Pass context for natural prosody across chunks
      });
      results.push(audio as Buffer);
    }

    return results;
  }

  private splitText(text: string, maxChars: number): string[] {
    const chunks: string[] = [];
    const sentences = text.match(/[^.!?]+[.!?]+/g) || [text];
    let current = "";

    for (const sentence of sentences) {
      if ((current + sentence).length > maxChars) {
        if (current) chunks.push(current.trim());
        current = sentence;
      } else {
        current += sentence;
      }
    }
    if (current) chunks.push(current.trim());
    return chunks;
  }
}

Step 4: Voice Management Service

// src/services/voice-service.ts
export class VoiceService {
  private client: ElevenLabsClient;

  constructor(client: ElevenLabsClient) {
    this.client = client;
  }

  async listVoices(filter?: { category?: "premade" | "cloned" | "generated" }) {
    const { voices } = await this.client.voices.getAll();
    if (filter?.category) {
      return voices.filter(v => v.category === filter.category);
    }
    return voices;
  }

  async cloneVoice(name: string, description: string, audioFiles: NodeJS.ReadableStream[]) {
    return this.client.voices.add({
      name,
      description,
      files: audioFiles,
    });
  }

  async getVoiceSettings(voiceId: string) {
    return this.client.voices.getSettings(voiceId);
  }

  async updateVoiceSettings(voiceId: string, settings: {
    stability: number;
    similarity_boost: number;
  }) {
    return this.client.voices.editSettings(voiceId, settings);
  }

  async deleteVoice(voiceId: string) {
    return this.client.voices.delete(voiceId);
  }
}

Step 5: Data Flow Diagram

                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚   Client     β”‚
                         β”‚  (Browser/   β”‚
                         β”‚   Mobile)    β”‚
                         β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                         β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”
                         β”‚   API Layer  β”‚
                         β”‚   /api/tts   β”‚
                         β”‚   /api/voice β”‚
                         β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚           β”‚           β”‚
             β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β” β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
             β”‚  Cache   β”‚ β”‚   TTS     β”‚ β”‚  Voice  β”‚
             β”‚ Service  β”‚ β”‚  Service  β”‚ β”‚ Service β”‚
             β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”‚           β”‚
              β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”  β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚ Redis/ β”‚  β”‚ Concurrency    β”‚
              β”‚ LRU    β”‚  β”‚ Queue (p-queue)β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                         β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”
                         β”‚  ElevenLabs  β”‚
                         β”‚  Client SDK  β”‚
                         β”‚  (singleton) β”‚
                         β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚           β”‚           β”‚
             β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β” β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β” β”Œβ”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
             β”‚ /v1/tts  β”‚ β”‚ /v1/voicesβ”‚ β”‚ /v1/sfx β”‚
             β”‚ REST/WS  β”‚ β”‚  REST     β”‚ β”‚  REST   β”‚
             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    ElevenLabs API (api.elevenlabs.io)

Step 6: Health Check Composition

// src/api/routes/health.ts
export async function healthCheck() {
  const checks = await Promise.allSettled([
    checkElevenLabsConnectivity(),
    checkQuotaStatus(),
    checkCacheHealth(),
  ]);

  const elevenlabs = checks[0].status === "fulfilled" ? checks[0].value : null;
  const quota = checks[1].status === "fulfilled" ? checks[1].value : null;
  const cache = checks[2].status === "fulfilled" ? checks[2].value : null;

  const degraded = !elevenlabs || (quota && quota.pctUsed > 90);

  return {
    status: !elevenlabs ? "unhealthy" : degraded ? "degraded" : "healthy",
    services: { elevenlabs, quota, cache },
    timestamp: new Date().toISOString(),
  };
}

Architecture Decisions

DecisionChoiceRationale
Client patternSingletonOne connection pool, shared retry config
Concurrencyp-queueRespects plan limits, prevents 429
CachingLRU (local) or Redis (distributed)Repeated content is common in TTS
Long textSentence-boundary splittingPreserves natural speech prosody
Error handlingClassification + retryDifferent strategies for 429 vs 401 vs 500
Model selectionEnvironment-basedFlash in dev (cheap), Multilingual in prod (quality)
StreamingHTTP streaming + WebSocketHTTP for simple, WS for LLM integration

Error Handling

IssueCauseSolution
Circular dependenciesWrong layeringServices depend on client, never reverse
Cold start latencyClient initializationPre-warm in server startup
Memory pressureUnbounded audio cacheSet maxSizeMB on cache
Type errorsSDK version mismatchPin SDK version in package.json

Resources

Next Steps

Start with elevenlabs-install-auth for setup, then apply this architecture. Use elevenlabs-core-workflow-a and elevenlabs-core-workflow-b for feature implementation.

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 326,984. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.