Verify Deepgram callback requests (the results of transcribe-url-async / transcribe-audio-async). Deepgram does not sign callbacks; its docs recommend either Basic Auth credentials in the callback URL (verify-basic-auth) or a shared secret sent as extra=callback_secret:<secret> and echoed back in metadata.extra.callback_secret (verify-callback). The dg-token header carries the identifier of the API key that made the request; it is not a secret and is not sent on every callback, so verify-dg-token is only a supplementary check. See https://developers.deepgram.com/docs/callback.

Functions

verify-basic-auth

fn (request: Map, username: Str?, password: Str?): Bool

True when the request's Authorization header carries HTTP Basic credentials matching username/password (constant-time compare). Pair with a callback URL that embeds them, https://user:pass@example.com/hook, which Deepgram sends as Basic Auth. The password is masked in call records. Empty credentials never verify.

Example

deepgram-callback
meta {webhook: {service: "deepgram", path: "/deepgram/callback"}}
fn (request) {
  if(not(::deepgram::callbacks/verify-basic-auth(request, "deepgram", ::hot::ctx/get("deepgram.callback.password"))),
    ::hot::http/HttpResponse({status: 401, body: "invalid callback"}),
    ::deepgram/transcript(request.body))
}

verify-callback

fn (request: Map): Bool
fn (request: Map, secret: Str?): Bool

True when the callback body's metadata.extra.callback_secret matches the shared secret (constant-time compare over the raw body). Uses the deepgram.callback.secret context variable by default (failing when it is unset, the same secret the async transcribe functions send), or an explicit secret, which is masked in call records; an empty explicit secret never verifies. Use a hex secret (openssl rand -hex 32): Deepgram turns + into a space.

Example

deepgram-callback
meta {webhook: {service: "deepgram", path: "/deepgram/callback"}}
fn (request) {
  if(not(::deepgram::callbacks/verify-callback(request)),
    ::hot::http/HttpResponse({status: 401, body: "invalid callback"}),
    ::deepgram/transcript(request.body))
}
Context Vars: deepgram.callback.secret

verify-dg-token

fn (request: Map, api-key-id: Str?): Bool

Supplementary check: true when the dg-token header equals the API key identifier (the key's id in the Deepgram console, not the secret key) that submitted the request. Deepgram does not guarantee the header on every callback, so combine this with verify-callback or verify-basic-auth rather than relying on it alone. An empty api-key-id never verifies.

Example

request {headers: {dg-token: "3f8a2c1e"}}
::deepgram::callbacks/verify-dg-token(request, "3f8a2c1e")  // true
::deepgram::callbacks/verify-dg-token(request, "other")  // false