Deepgram pass-through
The /deepgram/v1/listen route (also served as /deepgram/listen) relays a live transcription WebSocket to Deepgram. Your app opens the WebSocket to the gateway with a virtual key, streams audio, and reads Deepgram's transcripts as they arrive. The gateway checks the key, adds its own Deepgram key, prices the session and records the spend, so the Deepgram key never leaves the gateway.
A real-world scenario
A call center shows agents a live transcript of each phone call. The softphone used to hold the Deepgram key. It now opens wss://gateway.example.com/deepgram/v1/listen?model=nova-3 with the agent's virtual key. The Deepgram key is gone from every desktop, each team's key has a monthly budget, and every call shows up on the Logs page with its cost.
Before you start
The gateway needs a Deepgram key. It looks first for a model_list deployment of provider Deepgram with use_in_pass_through: true, then for the environment below.
| Variable | Purpose |
|---|---|
DEEPGRAM_API_KEY | The key the gateway sends upstream as Authorization: Token <key>. |
DEEPGRAM_API_BASE | Optional. Another Deepgram endpoint. Defaults to https://api.deepgram.com/v1. |
Steps
-
Give the gateway the credential. Set
DEEPGRAM_API_KEYand restart the gateway, or add a Deepgram model on the Add Model tab of/ui/models-and-endpointswith Use in pass through routes turned on under Advanced Settings. -
Issue a virtual key on
/ui/api-keyswith + Create New Key, then Create Key. -
Open the WebSocket with the key and stream audio. Send the key as
Authorization: Bearer <key>, or as anapi-keyheader.modeldefaults tonova-3, and every other query parameter is passed to Deepgram unchanged.websocat -H "Authorization: Bearer $SPANWAY_API_KEY" \"ws://localhost:4000/deepgram/v1/listen?model=nova-3&language=en&encoding=linear16&sample_rate=16000" \< call-audio.raw -
Open
/ui/logsand click the newest row to see the session, the key and its cost.
Expected result
Deepgram's own transcript messages arrive on the WebSocket while you stream, for example {"type": "Results", "channel": {"alternatives": [{"transcript": "thanks for calling"}]}, "is_final": true}. When the socket closes, the session is costed at Deepgram's streaming price for the model and the spend log row carries the key, team and user.
Errors
The route answers errors by closing the WebSocket with a code and a reason.
| Close code | Reason | What it means and how to fix it |
|---|---|---|
1008 | An authentication error | The virtual key is missing, wrong, expired or blocked. Send a live key. |
1011 | Required 'DEEPGRAM_API_KEY' in environment to make pass-through calls to Deepgram. | The gateway has no Deepgram key. Set it as in step 1. |
1008 | Deepgram callback delivery is not supported through the proxy: remove callback, callback_method | The URL asked Deepgram to post results to a callback, which the gateway cannot account for. Remove those parameters. |
1008 | No streaming price for '<model>': add it to the model cost map to enable it | The model has no streaming price, so the gateway cannot cost the session and refuses it. Use a priced model such as nova-3, or add the price. |
1008 | Refused by the data policy | The key's data policy does not allow Deepgram. Use a key without that restriction. |
Logs
The relay writes the same WebSocket pass-through lines as the other live routes, see the pass-through Logs section. The gateway does not write the audio or the transcripts in its own lines.
Related
- Pass-through endpoints for how built-in routes, credentials and route lists work.
- Audio transcription for file transcription through the unified API.
- Virtual keys for budgets on the key.