| name | deepgram-cost-tuning |
| description | 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 deepgram usage".
|
| allowed-tools | Read, Write, Edit, Bash(gh:*), Bash(curl:*) |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
Deepgram Cost Tuning
Overview
Optimize Deepgram usage and costs through smart model selection, audio preprocessing, and usage monitoring.
Deepgram Pricing Overview
| Model | Price per Minute | Best For |
|---|
| Nova-2 | $0.0043 | General transcription |
| Nova | $0.0043 | General transcription |
| Whisper Cloud | $0.0048 | Multilingual |
| Enhanced | $0.0145 | Legacy support |
| Base | $0.0048 | Basic 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
import { createClient } from '@deepgram/sdk';
interface CostConfig {
maxMonthlySpend: number;
warningThreshold: number;
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: , : <> = {}) {
. = (apiKey);
. = {
: config. ?? ,
: config. ?? ,
: config. ?? ,
: config. ?? {
: ,
: ,
},
};
. = {
: ,
: ,
: ,
};
}
(: ): {
cost = durationMinutes * .[..];
(...) {
cost += durationMinutes * ;
}
cost;
}
(: ): {
estimatedCost = .(estimatedMinutes);
projectedTotal = .. + estimatedCost;
(projectedTotal > ..) {
();
}
percentage = (projectedTotal / ..) * ;
(percentage >= ..) {
.();
}
}
() {
.(estimatedDurationMinutes);
startTime = .();
{ result, error } = ....(
{ : audioUrl },
{
: ..,
: ...,
: ...,
}
);
(error) error;
actualDuration = result.. / ;
cost = .(actualDuration);
.. += actualDuration;
.. += cost;
{
: result..[].[].,
: {
: actualDuration,
cost,
: ..,
},
};
}
(): & { : } {
{
....,
: .. - ..,
};
}
}
Audio Duration Reducer
import ffmpeg from 'fluent-ffmpeg';
interface ReductionOptions {
silenceThreshold: string;
silenceMinDuration: number;
speed: number;
}
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 = (data.);
})
.([
,
,
...(speed !== ? [] : []),
])
.(outputPath)
.(, {
ffmpeg.(outputPath, {
(err) (err);
reducedDuration = metadata.. || ;
({
originalDuration,
reducedDuration,
: ((originalDuration - reducedDuration) / originalDuration) * ,
});
});
})
.(, reject)
.();
});
}
(): {
parts = duration.().();
parts[] * + parts[] * + parts[];
}
Usage Dashboard
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;
}
(daysBack = ): <> {
end = ();
start = (end.() - daysBack * * * * );
{ result, error } = ...(
.,
{
: start.(),
: end.(),
}
);
(error) error;
: <, { : ; : }> = {};
: <, { : ; : }> = ();
totalMinutes = ;
totalCost = ;
( request result. || []) {
minutes = (request. || ) / ;
model = request. || ;
cost = .(minutes, model);
dateKey = (request.).().()[];
totalMinutes += minutes;
totalCost += cost;
(!byModel[model]) {
byModel[model] = { : , : };
}
byModel[model]. += minutes;
byModel[model]. += cost;
(!byDay.(dateKey)) {
byDay.(dateKey, { : , : });
}
day = byDay.(dateKey)!;
day. += minutes;
day. += cost;
}
dailyAverage = totalMinutes / daysBack;
daysInMonth = ;
{
: { start, end },
totalMinutes,
totalCost,
byModel,
: .(byDay.()).( ({
date,
...data,
})),
: {
: dailyAverage * daysInMonth,
: (totalCost / daysBack) * daysInMonth,
},
};
}
(: , : ): {
: <, > = {
: ,
: ,
: ,
: ,
};
minutes * (rates[model] || );
}
}
Cost Alerts
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 ?? ,
: config. ?? [],
};
}
(): <> {
daily = ..();
weekly = ..();
monthly = ..();
: [] = [];
(daily. > ..) {
alerts.();
}
(weekly. > ..) {
alerts.();
}
(monthly. > ..) {
alerts.();
}
( alert alerts) {
alertKey = ;
(!..(alertKey)) {
.(alert);
..(alertKey);
}
}
}
(: ): <> {
.();
( channel ..) {
(channel) {
:
.(message);
;
:
.(message);
;
:
.(message);
;
}
}
}
(: ): <> {
webhookUrl = process..;
(!webhookUrl) ;
(webhookUrl, {
: ,
: { : },
: .({
: ,
}),
});
}
(: ): <> {
}
(: ): <> {
}
}
Model Selection for Cost
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 },
];
eligible = models.( {
(qualityRequirement === ) m. === ;
(qualityRequirement === ) m. !== ;
;
});
( model eligible.( a. - b.)) {
cost = audioDurationMinutes * model.;
(cost <= budgetRemaining) {
{
: model.,
: cost,
: model.,
: ,
};
}
}
cheapest = eligible[];
{
: cheapest.,
: audioDurationMinutes * cheapest.,
: cheapest.,
: ,
};
}
Resources
Next Steps
Proceed to deepgram-reference-architecture for architecture patterns.