Skip to content

feat(sdk): allow transcribe() without api_key for whisper and parakeet - #13087

Open
Aj2280 wants to merge 1 commit into
BasedHardware:mainfrom
Aj2280:feat/sdk-transcribe-optional-api-key
Open

feat(sdk): allow transcribe() without api_key for whisper and parakeet#13087
Aj2280 wants to merge 1 commit into
BasedHardware:mainfrom
Aj2280:feat/sdk-transcribe-optional-api-key

Conversation

@Aj2280

@Aj2280 Aj2280 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary

In sdks/python/omi/transcribe.py, the public wrapper function transcribe() previously declared api_key: str as a required positional argument, even though the Whisper and Parakeet engines do not accept or require an API key. This forced callers using Whisper or Parakeet to provide a dummy API key string, e.g. await transcribe(queue, "dummy", engine="whisper").

This PR makes api_key optional (api_key: Optional[str] = None) in transcribe() and validates that a key is provided only when the Deepgram engine is active. Existing calls passing Deepgram keys positionally or by keyword continue to work unchanged.

Fixes #13042

Changes

  • sdks/python/omi/transcribe.py:
    • Updated signature to api_key: Optional[str] = None.
    • Allowed positional callable arguments to bind to on_transcript when no API key is needed.
    • Enforced ValueError("Deepgram api_key is required") only when engine == SttEngine.DEEPGRAM.value.
  • sdks/python/tests/test_transcribe_wrapper.py:
    • Added unit tests for:
      • Deepgram requiring API key when not provided.
      • Deepgram accepting positional API key.
      • Deepgram accepting keyword API key.
      • Whisper working without an API key.
      • Parakeet working without an API key.
      • Positional callable automatically binding to on_transcript.

Verification

  • Automated Tests:
    • PYTHONPATH=sdks/python sdks/python/venv/bin/pytest sdks/python/tests/test_transcribe_wrapper.py -v: 6/6 passed.
    • PYTHONPATH=sdks/python sdks/python/venv/bin/pytest sdks/python/tests/: 13/13 passed.
  • Manifest Preflight:
    • Validated with scripts/pr-preflight.

Failure-Class: none

Review in cubic

In `sdks/python/omi/transcribe.py`, `transcribe()` required a positional
`api_key` argument even when using engines (like Whisper and Parakeet)
that do not use or require an API key.

Make `api_key: Optional[str] = None` and enforce key validation only
when Deepgram is selected.

Fixes BasedHardware#13042

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 2 files

Confidence score: 5/5

  • In sdks/python/tests/test_transcribe_wrapper.py, test_whisper_does_not_require_api_key derives the expected runner from the mocked call itself, so an incorrect value forwarded by transcribe() would still pass the test; define the expected runner independently and assert against it.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="sdks/python/tests/test_transcribe_wrapper.py">

<violation number="1" location="sdks/python/tests/test_transcribe_wrapper.py:57">
P3: The runner assertion in `test_whisper_does_not_require_api_key` is tautological: it builds the expected value from `mock_create.call_args[1]["runner"]`, so it passes no matter what `transcribe()` forwards. Capture the runner in a variable and assert it is forwarded unchanged so the test actually detects a regression.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

await transcribe(queue, engine="whisper", runner=lambda b: "hello")
mock_create.assert_called_once_with(
SttEngine.WHISPER.value,
runner=mock_create.call_args[1]["runner"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P3: The runner assertion in test_whisper_does_not_require_api_key is tautological: it builds the expected value from mock_create.call_args[1]["runner"], so it passes no matter what transcribe() forwards. Capture the runner in a variable and assert it is forwarded unchanged so the test actually detects a regression.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At sdks/python/tests/test_transcribe_wrapper.py, line 57:

<comment>The runner assertion in `test_whisper_does_not_require_api_key` is tautological: it builds the expected value from `mock_create.call_args[1]["runner"]`, so it passes no matter what `transcribe()` forwards. Capture the runner in a variable and assert it is forwarded unchanged so the test actually detects a regression.</comment>

<file context>
@@ -0,0 +1,91 @@
+            await transcribe(queue, engine="whisper", runner=lambda b: "hello")
+            mock_create.assert_called_once_with(
+                SttEngine.WHISPER.value,
+                runner=mock_create.call_args[1]["runner"]
+            )
+
</file context>

@Git-on-my-level

Copy link
Copy Markdown
Collaborator

Thanks @Aj2280 — this is a tidy, well-scoped fix for #13042, and it's verified end to end.

sdks/python/omi/transcribe.py

  • The signature change (api_key: Optional[str] = None) is backwards-compatible: existing transcribe(queue, "key") positional and api_key= keyword calls behave identically, and the README's Deepgram example stays valid as-is.
  • The new fail-fast ValueError("Deepgram api_key is required") now fires at the wrapper before any transcriber is constructed, and matches the identical guard in DeepgramTranscriber.__init__ — consistent error text at both layers. Empty-string keys are correctly rejected too (api_key or engine_kwargs.pop(...) + falsy check).
  • Nice side effect of the callable swap: transcribe(queue, callback) on the default Deepgram engine now raises that clear error, where before it silently used the function object as the api_key token. A real improvement.
  • Two small observations, neither blocking:
    • engine_kwargs.pop("api_key", None) is unreachable through normal calls — api_key is an explicit named parameter, so Python always binds it before **engine_kwargs. Harmless defensive code; keep or drop as you prefer.
    • The positional-callable-binds-to-on_transcript affordance goes a bit beyond what Python SDK transcribe() requires a Deepgram API key for Whisper and Parakeet engines #13042 asked for. It works and is tested, but it is a small public-API surface decision, so I'm flagging it for a maintainer's eye rather than treating it as purely mechanical.

sdks/python/tests/test_transcribe_wrapper.py

  • Good hermetic coverage: both key-passing styles, the missing-key error path, keyless whisper/parakeet, and the callable-binding case, with create_transcriber mocked throughout. I re-ran the suite in a clean sandbox at this head commit: 6/6 passed in 0.01s.
  • One ecosystem note (not this PR's job to fix): sdks/python has no CI lane today (only sdks/python-cli does), so these tests currently run only on contributors' machines. A follow-up wiring them into a discovered CI lane would make them enforceable.

No secrets, dependency, workflow, or network-surface changes; nothing security-sensitive. This is automated AI-maintainer feedback on behalf of the Omi maintainers.


by AI on behalf of David — merge call and the callable-binding API choice left to the maintainers; no urgent action needed.

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution python labels Sep 8, 2026

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

feat(sdk): makes api_key optional for whisper/parakeet engines — titled and shaped as a feature/API enhancement, not a bug fix. Approve only per confidence gate.

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

Labels

positive-signal Automation verified a genuine fix/quality contribution python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python SDK transcribe() requires a Deepgram API key for Whisper and Parakeet engines

3 participants