Session Management Best Practices
Overview
The Streaming API sessions encapsulate live user interaction (voice activity, tasks, etc.). Proper session lifecycle management ensures predictable session closure, avoids resource leakage, and helps surface issues like unclosed sessions that can lead to quota/concurrency errors.
To simplify and harden session management, we are deprecating the previous disable_idle_timeout mechanism and introduced:
- activity_idle_timeout in /v1/streaming.new — a bounded idle threshold based on actual user activity.
- /v1/streaming.keep_alive — a RESTful endpoint to explicitly reset the idle timer when needed.
Session Timeout Configuration
- Purpose: Defines how long a session can remain without user activity before it is automatically closed.
- Valid range: ≥ 30 seconds and < 3600 seconds.
- Default: 120 seconds.
- Activity sources: Includes user tasks, voice input, or other detectable interaction events.
- Behavior: The idle timer is reset on activity; if the threshold elapses with no activity, the session is closed automatically.
- Purpose: Explicitly resets the idle timer for an existing session, useful when the client knows the user is still present but no discrete “activity” event has fired.
- Usage pattern: Call prior to the expiration of activity_idle_timeout to keep the session alive during expected quiet periods.
Example (curl):
curl -X POST <https://api.heygen.com/v1/streaming.keep_alive>
-H "Authorization: Bearer $API_KEY"
-H "Content-Type: application/json"
-d '{"session_id": "abc123"}'
Recommendations & Operational Notes
- Set disable_idle_timeout to false. (It will soon be deprecated)
- Tune activity_idle_timeout to match the natural interaction cadence of your application: short for highly interactive flows, longer for sessions with expected pauses.
- Use /v1/streaming.keep_alive when you have periods without detectable activity but still consider the session “alive” from the user’s perspective.
- Monitor for concurrent limit errors. Consistent “concurrent limit” or quota-style errors often indicate unclosed (stale) sessions hanging around.
- If a developer suspects such unclosed sessions are the cause, they can reach out to HeyGen support; support can inspect and manually close lingering sessions to relieve the issue.
FAQ
Q: Why should disable_idle_timeout be false if I want to keep a session alive indefinitely?
A: There is no “forever” mode. Instead, use an appropriately high activity_idle_timeout (up to 3599s) and complement with keep-alives during known quiet periods. disable_idle_timeout is deprecated because it led to unstable session lifecycles.
Q: What do I do if my integration keeps hitting concurrent session limits?
A: First, audit for unclosed/stale sessions (e.g., sessions that didn’t get properly terminated). If unclear, contact HeyGen support—support can manually close problematic sessions to free up capacity.
Updated about 1 month ago