Skip to main content

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.

VariablePurpose
DEEPGRAM_API_KEYThe key the gateway sends upstream as Authorization: Token <key>.
DEEPGRAM_API_BASEOptional. Another Deepgram endpoint. Defaults to https://api.deepgram.com/v1.

Steps​

  1. Give the gateway the credential. Set DEEPGRAM_API_KEY and restart the gateway, or add a Deepgram model on the Add Model tab of /ui/models-and-endpoints with Use in pass through routes turned on under Advanced Settings.

  2. Issue a virtual key on /ui/api-keys with + Create New Key, then Create Key.

  3. Open the WebSocket with the key and stream audio. Send the key as Authorization: Bearer <key>, or as an api-key header. model defaults to nova-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
  4. Open /ui/logs and 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 codeReasonWhat it means and how to fix it
1008An authentication errorThe virtual key is missing, wrong, expired or blocked. Send a live key.
1011Required 'DEEPGRAM_API_KEY' in environment to make pass-through calls to Deepgram.The gateway has no Deepgram key. Set it as in step 1.
1008Deepgram callback delivery is not supported through the proxy: remove callback, callback_methodThe URL asked Deepgram to post results to a callback, which the gateway cannot account for. Remove those parameters.
1008No streaming price for '<model>': add it to the model cost map to enable itThe 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.
1008Refused by the data policyThe 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.