Skip to content
deepgram-cost-tuning logo

Deepgram Cost Tuning

deepgram-cost-tuning

Optimize Deepgram costs and usage for budget-conscious deployments. Use when reducing transcription costs, implementing usage controls, or optimizing pricing tier utilization. Trigger with phrases like "deepgram cost", "reduce deepgram spending", "deepgram pricing", "deepgram budget", "optimize d...

SKILL.md

Full skill instructions

Deepgram Cost Tuning

Overview

Optimize Deepgram usage and costs through smart model selection, audio preprocessing, and usage monitoring.

Deepgram Pricing Overview

ModelPrice per MinuteBest For
Nova-2$0.0043General transcription
Nova$0.0043General transcription
Whisper Cloud$0.0048Multilingual
Enhanced$0.0145Legacy support
Base$0.0048Basic transcription

Additional Features:

  • Speaker Diarization: +$0.0044/​min
  • Smart Formatting: Included
  • Punctuation: Included

Cost Optimization Strategies

1. Model Selection

Choose the most cost-effective model for your use case.

2. Audio Preprocessing

Reduce audio duration and optimize format.

3. Usage Monitoring

Track and control usage in real-time.

4. Caching

Avoid re-transcribing the same content.

Examples

Cost-Optimized Transcription Service

// services/​cost-optimized-transcription.ts
import { createClient } from '@deepgram/​sdk';

interface CostConfig {
  maxMonthlySpend: number;
  warningThreshold: number; // percentage
  model: string;
  enabledFeatures: {
    diarization: boolean;
    smartFormat: boolean;
  };
}

interface CostMetrics {
  currentMonthMinutes: number;
  currentMonthCost: number;
  projectedMonthlyCost: number;
}

export class CostOptimizedTranscription {
  private client;
  private config: CostConfig;
  private metrics: CostMetrics;
  private modelCosts: Record<string, number> = {
    'nova-2': 0.0043,
    'nova': 0.0043,
    'base': 0.0048,
    'enhanced': 0.0145,
  };

  constructor(apiKey: string, config: Partial<CostConfig> = {}) {
    this.client = createClient(apiKey);
    this.config = {
      maxMonthlySpend: config.maxMonthlySpend ?? 100,
      warningThreshold: config.warningThreshold ?? 80,
      model: config.model ?? 'nova-2',
      enabledFeatures: config.enabledFeatures ?? {
        diarization: false,
        smartFormat: true,
      },
    };
    this.metrics = {
      currentMonthMinutes: 0,
      currentMonthCost: 0,
      projectedMonthlyCost: 0,
    };
  }

  private calculateCost(durationMinutes: number): number {
    let cost = durationMinutes * this.modelCosts[this.config.model];

    if (this.config.enabledFeatures.diarization) {
      cost += durationMinutes * 0.0044;
    }

    return cost;
  }

  private checkBudget(estimatedMinutes: number): void {
    const estimatedCost = this.calculateCost(estimatedMinutes);
    const projectedTotal = this.metrics.currentMonthCost + estimatedCost;

    if (projectedTotal > this.config.maxMonthlySpend) {
      throw new Error(`Budget exceeded. Current: $${this.metrics.currentMonthCost.toFixed(2)}, Estimated: $${estimatedCost.toFixed(2)}, Limit: $${this.config.maxMonthlySpend}`);
    }

    const percentage = (projectedTotal / this.config.maxMonthlySpend) * 100;
    if (percentage >= this.config.warningThreshold) {
      console.warn(`Budget warning: ${percentage.toFixed(1)}% of monthly limit used`);
    }
  }

  async transcribe(audioUrl: string, estimatedDurationMinutes: number) {
    this.checkBudget(estimatedDurationMinutes);

    const startTime = Date.now();

    const { result, error } = await this.client.listen.prerecorded.transcribeUrl(
      { url: audioUrl },
      {
        model: this.config.model,
        smart_format: this.config.enabledFeatures.smartFormat,
        diarize: this.config.enabledFeatures.diarization,
      }
    );

    if (error) throw error;

    // Track actual usage
    const actualDuration = result.metadata.duration / 60; // seconds to minutes
    const cost = this.calculateCost(actualDuration);

    this.metrics.currentMonthMinutes += actualDuration;
    this.metrics.currentMonthCost += cost;

    return {
      transcript: result.results.channels[0].alternatives[0].transcript,
      metadata: {
        duration: actualDuration,
        cost,
        model: this.config.model,
      },
    };
  }

  getMetrics(): CostMetrics & { budgetRemaining: number } {
    return {
      ...this.metrics,
      budgetRemaining: this.config.maxMonthlySpend - this.metrics.currentMonthCost,
    };
  }
}

Audio Duration Reducer

// lib/​audio-reducer.ts
import ffmpeg from 'fluent-ffmpeg';

interface ReductionOptions {
  silenceThreshold: string; // dB
  silenceMinDuration: number; // seconds
  speed: number; // 1.0 = normal, 1.25 = 25% faster
}

export async function reduceDuration(
  inputPath: string,
  outputPath: string,
  options: Partial<ReductionOptions> = {}
): Promise<{ originalDuration: number; reducedDuration: number; savings: number }> {
  const {
    silenceThreshold = '-30dB',
    silenceMinDuration = 0.5,
    speed = 1.0,
  } = options;

  return new Promise((resolve, reject) => {
    let originalDuration = 0;
    let reducedDuration = 0;

    ffmpeg(inputPath)
      .on('codecData', (data) => {
        originalDuration = parseDuration(data.duration);
      })
      // Remove silence
      .audioFilters([
        `silenceremove=start_periods=1:start_silence=${silenceMinDuration}:start_threshold=${silenceThreshold}`,
        `silenceremove=stop_periods=-1:stop_silence=${silenceMinDuration}:stop_threshold=${silenceThreshold}`,
        // Optionally speed up
        ...(speed !== 1.0 ? [`atempo=${speed}`] : []),
      ])
      .output(outputPath)
      .on('end', () => {
        ffmpeg.ffprobe(outputPath, (err, metadata) => {
          if (err) return reject(err);
          reducedDuration = metadata.format.duration || 0;
          resolve({
            originalDuration,
            reducedDuration,
            savings: ((originalDuration - reducedDuration) / originalDuration) * 100,
          });
        });
      })
      .on('error', reject)
      .run();
  });
}

function parseDuration(duration: string): number {
  const parts = duration.split(':').map(Number);
  return parts[0] * 3600 + parts[1] * 60 + parts[2];
}

Usage Dashboard

// lib/​usage-dashboard.ts
import { createClient } from '@deepgram/​sdk';

interface UsageSummary {
  period: { start: Date; end: Date };
  totalMinutes: number;
  totalCost: number;
  byModel: Record<string, { minutes: number; cost: number }>;
  byDay: Array<{ date: string; minutes: number; cost: number }>;
  projections: {
    monthlyMinutes: number;
    monthlyCost: number;
  };
}

export class UsageDashboard {
  private client;
  private projectId: string;

  constructor(apiKey: string, projectId: string) {
    this.client = createClient(apiKey);
    this.projectId = projectId;
  }

  async getUsageSummary(daysBack = 30): Promise<UsageSummary> {
    const end = new Date();
    const start = new Date(end.getTime() - daysBack * 24 * 60 * 60 * 1000);

    // Get usage data from Deepgram API
    const { result, error } = await this.client.manage.getProjectUsageRequest(
      this.projectId,
      {
        start: start.toISOString(),
        end: end.toISOString(),
      }
    );

    if (error) throw error;

    // Aggregate data
    const byModel: Record<string, { minutes: number; cost: number }> = {};
    const byDay: Map<string, { minutes: number; cost: number }> = new Map();

    let totalMinutes = 0;
    let totalCost = 0;

    for (const request of result.requests || []) {
      const minutes = (request.duration || 0) / 60;
      const model = request.model || 'unknown';
      const cost = this.calculateCost(minutes, model);
      const dateKey = new Date(request.created).toISOString().split('T')[0];

      totalMinutes += minutes;
      totalCost += cost;

      if (!byModel[model]) {
        byModel[model] = { minutes: 0, cost: 0 };
      }
      byModel[model].minutes += minutes;
      byModel[model].cost += cost;

      if (!byDay.has(dateKey)) {
        byDay.set(dateKey, { minutes: 0, cost: 0 });
      }
      const day = byDay.get(dateKey)!;
      day.minutes += minutes;
      day.cost += cost;
    }

    // Calculate projections
    const dailyAverage = totalMinutes / daysBack;
    const daysInMonth = 30;

    return {
      period: { start, end },
      totalMinutes,
      totalCost,
      byModel,
      byDay: Array.from(byDay.entries()).map(([date, data]) => ({
        date,
        ...data,
      })),
      projections: {
        monthlyMinutes: dailyAverage * daysInMonth,
        monthlyCost: (totalCost / daysBack) * daysInMonth,
      },
    };
  }

  private calculateCost(minutes: number, model: string): number {
    const rates: Record<string, number> = {
      'nova-2': 0.0043,
      'nova': 0.0043,
      'base': 0.0048,
      'enhanced': 0.0145,
    };
    return minutes * (rates[model] || 0.0043);
  }
}

Cost Alerts

// lib/​cost-alerts.ts
import { UsageDashboard } from './​usage-dashboard';

interface AlertConfig {
  dailyLimit: number;
  weeklyLimit: number;
  monthlyLimit: number;
  alertChannels: Array<'email' | 'slack' | 'webhook'>;
}

export class CostAlerts {
  private dashboard: UsageDashboard;
  private config: AlertConfig;
  private alertsSent: Set<string> = new Set();

  constructor(dashboard: UsageDashboard, config: Partial<AlertConfig> = {}) {
    this.dashboard = dashboard;
    this.config = {
      dailyLimit: config.dailyLimit ?? 10,
      weeklyLimit: config.weeklyLimit ?? 50,
      monthlyLimit: config.monthlyLimit ?? 200,
      alertChannels: config.alertChannels ?? ['email'],
    };
  }

  async checkAndAlert(): Promise<void> {
    const daily = await this.dashboard.getUsageSummary(1);
    const weekly = await this.dashboard.getUsageSummary(7);
    const monthly = await this.dashboard.getUsageSummary(30);

    const alerts: string[] = [];

    if (daily.totalCost > this.config.dailyLimit) {
      alerts.push(`Daily spend ($${daily.totalCost.toFixed(2)}) exceeds limit ($${this.config.dailyLimit})`);
    }

    if (weekly.totalCost > this.config.weeklyLimit) {
      alerts.push(`Weekly spend ($${weekly.totalCost.toFixed(2)}) exceeds limit ($${this.config.weeklyLimit})`);
    }

    if (monthly.totalCost > this.config.monthlyLimit) {
      alerts.push(`Monthly spend ($${monthly.totalCost.toFixed(2)}) exceeds limit ($${this.config.monthlyLimit})`);
    }

    // Send alerts (deduplicated)
    for (const alert of alerts) {
      const alertKey = `${new Date().toDateString()}-${alert}`;
      if (!this.alertsSent.has(alertKey)) {
        await this.sendAlert(alert);
        this.alertsSent.add(alertKey);
      }
    }
  }

  private async sendAlert(message: string): Promise<void> {
    console.log(`COST ALERT: ${message}`);

    for (const channel of this.config.alertChannels) {
      switch (channel) {
        case 'slack':
          await this.sendSlackAlert(message);
          break;
        case 'email':
          await this.sendEmailAlert(message);
          break;
        case 'webhook':
          await this.sendWebhookAlert(message);
          break;
      }
    }
  }

  private async sendSlackAlert(message: string): Promise<void> {
    const webhookUrl = process.env.SLACK_WEBHOOK_URL;
    if (!webhookUrl) return;

    await fetch(webhookUrl, {
      method: 'POST',
      headers: { 'Content-Type': 'application/​json' },
      body: JSON.stringify({
        text: `Deepgram Cost Alert: ${message}`,
      }),
    });
  }

  private async sendEmailAlert(message: string): Promise<void> {
    // Implement email sending
  }

  private async sendWebhookAlert(message: string): Promise<void> {
    // Implement webhook sending
  }
}

Model Selection for Cost

// lib/​cost-aware-model.ts
interface ModelRecommendation {
  model: string;
  estimatedCost: number;
  qualityLevel: 'high' | 'medium' | 'low';
  reason: string;
}

export function recommendModel(params: {
  audioDurationMinutes: number;
  monthlyBudget: number;
  currentMonthSpend: number;
  qualityRequirement: 'high' | 'medium' | 'any';
}): ModelRecommendation {
  const { audioDurationMinutes, monthlyBudget, currentMonthSpend, qualityRequirement } = params;
  const budgetRemaining = monthlyBudget - currentMonthSpend;

  const models = [
    { name: 'nova-2', rate: 0.0043, quality: 'high' as const },
    { name: 'nova', rate: 0.0043, quality: 'high' as const },
    { name: 'base', rate: 0.0048, quality: 'low' as const },
  ];

  // Filter by quality requirement
  const eligible = models.filter(m => {
    if (qualityRequirement === 'high') return m.quality === 'high';
    if (qualityRequirement === 'medium') return m.quality !== 'low';
    return true;
  });

  // Find cheapest that fits budget
  for (const model of eligible.sort((a, b) => a.rate - b.rate)) {
    const cost = audioDurationMinutes * model.rate;
    if (cost <= budgetRemaining) {
      return {
        model: model.name,
        estimatedCost: cost,
        qualityLevel: model.quality,
        reason: `Best value within budget ($${budgetRemaining.toFixed(2)} remaining)`,
      };
    }
  }

  // Fallback to cheapest
  const cheapest = eligible[0];
  return {
    model: cheapest.name,
    estimatedCost: audioDurationMinutes * cheapest.rate,
    qualityLevel: cheapest.quality,
    reason: 'Warning: May exceed budget',
  };
}

Resources

Next Steps

Proceed to deepgram-reference-architecture for architecture patterns.

More skills from Dicklesworthstone

environment-setup-guide logo
Dicklesworthstone/pi_agent_rust

environment-setup-guide

Guide developers through setting up development environments with proper tools, dependencies, and configurations

1.8K 0
View
exa-policy-guardrails logo
Dicklesworthstone/pi_agent_rust

exa-policy-guardrails

Implement Exa lint rules, policy enforcement, and automated guardrails. Use when setting up code quality rules for Exa integrations, implementing pre-commit hooks, or configuring CI policy checks for Exa best practices. Trigger with phrases like "exa policy", "exa lint", "exa guardrails", "exa be...

1.8K 0
View
documenso-ci-integration logo
Dicklesworthstone/pi_agent_rust

documenso-ci-integration

Configure CI/CD pipelines for Documenso integrations. Use when setting up automated testing, deployment pipelines, or continuous integration for Documenso projects. Trigger with phrases like "documenso CI", "documenso GitHub Actions", "documenso pipeline", "documenso automated testing".

1.8K 0
View
openrouter-model-availability logo
Dicklesworthstone/pi_agent_rust

openrouter-model-availability

Build check model availability and implement fallback chains. Use when building resilient systems or handling model outages. Trigger with phrases like 'openrouter availability', 'openrouter fallback', 'openrouter model down', 'openrouter health check'.

1.8K 0
View
langfuse-enterprise-rbac logo
Dicklesworthstone/pi_agent_rust

langfuse-enterprise-rbac

Configure Langfuse enterprise organization management and access control. Use when implementing team access controls, configuring organization settings, or setting up role-based permissions for Langfuse projects. Trigger with phrases like "langfuse RBAC", "langfuse teams", "langfuse organization"...

1.8K 0
View
cursor-compliance-audit logo
Dicklesworthstone/pi_agent_rust

cursor-compliance-audit

Execute compliance and security auditing for Cursor usage. Triggers on "cursor compliance", "cursor audit", "cursor security review", "cursor soc2", "cursor gdpr". Use when analyzing or auditing cursor compliance audit. Trigger with phrases like "cursor compliance audit", "cursor audit", "cursor".

1.8K 0
View
apollo-ci-integration logo
Dicklesworthstone/pi_agent_rust

apollo-ci-integration

Configure Apollo.io CI/CD integration. Use when setting up automated testing, continuous integration, or deployment pipelines for Apollo integrations. Trigger with phrases like "apollo ci", "apollo github actions", "apollo pipeline", "apollo ci/cd", "apollo automated tests".

1.8K 0
View
python-script logo
Dicklesworthstone/pi_agent_rust

python-script

Create robust Python automation with full logging and safety checks. Use when tasks need complex data processing, authenticated API work, conditional file operations, or error handling beyond simple shell commands.

1.8K 0
View
posthog-multi-env-setup logo
Dicklesworthstone/pi_agent_rust

posthog-multi-env-setup

Configure PostHog across development, staging, and production environments. Use when setting up multi-environment deployments, configuring per-environment secrets, or implementing environment-specific PostHog configurations. Trigger with phrases like "posthog environments", "posthog staging", "po...

1.8K 0
View
ai-agents-architect logo
Dicklesworthstone/pi_agent_rust

ai-agents-architect

Expert in designing and building autonomous AI agents. Masters tool use, memory systems, planning strategies, and multi-agent orchestration. Use when: build agent, AI agent, autonomous agent, tool use, function calling.

1.8K 0
View
insecure-deserialization-checker logo
Dicklesworthstone/pi_agent_rust

insecure-deserialization-checker

Validate insecure deserialization checker operations. Auto-activating skill for Security Fundamentals. Triggers on: insecure deserialization checker, insecure deserialization checker Part of the Security Fundamentals skill category. Use when working with insecure deserialization checker functiona...

1.8K 0
View
path-traversal-finder logo
Dicklesworthstone/pi_agent_rust

path-traversal-finder

Manage path traversal finder operations. Auto-activating skill for Security Fundamentals. Triggers on: path traversal finder, path traversal finder Part of the Security Fundamentals skill category. Use when working with path traversal finder functionality. Trigger with phrases like "path traversa...

1.8K 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View