Skip to content

Commit d473df6

Browse files
committed
fix(auth): use correct precedence for new api key / access token work
1 parent c7dc37c commit d473df6

File tree

13 files changed

+34
-29
lines changed

13 files changed

+34
-29
lines changed

deepgram/client.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,19 +446,20 @@ def __init__(
446446

447447
# Handle credential extraction from config first
448448
if api_key == "" and access_token == "" and config is not None:
449-
self._logger.info("Attempting to set credentials from config object")
449+
self._logger.info(
450+
"Attempting to set credentials from config object")
450451
api_key = config.api_key
451452
access_token = config.access_token
452453

453454
# Fallback to environment variables if no explicit credentials provided
454-
# Prioritize API key for backward compatibility
455+
# Prioritize access token over API key
455456
if api_key == "" and access_token == "":
456457
self._logger.info(
457458
"Attempting to get credentials from environment variables"
458459
)
459-
api_key = os.getenv("DEEPGRAM_API_KEY", "")
460-
if api_key == "":
461-
access_token = os.getenv("DEEPGRAM_ACCESS_TOKEN", "")
460+
access_token = os.getenv("DEEPGRAM_ACCESS_TOKEN", "")
461+
if access_token == "":
462+
api_key = os.getenv("DEEPGRAM_API_KEY", "")
462463

463464
# Log warnings for missing credentials
464465
if api_key == "" and access_token == "":

deepgram/options.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ def is_auto_flush_reply_enabled(self) -> bool:
142142
"""
143143
is_auto_flush_reply_enabled: Returns True if the client is configured to auto-flush for listen.
144144
"""
145-
auto_flush_reply_delta = float(self.options.get("auto_flush_reply_delta", 0))
145+
auto_flush_reply_delta = float(
146+
self.options.get("auto_flush_reply_delta", 0))
146147
return (
147148
isinstance(auto_flush_reply_delta, numbers.Number)
148149
and auto_flush_reply_delta > 0
@@ -152,7 +153,8 @@ def is_auto_flush_speak_enabled(self) -> bool:
152153
"""
153154
is_auto_flush_speak_enabled: Returns True if the client is configured to auto-flush for speak.
154155
"""
155-
auto_flush_speak_delta = float(self.options.get("auto_flush_speak_delta", 0))
156+
auto_flush_speak_delta = float(
157+
self.options.get("auto_flush_speak_delta", 0))
156158
return (
157159
isinstance(auto_flush_speak_delta, numbers.Number)
158160
and auto_flush_speak_delta > 0
@@ -198,17 +200,17 @@ def __init__(
198200
if access_token is None:
199201
access_token = ""
200202

201-
# Prioritize API key for backward compatibility, fallback to access token
202-
# This ensures existing DEEPGRAM_API_KEY users continue working as before
203-
if api_key == "":
204-
api_key = os.getenv("DEEPGRAM_API_KEY", "")
205-
206-
if access_token == "" and api_key == "":
203+
# Prioritize access token over API key
204+
if access_token == "":
207205
access_token = os.getenv("DEEPGRAM_ACCESS_TOKEN", "")
208206

207+
if api_key == "" and access_token == "":
208+
api_key = os.getenv("DEEPGRAM_API_KEY", "")
209+
209210
# Require at least one form of authentication
210211
if api_key == "" and access_token == "":
211-
self._logger.critical("Neither Deepgram API KEY nor ACCESS TOKEN is set")
212+
self._logger.critical(
213+
"Neither Deepgram API KEY nor ACCESS TOKEN is set")
212214
raise DeepgramApiKeyError(
213215
"Neither Deepgram API KEY nor ACCESS TOKEN is set"
214216
)
@@ -260,7 +262,8 @@ def __init__(
260262
for x in range(0, 20):
261263
header = os.getenv(f"DEEPGRAM_HEADER_{x}", None)
262264
if header is not None:
263-
headers[header] = os.getenv(f"DEEPGRAM_HEADER_VALUE_{x}", None)
265+
headers[header] = os.getenv(
266+
f"DEEPGRAM_HEADER_VALUE_{x}", None)
264267
self._logger.debug(
265268
"Deepgram header %s is set with value %s",
266269
header,
@@ -277,7 +280,8 @@ def __init__(
277280
for x in range(0, 20):
278281
param = os.getenv(f"DEEPGRAM_PARAM_{x}", None)
279282
if param is not None:
280-
options[param] = os.getenv(f"DEEPGRAM_PARAM_VALUE_{x}", None)
283+
options[param] = os.getenv(
284+
f"DEEPGRAM_PARAM_VALUE_{x}", None)
281285
self._logger.debug(
282286
"Deepgram option %s is set with value %s", param, options[param]
283287
)
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"metadata": {"transaction_key": "deprecated", "request_id": "3aa706dc-6029-41dd-8443-91928c2e178c", "sha256": "5324da68ede209a16ac69a38e8cd29cee4d754434a041166cda3a1f5e0b24566", "created": "2025-06-22T16:41:03.304Z", "duration": 17.566313, "channels": 1, "models": ["3b3aabe4-608a-46ac-9585-7960a25daf1a"], "model_info": {"3b3aabe4-608a-46ac-9585-7960a25daf1a": {"name": "general-nova-3", "version": "2024-12-20.0", "arch": "nova-3"}}, "summary_info": {"model_uuid": "67875a7f-c9c4-48a0-aa55-5bdb8a91c34a", "input_tokens": 0, "output_tokens": 0}}, "results": {"channels": [{"alternatives": [{"transcript": "Yep. I said it before, and I'll say it again. Life moves pretty fast. You don't stop and look around once in a while, you could miss it.", "confidence": 0.9991429, "words": [{"word": "yep", "start": 5.52, "end": 6.2400002, "confidence": 0.92344034, "punctuated_word": "Yep."}, {"word": "i", "start": 6.96, "end": 7.2799997, "confidence": 0.5774878, "punctuated_word": "I"}, {"word": "said", "start": 7.2799997, "end": 7.52, "confidence": 0.90520746, "punctuated_word": "said"}, {"word": "it", "start": 7.52, "end": 7.68, "confidence": 0.9979729, "punctuated_word": "it"}, {"word": "before", "start": 7.68, "end": 8.08, "confidence": 0.89339864, "punctuated_word": "before,"}, {"word": "and", "start": 8.08, "end": 8.16, "confidence": 0.99981827, "punctuated_word": "and"}, {"word": "i'll", "start": 8.16, "end": 8.4, "confidence": 0.99961716, "punctuated_word": "I'll"}, {"word": "say", "start": 8.4, "end": 8.48, "confidence": 0.99941754, "punctuated_word": "say"}, {"word": "it", "start": 8.48, "end": 8.639999, "confidence": 0.999597, "punctuated_word": "it"}, {"word": "again", "start": 8.639999, "end": 8.96, "confidence": 0.95282805, "punctuated_word": "again."}, {"word": "life", "start": 10.071313, "end": 10.311313, "confidence": 0.9990012, "punctuated_word": "Life"}, {"word": "moves", "start": 10.311313, "end": 10.631312, "confidence": 0.9996643, "punctuated_word": "moves"}, {"word": "pretty", "start": 10.631312, "end": 11.031313, "confidence": 0.99988604, "punctuated_word": "pretty"}, {"word": "fast", "start": 11.031313, "end": 11.671312, "confidence": 0.9989685, "punctuated_word": "fast."}, {"word": "you", "start": 12.071312, "end": 12.311313, "confidence": 0.92013574, "punctuated_word": "You"}, {"word": "don't", "start": 12.311313, "end": 12.551312, "confidence": 0.99986017, "punctuated_word": "don't"}, {"word": "stop", "start": 12.551312, "end": 12.791312, "confidence": 0.99976414, "punctuated_word": "stop"}, {"word": "and", "start": 12.791312, "end": 12.951312, "confidence": 0.99852234, "punctuated_word": "and"}, {"word": "look", "start": 12.951312, "end": 13.111313, "confidence": 0.9998677, "punctuated_word": "look"}, {"word": "around", "start": 13.111313, "end": 13.351313, "confidence": 0.9998548, "punctuated_word": "around"}, {"word": "once", "start": 13.351313, "end": 13.671312, "confidence": 0.9991429, "punctuated_word": "once"}, {"word": "in", "start": 13.671312, "end": 13.831312, "confidence": 0.9976285, "punctuated_word": "in"}, {"word": "a", "start": 13.831312, "end": 13.911312, "confidence": 0.98508644, "punctuated_word": "a"}, {"word": "while", "start": 13.911312, "end": 14.391312, "confidence": 0.9349544, "punctuated_word": "while,"}, {"word": "you", "start": 14.711312, "end": 14.871312, "confidence": 0.99921596, "punctuated_word": "you"}, {"word": "could", "start": 14.871312, "end": 15.031313, "confidence": 0.99974436, "punctuated_word": "could"}, {"word": "miss", "start": 15.031313, "end": 15.271313, "confidence": 0.9997111, "punctuated_word": "miss"}, {"word": "it", "start": 15.271313, "end": 15.5113125, "confidence": 0.99891466, "punctuated_word": "it."}], "paragraphs": {"transcript": "\nYep. I said it before, and I'll say it again. Life moves pretty fast. You don't stop and look around once in a while, you could miss it.", "paragraphs": [{"sentences": [{"text": "Yep.", "start": 5.52, "end": 6.2400002}, {"text": "I said it before, and I'll say it again.", "start": 6.96, "end": 8.96}, {"text": "Life moves pretty fast.", "start": 10.071313, "end": 11.671312}, {"text": "You don't stop and look around once in a while, you could miss it.", "start": 12.071312, "end": 15.5113125}], "start": 5.52, "end": 15.5113125, "num_words": 28}]}}]}], "summary": {"result": "success", "short": "Yep. I said it before, and I'll say it again. Life moves pretty fast. You don't stop and look around once in a while, you could miss it."}}}
1+
{"metadata": {"transaction_key": "deprecated", "request_id": "ecae8f5b-ce66-40e3-b66c-41f6e2affe68", "sha256": "5324da68ede209a16ac69a38e8cd29cee4d754434a041166cda3a1f5e0b24566", "created": "2025-06-22T16:50:02.280Z", "duration": 17.566313, "channels": 1, "models": ["3b3aabe4-608a-46ac-9585-7960a25daf1a"], "model_info": {"3b3aabe4-608a-46ac-9585-7960a25daf1a": {"name": "general-nova-3", "version": "2024-12-20.0", "arch": "nova-3"}}, "summary_info": {"model_uuid": "67875a7f-c9c4-48a0-aa55-5bdb8a91c34a", "input_tokens": 0, "output_tokens": 0}}, "results": {"channels": [{"alternatives": [{"transcript": "Yep. I said it before, and I'll say it again. Life moves pretty fast. You don't stop and look around once in a while, you could miss it.", "confidence": 0.9991429, "words": [{"word": "yep", "start": 5.52, "end": 6.2400002, "confidence": 0.92345256, "punctuated_word": "Yep."}, {"word": "i", "start": 6.96, "end": 7.2799997, "confidence": 0.5776232, "punctuated_word": "I"}, {"word": "said", "start": 7.2799997, "end": 7.52, "confidence": 0.9052255, "punctuated_word": "said"}, {"word": "it", "start": 7.52, "end": 7.68, "confidence": 0.9979741, "punctuated_word": "it"}, {"word": "before", "start": 7.68, "end": 8.08, "confidence": 0.89339817, "punctuated_word": "before,"}, {"word": "and", "start": 8.08, "end": 8.16, "confidence": 0.99981827, "punctuated_word": "and"}, {"word": "i'll", "start": 8.16, "end": 8.4, "confidence": 0.99961734, "punctuated_word": "I'll"}, {"word": "say", "start": 8.4, "end": 8.48, "confidence": 0.99941754, "punctuated_word": "say"}, {"word": "it", "start": 8.48, "end": 8.639999, "confidence": 0.99959713, "punctuated_word": "it"}, {"word": "again", "start": 8.639999, "end": 8.96, "confidence": 0.95283747, "punctuated_word": "again."}, {"word": "life", "start": 10.071313, "end": 10.311313, "confidence": 0.9990012, "punctuated_word": "Life"}, {"word": "moves", "start": 10.311313, "end": 10.631312, "confidence": 0.9996643, "punctuated_word": "moves"}, {"word": "pretty", "start": 10.631312, "end": 11.031313, "confidence": 0.99988604, "punctuated_word": "pretty"}, {"word": "fast", "start": 11.031313, "end": 11.671312, "confidence": 0.99896836, "punctuated_word": "fast."}, {"word": "you", "start": 12.071312, "end": 12.311313, "confidence": 0.9201446, "punctuated_word": "You"}, {"word": "don't", "start": 12.311313, "end": 12.551312, "confidence": 0.99986017, "punctuated_word": "don't"}, {"word": "stop", "start": 12.551312, "end": 12.791312, "confidence": 0.99976414, "punctuated_word": "stop"}, {"word": "and", "start": 12.791312, "end": 12.951312, "confidence": 0.998522, "punctuated_word": "and"}, {"word": "look", "start": 12.951312, "end": 13.111313, "confidence": 0.9998677, "punctuated_word": "look"}, {"word": "around", "start": 13.111313, "end": 13.351313, "confidence": 0.9998548, "punctuated_word": "around"}, {"word": "once", "start": 13.351313, "end": 13.671312, "confidence": 0.9991429, "punctuated_word": "once"}, {"word": "in", "start": 13.671312, "end": 13.831312, "confidence": 0.9976286, "punctuated_word": "in"}, {"word": "a", "start": 13.831312, "end": 13.911312, "confidence": 0.9850873, "punctuated_word": "a"}, {"word": "while", "start": 13.911312, "end": 14.391312, "confidence": 0.9349425, "punctuated_word": "while,"}, {"word": "you", "start": 14.711312, "end": 14.871312, "confidence": 0.99921596, "punctuated_word": "you"}, {"word": "could", "start": 14.871312, "end": 15.031313, "confidence": 0.99974436, "punctuated_word": "could"}, {"word": "miss", "start": 15.031313, "end": 15.271313, "confidence": 0.9997111, "punctuated_word": "miss"}, {"word": "it", "start": 15.271313, "end": 15.5113125, "confidence": 0.9989148, "punctuated_word": "it."}], "paragraphs": {"transcript": "\nYep. I said it before, and I'll say it again. Life moves pretty fast. You don't stop and look around once in a while, you could miss it.", "paragraphs": [{"sentences": [{"text": "Yep.", "start": 5.52, "end": 6.2400002}, {"text": "I said it before, and I'll say it again.", "start": 6.96, "end": 8.96}, {"text": "Life moves pretty fast.", "start": 10.071313, "end": 11.671312}, {"text": "You don't stop and look around once in a while, you could miss it.", "start": 12.071312, "end": 15.5113125}], "start": 5.52, "end": 15.5113125, "num_words": 28}]}}]}], "summary": {"result": "success", "short": "Yep. I said it before, and I'll say it again. Life moves pretty fast. You don't stop and look around once in a while, you could miss it."}}}

0 commit comments

Comments
 (0)