feat(deepgram): add STT/TTS with_cloudflare() for Cloudflare AI Gateway#6133
Open
mcdgavin wants to merge 9 commits into
Open
feat(deepgram): add STT/TTS with_cloudflare() for Cloudflare AI Gateway#6133mcdgavin wants to merge 9 commits into
mcdgavin wants to merge 9 commits into
Conversation
mcdgavin
added a commit
to mcdgavin/agents
that referenced
this pull request
Jun 17, 2026
- public extra_headers (additive, merged over default Token auth; sole auth when no key) replacing the private _connect_headers seam - with_cloudflare accepts bare model names (nova-3/aura-1), prefixes @cf/deepgram/ - cf-aig-authorization sent as 'Bearer <token>' per Cloudflare's Deepgram docs
- public extra_headers (additive, merged over the default Token auth; sole auth when no key is set) replacing the private _connect_headers seam - with_cloudflare accepts bare model names (nova-3 / aura-1) and prepends @cf/deepgram/ internally - cf-aig-authorization sent as the raw token, matching the /workers-ai endpoint examples (the Bearer form documented on Cloudflare's /deepgram provider proxy is a different endpoint)
55c1545 to
21f1d68
Compare
…on for CF models - with_cloudflare passes api_key="" so a DEEPGRAM_API_KEY in the env is no longer picked up and sent to the gateway as a stray Authorization: Token header - TTS only falls back to the env var when api_key is None (explicit "" means no key) - _validate_model/_validate_keyterm strip the @cf/deepgram/ routing prefix so keyterm is correctly allowed for @cf/deepgram/nova-3
_validate_model dropped the routing prefix when downgrading an en-only model to nova-2-general for a non-English language, yielding an invalid gateway model.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Cloudflare AI Gateway support to the Deepgram plugin — streaming STT (Nova-3 / Flux)
and TTS (Aura) — via
deepgram.STT.with_cloudflare(...)anddeepgram.TTS.with_cloudflare(...).Addresses the STT/TTS portion of #3163. (The LLM portion shipped separately in #6131 as
openai.LLM.with_cloudflare.)Design notes
WebSocket protocol verbatim (
channel.alternatives[0].transcript+is_finalfor STT;Speak/Flush/Flushedfor TTS), so these reuse the existing DeepgramSTT/TTSstreaming implementations rather than duplicating them. This mirrors the LLM approach, where
Cloudflare-LLM rode on the OpenAI plugin because it's OpenAI-compatible — each Cloudflare
modality lives on the plugin whose protocol it matches.
Authorization: Token <key>) become an overridable_connect_headers, defaulting to theexact prior value. Existing Deepgram usage is unchanged;
with_cloudflareinjectscf-aig-authorization(the raw Cloudflare token — no Deepgram key required).Testing
tests/test_deepgram_with_cloudflare.py— 12 hermetic--unittests covering URL building,CLOUDFLARE_ACCOUNT_IDenv fallback,base_urloverride, thecf-aig-authorizationheader,default models,
streamingcapability, and theValueErrorpaths.make checkpasses (ruff format + lint, strict mypy).