Skip to content

fix(client): copy custom headers before adding the session id - #825

Open
RaphaelFakhri wants to merge 1 commit into
deepgram:mainfrom
RaphaelFakhri:fix/client-shared-headers-session-id
Open

RaphaelFakhri wants to merge 1 commit into
deepgram:mainfrom
RaphaelFakhri:fix/client-shared-headers-session-id

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Summary

DeepgramClient and AsyncDeepgramClient add x-deepgram-session-id directly to the headers dict that the caller passes in. The generated client wrapper stores a reference to that dict, so clients built from one shared dict all send the session ID of the last client created, and the caller's dict changes.

This change copies headers before the session header is added, in both clients.

Changes

  • src/deepgram/client.py: copy the caller's headers into a new dict before setting x-deepgram-session-id.
  • tests/custom/test_client_construction_and_helpers.py: add a test that builds two clients from one shared dict and checks that each client sends its own session_id and that the shared dict is unchanged.

Testing

  • New test fails on main (2 failed: the first client sends the second client's session ID) and passes with the fix (2 passed).
  • pytest tests/custom tests/utils: 1081 passed, 1 skipped.
  • ruff check and mypy pass on the changed files.

Fixes #824

Copilot AI balanced review requested due to automatic review settings November 3, 2026 15:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
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.

[Bug]: Clients that share a headers dict send the wrong x-deepgram-session-id

2 participants