GuidesConnections

Deepgram connection

One URL for every Deepgram live stream; each stream becomes its own conversation.

A Deepgram connection is one permanent URL your live streams post their results to. Sparkle creates a conversation for each streaming request on its first final result, and ends it when the stream closes. You create no conversations yourself.

Use a connection when streams start outside your code and you don't want to create conversations yourself. When your code already creates the conversation and wants its id, its own webhook_url or its title up front, use the per-conversation Deepgram receiver instead. Sources compares the two.

Set it up

Create the connection

Deepgram takes no credentials. You can also create the connection in the dashboard under Sources → Connect.

curl -X POST https://api.sparkle.ai/public/v1/connections \
  -H "X-API-Key: $SPARKLE_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{"vendor": "deepgram", "name": "Support line", "environment": "live"}'
FieldWhat it does
vendorRequired. deepgram.
nameRequired. A label, up to 100 characters.
environmentRequired. live or test: the environment of every conversation its calls create. Live ones are billed; test ones count against your test minutes.
moment_typesThe moment kinds its conversations detect. Absent or empty detects every kind.

Sparkle answers 201 Created with the connection and its receiver_url:

{
  "id": "con_2kd9g6j0m4q8u2y6b9cf",
  "vendor": "deepgram",
  "name": "Support line",
  "environment": "live",
  "moment_types": [],
  "status": "active",
  "has_credentials": false,
  "last_event_at": null,
  "last_error_code": null,
  "receiver_url": "https://api.sparkle.ai/public/v1/receivers/deepgram/<token>",
  "…": "…"
}

This is the only time you see receiver_url. If you lose it, or it leaks, POST /connections/{id}/rotate-url returns a new one, and the old one stops at once.

The URL is the credential

Deepgram doesn't sign its requests, so the token in the URL is the connection's only authentication. Anyone who holds the URL can start conversations in your organization. Keep it on your server like an API key.

Send the results

Turn on diarization (diarize=true) so turns are split by speaker. Then send the messages in one of two ways:

Add the URL as the stream's callback, URL-encoded. Deepgram then posts each streaming response to it:

wss://api.deepgram.com/v1/listen?model=nova-3&diarize=true&callback=https%3A%2F%2Fapi.sparkle.ai%2Fpublic%2Fv1%2Freceivers%2Fdeepgram%2F<token>

Every stream uses the same URL. The streaming request is the call: each request_id gets its own conversation, so a reconnect, which is a new request, starts a new one.

Subscribe to the events

A call's conversation has no webhook_url of its own: its events go to the organization's webhook subscriptions. Create one in the connection's environment, since a subscription only receives its own environment's events.

Send a test call

POST /connections/{id}/test sends a sample stream through the same path Deepgram's messages take: one final result asking for work, then the closing Metadata message. It creates a short test conversation, whatever the connection's environment, and works on a disabled connection too. It answers:

{ "conversation_id": "cnv_2kd9f5k9m3q7u1y5b8de", "error_code": null }

conversation_id is null and error_code says why when the call was refused. Being a test conversation, its events go to your test webhook subscriptions, not your live ones.

What each call becomes

The first final result of a streaming request creates a live conversation in the connection's environment, detecting the connection's moment types:

  • Its title is Deepgram call and the first 8 characters of the request id, such as Deepgram call 6f1b2c3d.

  • Its metadata names the connection, the vendor and the request:

    {
      "connection_id": "con_2kd9g6j0m4q8u2y6b9cf",
      "vendor": "deepgram",
      "external_ref": "6f1b2c3d-0a9e-4b8c-8d7f-2e1a5c4b9d30"
    }
  • conversation.created carries that metadata, so your handler can match the conversation to your own record of the stream.

  • Two first results of one stream arriving together still create one conversation.

Final results become turns as the Deepgram receiver reads them. Interim results and the other message types are ignored.

How a call ends

What happensconversation.ended reason
The stream's closing Metadata message arrivesrequested
No turn arrives for 60 minutesidle

Deepgram doesn't document the Metadata message as always the last one, so the 60-minute rule is the backstop for a stream that closes without it. Whichever comes first ends the conversation; a later message of an ended call changes nothing.

Manage the connection

ToCall
Stop taking callsPATCH /connections/{id} with {"status": "disabled"}. Deepgram still gets a 2xx, and the calls are dropped. "active" resumes.
Change the moment typesPATCH with moment_types. Calls that start from then on use them.
Get a new URLPOST /connections/{id}/rotate-url. The old URL stops at once.
Delete itDELETE /connections/{id}. Its URL stops at once; its calls' conversations stay.

When calls don't arrive

Check status first: a disabled connection drops calls without recording them. GET /connections/{id} returns last_event_at, when a call's message last went through, and last_error_code, why the latest one was not taken. last_error_code is null again once a message goes through.

last_error_codeMeans
plan_limitYour plan refused the call: its minutes are used up, or it runs as many live conversations as it allows.
suspendedYour company is suspended.
failedAnything else that kept the call's turns out.

GET /connections/{id}/events lists the latest 50 requests that carried a call's turns or its end, newest first: each one's message type, the request id, its conversation and its error code. It never holds the transcript.

Responses

StatusMeaning
204Accepted, or ignored. A call refused by your plan or a suspended company is a 204 too, and shows in last_error_code. So is a disabled connection's, which records nothing.
401The URL names no connection, such as one replaced by a rotation. Sparkle checks only when a message has a final result to add, so other messages to it still get 204.
413The body is larger than 1 MB.
429More than 20,000 requests in a minute to one connection URL.

On this page