Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Apply production-ready Deepgram SDK patterns for TypeScript and Python. Use when implementing Deepgram integrations, refactoring SDK usage, or establishing team coding standards for Deepgram. Trigger: "deepgram SDK patterns", "deepgram best practices", "deepgram code patterns", "idiomatic deepgram", "deepgram typescript".
.claude/skills/jeremylongshore-deepgram-sdk-patterns/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 60% | 0% |
| case-02 | ✗→✓ | ▲ Improved | 26% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 36% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 78% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 58% | 0% |
Production patterns for @deepgram/sdk (TypeScript) and deepgram-sdk (Python). Covers singleton client, typed wrappers, text-to-speech with Aura, audio intelligence pipeline, error handling, and SDK v5 migration path.
npm install @deepgram/sdk or pip install deepgram-sdkDEEPGRAM_API_KEY environment variable configuredtypescriptimport { createClient, DeepgramClient } from '@deepgram/sdk'; class DeepgramService { private static instance: DeepgramService; private client: DeepgramClient; private constructor() { const apiKey = process.env.DEEPGRAM_API_KEY; if (!apiKey) throw new Error('DEEPGRAM_API_KEY is required'); this.client = createClient(apiKey); } static getInstance(): DeepgramService { if (!this.instance) this.instance = new DeepgramService(); return this.instance; } getClient(): DeepgramClient { return this.client; } } export const deepgram = DeepgramService.getInstance().getClient();
typescriptimport { createClient } from '@deepgram/sdk'; import { writeFileSync } from 'fs'; const deepgram = createClient(process.env.DEEPGRAM_API_KEY!); async function textToSpeech(text: string, outputPath: string) { const response = await deepgram.speak.request( { text }, { model: 'aura-2-thalia-en', // Female English voice encoding: 'linear16', container: 'wav', sample_rate: 24000, } ); const stream = await response.getStream(); if (!stream) throw new Error('No audio stream returned'); // Collect stream into buffer const reader = stream.getReader(); const chunks: Uint8Array[] = []; while (true) { const { done, value } = await reader.read(); if (done) break; chunks.push(value); } const buffer = Buffer.concat(chunks); writeFileSync(outputPath, buffer); console.log(`Audio saved: ${outputPath} (${buffer.length} bytes)`); return buffer; } // Aura-2 voice options: // aura-2-thalia-en — Female, warm // aura-2-asteria-en — Female, default // aura-2-orion-en — Male, deep // aura-2-luna-en — Female, soft // aura-2-helios-en — Male, authoritative // aura-asteria-en — Aura v1 fallback
typescriptasync function analyzeConversation(audioUrl: string) { const { result, error } = await deepgram.listen.prerecorded.transcribeUrl( { url: audioUrl }, { model: 'nova-3', smart_format: true, diarize: true, utterances: true, // Audio Intelligence features summarize: 'v2', // Generates a short summary detect_topics: true, // Identifies key topics sentiment: true, // Per-segment sentiment analysis intents: true, // Identifies speaker intents } ); if (error) throw error; return { transcript: result.results.channels[0].alternatives[0].transcript, summary: result.results.summary?.short, topics: result.results.topics?.segments?.map((s: any) => ({ text: s.text, topics: s.topics.map((t: any) => t.topic), })), sentiments: result.results.sentiments?.segments?.map((s: any) => ({ text: s.text, sentiment: s.sentiment, confidence: s.sentiment_score, })), intents: result.results.intents?.segments?.map((s: any) => ({ text: s.text, intent: s.intents[0]?.intent, confidence: s.intents[0]?.confidence_score, })), }; }
pythonfrom deepgram import DeepgramClient, PrerecordedOptions, LiveOptions, SpeakOptions import os class DeepgramService: _instance = None def __new__(cls): if cls._instance is None: cls._instance = super().__new__(cls) cls._instance.client = DeepgramClient(os.environ["DEEPGRAM_API_KEY"]) return cls._instance def transcribe_url(self, url: str, **kwargs): options = PrerecordedOptions( model=kwargs.get("model", "nova-3"), smart_format=True, diarize=kwargs.get("diarize", False), summarize=kwargs.get("summarize", False), ) source = {"url": url} return self.client.listen.rest.v("1").transcribe_url(source, options) def transcribe_file(self, path: str, **kwargs): with open(path, "rb") as f: source = {"buffer": f.read(), "mimetype": self._mimetype(path)} options = PrerecordedOptions( model=kwargs.get("model", "nova-3"), smart_format=True, diarize=kwargs.get("diarize", False), ) return self.client.listen.rest.v("1").transcribe_file(source, options) def text_to_speech(self, text: str, output_path: str): options = SpeakOptions(model="aura-2-thalia-en", encoding="linear16") response = self.client.speak.rest.v("1").save(output_path, {"text": text}, options) return response @staticmethod def _mimetype(path: str) -> str: ext = path.rsplit(".", 1)[-1].lower() return {"wav": "audio/wav", "mp3": "audio/mpeg", "flac": "audio/flac", "ogg": "audio/ogg", "m4a": "audio/mp4"}.get(ext, "audio/wav")
typescript// Extract clean types from Deepgram responses interface TranscriptWord { word: string; start: number; end: number; confidence: number; speaker?: number; punctuated_word?: string; } interface TranscriptResult { transcript: string; confidence: number; words: TranscriptWord[]; duration: number; requestId: string; } function parseResult(result: any): TranscriptResult { const alt = result.results.channels[0].alternatives[0]; return { transcript: alt.transcript, confidence: alt.confidence, words: alt.words ?? [], duration: result.metadata.duration, requestId: result.metadata.request_id, }; }
typescript// v3/v4 (current stable): import { createClient } from '@deepgram/sdk'; const dg = createClient(apiKey); await dg.listen.prerecorded.transcribeUrl(source, options); await dg.listen.live(options); await dg.speak.request({ text }, options); // v5 (auto-generated, Fern-based): import { DeepgramClient } from '@deepgram/sdk'; const dg = new DeepgramClient({ apiKey }); await dg.listen.v1.media.transcribeUrl(source, options); await dg.listen.v1.connect(options); // async await dg.speak.v1.audio.generate({ text }, options);
| Error | Cause | Solution | |-------|-------|----------| | 401 Unauthorized | Invalid API key | Check DEEPGRAM_API_KEY value | | 400 Unsupported format | Bad audio codec | Convert to WAV/MP3/FLAC | | speak.request is not a function | SDK version mismatch | Check import, v5 uses speak.v1.audio.generate | | Empty TTS response | Empty text input | Validate text is non-empty before calling | | summarize returns null | Feature not enabled | Pass summarize: 'v2' (string, not boolean) |
Proceed to deepgram-data-handling for transcript storage and processing patterns.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | 14,177 | 11,238 | -21% | 1 | 1 | 0% | 3,051 | 4,885 | +60% | 0 | 0 | — |
case-02 | fail→pass | 19,660 | 12,811 | -35% | 1 | 1 | 0% | 4,052 | 5,093 | +26% | 0 | 0 | — |
case-03 | fail→pass | 15,065 | 7,039 | -53% | 1 | 1 | 0% | 2,715 | 3,686 | +36% | 0 | 0 | — |
case-04 | fail→pass | 13,282 | 9,403 | -29% | 1 | 1 | 0% | 2,328 | 4,143 | +78% | 0 | 0 | — |
case-05 | fail→pass | 9,218 | 2,842 | -69% | 1 | 1 | 0% | 1,789 | 2,822 | +58% | 0 | 0 | — |
case-06 | pass→pass | 10,628 | 3,930 | -63% | 1 | 1 | 0% | 1,922 | 2,811 | +46% | 0 | 0 | — |
case-07 | pass→pass | 12,983 | 4,999 | -61% | 1 | 1 | 0% | 1,838 | 3,104 | +69% | 0 | 0 | — |
case-08 | pass→pass | 6,490 | 6,381 | -2% | 1 | 1 | 0% | 1,113 | 3,486 | +213% | 0 | 0 | — |
case-09 | fail→pass | 12,883 | 7,688 | -40% | 1 | 1 | 0% | 2,390 | 3,730 | +56% | 0 | 0 | — |
case-10 | pass→pass | 13,417 | 7,465 | -44% | 1 | 1 | 0% | 2,485 | 3,605 | +45% | 0 | 0 | — |
case-11 | fail→pass | 7,621 | 6,932 | -9% | 1 | 1 | 0% | 1,448 | 3,495 | +141% | 0 | 0 | — |
case-12 | pass→pass | 9,665 | 6,393 | -34% | 1 | 1 | 0% | 1,530 | 3,339 | +118% | 0 | 0 | — |
case-13 | pass→pass | 8,520 | 6,034 | -29% | 1 | 1 | 0% | 1,740 | 3,478 | +100% | 0 | 0 | — |
case-14 | pass→pass | 12,071 | 6,571 | -46% | 1 | 1 | 0% | 1,861 | 3,443 | +85% | 0 | 0 | — |
case-15 | fail→pass | 41,870 | 4,686 | -89% | 1 | 1 | 0% | 3,502 | 3,111 | -11% | 0 | 0 | — |
case-16 | fail→pass | 22,686 | 8,307 | -63% | 1 | 1 | 0% | 3,873 | 3,545 | -8% | 0 | 0 | — |
case-17 | fail→pass | 9,805 | 20,822 | +112% | 1 | 1 | 0% | 1,415 | 2,766 | +95% | 0 | 0 | — |
case-18 | pass→pass | 12,878 | 28,295 | +120% | 1 | 1 | 0% | 1,950 | 3,187 | +63% | 0 | 0 | — |
case-19 | fail→pass | 13,698 | 3,993 | -71% | 1 | 1 | 0% | 2,414 | 2,942 | +22% | 0 | 0 | — |
case-20 | pass→pass | 16,012 | 14,419 | -10% | 1 | 1 | 0% | 3,048 | 5,101 | +67% | 0 | 0 | — |
case-21 | pass→pass | 12,299 | 14,925 | +21% | 1 | 1 | 0% | 2,367 | 5,234 | +121% | 0 | 0 | — |
case-22 | pass→pass | 18,180 | 58,349 | +221% | 1 | 1 | 0% | 3,628 | 5,013 | +38% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +50 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.