Using Custom Add On Parameters with SDKs

Learn how to use custom add on parameters to set arbitrary key/value pairs with the Deepgram SDKs.

JS SDK

The Deepgram JS SDK has defined typed parameters, but also allows for arbitrary key/value pairs. You can provide custom parameters when using the JS SDK to make an API Request even if the parameter isn’t defined as a type.

This is useful if you want to use a feature of the Deepgram API that isn’t officially supported in the JS SDK.

Example

JavaScript
1// install our SDK @deepgram/sdk
2
3import { createClient } from "@deepgram/sdk";
4// - or -
5// const { createClient } = require("@deepgram/sdk");
6
7const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
8 {
9 url: "https://dpgr.am/spacewalk.wav",
10 },
11 {
12 model: "nova-3",
13 // To demonstrate using the custom addon parameters, you could enable it like this
14 custom_parameter: option
15 }
16);

Python SDK

The Deepgram Python SDK has defined option parameters, but also allows for arbitrary key/value pairs. You can provide custom parameters when using the Python SDK to make an API Request even if the parameter isn’t defined as an option.

This is useful if you want to use a feature of the Deepgram API that isn’t officially supported in the Python SDK.

Example

1# Install the SDK: pip install deepgram-sdk
2
3import os
4from dotenv import load_dotenv
5
6from deepgram import DeepgramClient, PrerecordedOptions
7
8load_dotenv()
9
10AUDIO_URL = {
11 "url": "https://dpgr.am/bueller.wav"
12}
13
14def main():
15 options: PrerecordedOptions = PrerecordedOptions(
16 model="nova-3"
17 )
18
19 # To demonstrate using the custom addon parameters, you could enable it like this
20 custom_options: dict = {"custom_parameter": option}
21
22 # STEP 1 Create a Deepgram client using the API key in the environment variables DEEPGRAM_API_KEY
23 deepgram: DeepgramClient = DeepgramClient()
24
25 try:
26 # STEP 2 Call the transcribe_url method on the prerecorded class
27 response = deepgram.listen.rest.v("1").transcribe_url(
28 AUDIO_URL, options, addons=custom_options
29 )
30 print(response.to_json(indent=4))
31 except Exception as e:
32 print(f"Exception: {e}")
33
34if __name__ == "__main__":
35 main()

.NET SDK

The Deepgram .NET SDK has defined option parameters, but also allows for arbitrary key/value pairs. You can provide custom parameters when using the .NET SDK to make an API Request even if the parameter isn’t defined as an option.

This is useful if you want to use a feature of the Deepgram API that isn’t officially supported in the .NET SDK.

Example

C#
1//Install the SDK: dotnet add package Deepgram
2
3using Deepgram.Models.Listen.v1.REST;
4
5namespace PreRecorded
6{
7 class Program
8 {
9 static async Task Main(string[] args)
10 {
11 // Initialize Library with default logging
12 // Normal logging is "Info" level
13 Library.Initialize();
14
15 // Set "DEEPGRAM_API_KEY" environment variable to your Deepgram API Key
16 var deepgramClient = ClientFactory.CreateListenRESTClient();
17
18 var prerecordedOptions = new PreRecordedSchema()
19 {
20 Model = "nova-3"
21 };
22
23 // but to demonstrate using the custom addon parameters, you could enable it like this
24 var customOptions = new Dictionary<string, string>();
25 customOptions["custom_parameter"] = "option";
26
27 var response = await deepgramClient.TranscribeUrl(
28 new UrlSource("https://dpgr.am/bueller.wav"),
29 prerecordedOptions,
30 null, // Don't want to specify a cancellation token, use the default
31 customOptions,
32 );
33
34 Console.WriteLine(response);
35
36 // Teardown Library
37 Library.Terminate();
38 }
39 }
40}

Go SDK

The Deepgram Go SDK has defined option parameters, but also allows for arbitrary key/value pairs. You can provide custom parameters when using the Go SDK to make an API Request even if the parameter isn’t defined as an option.

This is useful if you want to use a feature of the Deepgram API that isn’t officially supported in the Go SDK.

Example

Go
1// Install the SDK: go get github.com/deepgram/deepgram-go-sdk
2
3package main
4
5import (
6 "context"
7 "encoding/json"
8 "fmt"
9 "os"
10
11 prettyjson "github.com/hokaccha/go-prettyjson"
12
13 api "github.com/deepgram/deepgram-go-sdk/pkg/api/listen/v1/rest"
14 interfaces "github.com/deepgram/deepgram-go-sdk/pkg/client/interfaces"
15 client "github.com/deepgram/deepgram-go-sdk/pkg/client/listen"
16)
17
18const (
19 url string = "https://dpgr.am/bueller.wav"
20)
21
22func main() {
23 // init library
24 client.InitWithDefault()
25
26 // Go context
27 ctx := context.Background()
28
29 // set the Transcription options
30 options := &interfaces.PreRecordedTranscriptionOptions{
31 Model: "nova-3",
32 }
33
34 // create a Deepgram client
35 c := client.NewRESTWithDefaults()
36 dg := api.New(c)
37
38 // but to demonstrate using the custom addon parameters, you could enable it like this
39 params := make(map[string][]string, 0)
40 params["custom_parameter"] = []string{"option"}
41 ctx = interfaces.WithCustomParameters(ctx, params)
42
43 // send/process file to Deepgram
44 res, err := dg.FromURL(ctx, url, options)
45 if err != nil {
46 if e, ok := err.(*interfaces.StatusError); ok {
47 fmt.Printf("DEEPGRAM ERROR:\n%s:\n%s\n", e.DeepgramError.ErrCode, e.DeepgramError.ErrMsg)
48 }
49 fmt.Printf("FromStream failed. Err: %v\n", err)
50 os.Exit(1)
51 }
52
53 data, err := json.Marshal(res)
54 if err != nil {
55 fmt.Printf("json.Marshal failed. Err: %v\n", err)
56 os.Exit(1)
57 }
58
59 // make the JSON pretty
60 prettyJSON, err := prettyjson.Format(data)
61 if err != nil {
62 fmt.Printf("prettyjson.Marshal failed. Err: %v\n", err)
63 os.Exit(1)
64 }
65 fmt.Printf("\n\nResult:\n%s\n\n", prettyJSON)
66}
Built with