Skip to content

deepgram-stt: report connection-lifetime remainder so usage matches billing#5506

Open
joaquinhuigomez wants to merge 1 commit intolivekit:mainfrom
joaquinhuigomez:fix/deepgram-stt-connection-duration
Open

deepgram-stt: report connection-lifetime remainder so usage matches billing#5506
joaquinhuigomez wants to merge 1 commit intolivekit:mainfrom
joaquinhuigomez:fix/deepgram-stt-connection-duration

Conversation

@joaquinhuigomez
Copy link
Copy Markdown
Contributor

STTMetrics.audio_duration accumulated only the duration of audio frames pushed to the Deepgram WebSocket via the PeriodicCollector. Deepgram bills for the full WebSocket connection lifetime, so cost-tracking users saw a consistent 4–5 s per-stream undercount against Deepgram's usage reports (much worse on short calls, ~17% on a 20 s call).

Track the connection open timestamp and the total duration already reported via _on_audio_duration_report, and on close emit any remainder between wall-clock connection lifetime and reported frames. The collector is also flushed before the remainder calc so pending frame duration is accounted for first.

Fixes #5498

…illing

STTMetrics.audio_duration accumulated only the duration of audio frames
pushed to the Deepgram WebSocket via the PeriodicCollector. Deepgram
bills for the full WebSocket connection lifetime, so cost-tracking
users saw a consistent 4–5 s per-stream undercount against Deepgram's
usage reports (much worse on short calls).

Track the connection open timestamp and the total duration already
reported via _on_audio_duration_report, and on close emit any
remainder between wall-clock connection lifetime and reported frames.
The collector is also flushed before the remainder calc so pending
frame duration is accounted for first.

Fixes livekit#5498
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stt_audio_duration in UsageSummary doesn't match Deepgram billed duration (~4-5s fixed undercount per stream)

3 participants