Skip to content

[Enhancement] Add streaming session rate limiter with automatic backpressure and retry for concurrent connections #748

Description

@deepgram-robot

Summary

Add a built-in rate limiter to the Python SDK that manages concurrent WebSocket streaming sessions, automatically handles HTTP 429 responses with exponential backoff, and provides backpressure signaling when approaching rate limits. This enables developers to safely run multiple concurrent streaming sessions without manually implementing rate limiting logic.

Problem it solves

Developers running multiple concurrent streaming sessions (e.g., transcribing multiple audio streams in a call center, batch-processing recordings with parallel streams) frequently encounter HTTP 429 errors when they exceed their plan's connection limits. Currently, each developer must implement their own retry logic with exponential backoff, track active connection counts, and handle rate limit headers — a pattern that is error-prone and repeated across every production deployment.

Proposed API

from deepgram import DeepgramClient, RateLimitConfig

# Configure rate limiting at client level
client = DeepgramClient(
    api_key="...",
    rate_limit=RateLimitConfig(
        max_concurrent_streams=10,     # Max concurrent WebSocket connections
        retry_on_429=True,             # Auto-retry with backoff on 429
        max_retries=3,                 # Max retry attempts
        backoff_base=1.0,              # Base backoff in seconds
    )
)

# Sessions automatically respect rate limits
async with client.listen.v2.connect(options) as session:
    # If max_concurrent_streams reached, this blocks until a slot opens
    await session.send(audio_data)

# Or check availability before connecting
if client.rate_limit.available_slots > 0:
    session = await client.listen.v2.connect(options)

Acceptance criteria

  • Tracks active WebSocket connection count across all client instances
  • Blocks new connections when max_concurrent_streams is reached (with configurable timeout)
  • Automatically retries on HTTP 429 with exponential backoff
  • Exposes available_slots and active_connections properties for monitoring
  • Documented with usage example
  • Compatible with existing API (opt-in via RateLimitConfig, no breaking changes)

Raised by the DX intelligence system.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions