{"id":21495660,"url":"https://github.com/deepgram/deepgram-go-sdk","last_synced_at":"2025-10-06T00:13:26.981Z","repository":{"id":40380380,"uuid":"488803183","full_name":"deepgram/deepgram-go-sdk","owner":"deepgram","description":"Official Go SDK for Deepgram.","archived":false,"fork":false,"pushed_at":"2025-03-03T18:27:42.000Z","size":3192,"stargazers_count":43,"open_issues_count":15,"forks_count":34,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-03-30T08:09:23.803Z","etag":null,"topics":["asr","deepgram","go","hacktoberfest","speech-recognition","speech-to-text","text-to-speech","voice-agent","voice-ai"],"latest_commit_sha":null,"homepage":"https://developers.deepgram.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/deepgram.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-05T02:13:20.000Z","updated_at":"2025-03-18T18:53:28.000Z","dependencies_parsed_at":"2023-11-07T17:27:24.672Z","dependency_job_id":"e02361b1-cf95-4114-a5c0-24b24a0e01a3","html_url":"https://github.com/deepgram/deepgram-go-sdk","commit_stats":null,"previous_names":["deepgram-devs/go-sdk","deepgram/deepgram-go-sdk","deepgram-devs/deepgram-go-sdk"],"tags_count":68,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepgram%2Fdeepgram-go-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepgram%2Fdeepgram-go-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepgram%2Fdeepgram-go-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepgram%2Fdeepgram-go-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deepgram","download_url":"https://codeload.github.com/deepgram/deepgram-go-sdk/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247457799,"owners_count":20941906,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asr","deepgram","go","hacktoberfest","speech-recognition","speech-to-text","text-to-speech","voice-agent","voice-ai"],"created_at":"2024-11-23T16:12:44.863Z","updated_at":"2025-10-06T00:13:26.973Z","avatar_url":"https://github.com/deepgram.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Deepgram Go SDK\n\n[![Discord](https://dcbadge.vercel.app/api/server/xWRaCDBtW4?style=flat)](https://discord.gg/xWRaCDBtW4) [![Go Reference](https://pkg.go.dev/badge/github.com/deepgram/deepgram-go-sdk/v3.svg)](https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk/v3) [![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg?style=flat-rounded)](./.github/CODE_OF_CONDUCT.md)\n\nOfficial Go SDK for [Deepgram](https://www.deepgram.com/). Power your apps with world-class speech and Language AI models.\n\n- [Deepgram Go SDK](#deepgram-go-sdk)\n  - [Documentation](#documentation)\n  - [Migrating from earlier versions](#migrating-from-earlier-versions)\n    - [V1.2 to V1.3](#v12-to-v13)\n    - [V1 to V2](#v1-to-v2)\n    - [V2.\\* to V3](#v2-to-v3)\n  - [Requirements](#requirements)\n  - [Installation](#installation)\n  - [Getting an API Key](#getting-an-api-key)\n  - [Initialization](#initialization)\n  - [Pre-Recorded (Synchronous)](#pre-recorded-synchronous)\n    - [Remote Files (Synchronous)](#remote-files-synchronous)\n    - [Local Files (Synchronous)](#local-files-synchronous)\n  - [Pre-Recorded (Asynchronous / Callbacks)](#pre-recorded-asynchronous--callbacks)\n    - [Remote Files (Asynchronous)](#remote-files-asynchronous)\n    - [Local Files (Asynchronous)](#local-files-asynchronous)\n  - [Streaming Audio](#streaming-audio)\n  - [Voice Agent](#voice-agent)\n  - [Text to Speech REST](#text-to-speech-rest)\n  - [Text to Speech Streaming](#text-to-speech-streaming)\n  - [Text Intelligence](#text-intelligence)\n  - [Authentication](#authentication)\n    - [Authentication Methods](#authentication-methods)\n    - [Authentication Priority](#authentication-priority)\n    - [Environment Variables](#environment-variables)\n    - [OAuth-Style Workflow: API Key → Bearer Token](#oauth-style-workflow-api-key--bearer-token)\n    - [Grant Token](#grant-token)\n    - [Migration Guide](#migration-guide)\n  - [Projects](#projects)\n    - [Get Projects](#get-projects)\n    - [Get Project](#get-project)\n    - [Update Project](#update-project)\n    - [Delete Project](#delete-project)\n  - [Keys](#keys)\n    - [List Keys](#list-keys)\n    - [Get Key](#get-key)\n    - [Create Key](#create-key)\n    - [Delete Key](#delete-key)\n  - [Members](#members)\n    - [Get Members](#get-members)\n    - [Remove Member](#remove-member)\n  - [Scopes](#scopes)\n    - [Get Member Scopes](#get-member-scopes)\n    - [Update Scope](#update-scope)\n  - [Invitations](#invitations)\n    - [List Invites](#list-invites)\n    - [Send Invite](#send-invite)\n    - [Delete Invite](#delete-invite)\n    - [Leave Project](#leave-project)\n  - [Usage](#usage)\n    - [Get All Requests](#get-all-requests)\n    - [Get Request](#get-request)\n    - [Get Fields](#get-fields)\n    - [Summarize Usage](#summarize-usage)\n  - [Billing](#billing)\n    - [Get All Balances](#get-all-balances)\n    - [Get Balance](#get-balance)\n  - [Models](#models)\n    - [Get All Project Models](#get-all-project-models)\n    - [Get Model](#get-model)\n  - [On-Prem APIs](#on-prem-apis)\n    - [List On-Prem credentials](#list-on-prem-credentials)\n    - [Get On-Prem credentials](#get-on-prem-credentials)\n    - [Create On-Prem credentials](#create-on-prem-credentials)\n    - [Delete On-Prem credentials](#delete-on-prem-credentials)\n  - [Logging](#logging)\n  - [Testing](#testing)\n  - [Backwards Compatibility](#backwards-compatibility)\n  - [Development and Contributing](#development-and-contributing)\n    - [Getting Help](#getting-help)\n\n## Documentation\n\nYou can learn more about the Deepgram API at [developers.deepgram.com](https://developers.deepgram.com/docs).\n\nDocumentation for specifics about the structs, interfaces, and functions of this SDK can be found here: [Go SDK Documentation](https://pkg.go.dev/github.com/deepgram/deepgram-go-sdk@main)\n\n## Migrating from earlier versions\n\n### V1.2 to V1.3\n\nSee the [migration guide](https://developers.deepgram.com/sdks/go-sdk/v12-to-v13-migration) for more details.\n\n### V1 to V2\n\nThe Voice Agent interfaces have been updated to use the new Voice Agent V1 API. Please refer to our [Documentation](https://developers.deepgram.com/docs/voice-agent-v1-migration) on Migration to new V1 Agent API.\n\n### V2.\\* to V3\n\nV3 Introduced a generic object approach for Agent Providers to ease the maintenance overhead of adding new providers see this [PR](https://github.com/deepgram/deepgram-go-sdk/pull/296) for more details.\n\n## Requirements\n\n[Go](https://go.dev/doc/install) (version ^1.19)\n\n## Installation\n\nTo incorporate this SDK into your project's `go.mod` file, run the following command from your repo:\n\n```bash\ngo get github.com/deepgram/deepgram-go-sdk/v3\n```\n\n## Getting an API Key\n\n🔑 To access the Deepgram API you will need a [free Deepgram API Key](https://console.deepgram.com/signup?jump=keys).\n\n## Initialization\n\nAll of the examples below will require initializing the Deepgram client and inclusion of imports. The SDK supports **dual authentication** with both API Keys and Bearer tokens.\n\n```go\npackage main\n\nimport (\n    \"context\"\n    \"fmt\"\n    \"log\"\n    \"os\"\n\n    api \"github.com/deepgram/deepgram-go-sdk/v3/pkg/api/listen/v1/rest\"\n    interfaces \"github.com/deepgram/deepgram-go-sdk/v3/pkg/client/interfaces/v1\"\n    client \"github.com/deepgram/deepgram-go-sdk/v3/pkg/client/listen\"\n)\n\nctx := context.Background()\n\n// Option 1: API Key Authentication (Traditional)\nc := client.NewREST(\"YOUR_API_KEY\", \u0026interfaces.ClientOptions{\n    Host: \"https://api.deepgram.com\",\n})\n\n// Option 2: Bearer Token Authentication (Modern)\nc := client.NewREST(\"\", \u0026interfaces.ClientOptions{\n    Host:        \"https://api.deepgram.com\",\n    AccessToken: \"YOUR_ACCESS_TOKEN\",\n})\n\n// Option 3: Environment Variables (Recommended)\n// Set DEEPGRAM_API_KEY or DEEPGRAM_ACCESS_TOKEN\nc := client.NewWithDefaults()\n```\n\n## Pre-Recorded (Synchronous)\n\n### Remote Files (Synchronous)\n\nTranscribe audio from a URL.\n\n```go\n// Define Deepgram options\noptions := \u0026interfaces.PreRecordedTranscriptionOptions{\n    Model:       \"nova-3\",\n}\n// Define url to use\nURL := \"https://dpgr.am/spacewalk.wav\"\nres, err := dg.FromURL(ctx, URL, options)\nif err != nil {\n    log.Fatalf(\"FromURL failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Transcript: %s\\n\", res.Results.Channels[0].Alternatives[0].Transcript)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/speech-to-text-api/listen).\n\n### Local Files (Synchronous)\n\nTranscribe audio from a file.\n\n```go\n// Define Deepgram options\noptions := \u0026interfaces.PreRecordedTranscriptionOptions{\n    Model:       \"nova-3\",\n}\n// Define file to use\nfilePath := \"path/to/your/audio.wav\"\nres, err := dg.FromFile(ctx, filePath, options)\nif err != nil {\n    log.Fatalf(\"FromFile failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Transcript: %s\\n\", res.Results.Channels[0].Alternatives[0].Transcript)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/speech-to-text-api/listen).\n\n## Pre-Recorded (Asynchronous / Callbacks)\n\n### Remote Files (Asynchronous)\n\nTranscribe audio from a URL with callback.\n\n```go\n// Define Deepgram options\noptions := \u0026interfaces.PreRecordedTranscriptionOptions{\n    Model:       \"nova-3\",\n}\n// Define URL to use\nURL := \"https://dpgr.am/spacewalk.wav\"\ncallbackURL := \"https://your-callback-url.com/webhook\"\nres, err := dg.FromURLAsync(ctx, URL, callbackURL, options)\nif err != nil {\n    log.Fatalf(\"FromURLAsync failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Request ID: %s\\n\", res.RequestID)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/speech-to-text-api/listen).\n\n### Local Files (Asynchronous)\n\nTranscribe audio from a file with callback.\n\n```go\n// Define Deepgram options\noptions := \u0026interfaces.PreRecordedTranscriptionOptions{\n    Model:       \"nova-3\",\n}\n// Define file to use and Callback URL\nfilePath := \"path/to/your/audio.wav\"\ncallbackURL := \"https://your-callback-url.com/webhook\"\nres, err := dg.FromFileAsync(ctx, filePath, callbackURL, options)\nif err != nil {\n    log.Fatalf(\"FromFileAsync failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Request ID: %s\\n\", res.RequestID)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/speech-to-text-api/listen).\n\n## Streaming Audio\n\nTranscribe streaming audio.\n\n```go\nimport (\n    \"context\"\n    \"fmt\"\n    \"os\"\n\n    interfaces \"github.com/deepgram/deepgram-go-sdk/v3/pkg/client/interfaces\"\n    client \"github.com/deepgram/deepgram-go-sdk/v3/pkg/client/listen\"\n)\n\n// Initiate Client\nclient.InitWithDefault()\nctx := context.Background()\n\n// Create WebSocket client with default handler\ndgClient, err := client.NewWSUsingChanForDemo(ctx, \u0026interfaces.LiveTranscriptionOptions{})\n// Define Deepgram options\noptions := \u0026interfaces.LiveTranscriptionOptions{\n    Model:     \"nova-3\",\n}\n\n// Define Streaming URL\nconst audioURL = \"streaming_audio.url\"\n\n// Connect to Deepgram WebSocket\ndgClient.Connect()\n\n// Fetch audio from URL\nresp, err := http.Get(audioURL)\nif err != nil {\n    fmt.Printf(\"Error fetching audio: %v\\n\", err)\n    os.Exit(1)\n}\ndefer resp.Body.Close()\n\n// Stream audio data to Deepgram in background\ngo dgClient.Stream(bufio.NewReader(resp.Body))\n\n// Wait for user input to exit\nfmt.Println(\"Press ENTER to exit...\")\nbufio.NewScanner(os.Stdin).Scan()\n\n// Cleanup and close connection\ndgClient.Stop()\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/speech-to-text-api/listen-streaming).\n\n## Voice Agent\n\nConfigure a Voice Agent using WebSocket.\n\n```go\nimport (\n    \"context\"\n    \"fmt\"\n    \"os\"\n    \"time\"\n\n    interfaces \"github.com/deepgram/deepgram-go-sdk/v3/pkg/client/interfaces\"\n    client \"github.com/deepgram/deepgram-go-sdk/v3/pkg/client/agent\"\n)\n\n// Initialize the SDK\nclient.InitWithDefault()\n\n// Create context\nctx := context.Background()\n\n// Configure agent settings\noptions := \u0026interfaces.SettingsOptions{}\noptions.Language = \"en\"\noptions.Agent.Think.Provider.Type = \"open_ai\"\noptions.Agent.Think.Provider.Model = \"gpt-4o-mini\"\noptions.Agent.Think.Prompt = \"You are a helpful AI assistant.\"\noptions.Agent.Listen.Provider[\"type\"] = \"deepgram\"\noptions.Agent.Listen.Provider[\"model\"] = \"nova-3\"\n// Set speak provider - supports both single and multiple providers for fallback\n// Option 1: Single provider (backward compatible)\noptions.Agent.Speak = interfaces.Speak{\n    Provider: map[string]interface{}{\n        \"type\":  \"deepgram\",\n        \"model\": \"aura-2-thalia-en\",\n    },\n}\n\n// Option 2: Add fallback providers (new feature)\n// Primary provider is still configured above, fallback providers are additional\noptions.Agent.SpeakFallback = \u0026[]interfaces.Speak{\n    {\n        Provider: map[string]interface{}{\n            \"type\":  \"open_ai\",\n            \"model\": \"tts-1\",\n            \"voice\": \"shimmer\",\n        },\n        Endpoint: \u0026interfaces.Endpoint{\n            URL: \"https://api.openai.com/v1/audio/speech\",\n            Headers: map[string]interface{}{\n                \"authorization\": \"Bearer {{OPENAI_API_KEY}}\",\n            },\n        },\n    },\n    {\n        Provider: map[string]interface{}{\n            \"type\":  \"elevenlabs\",\n            \"model\": \"eleven_turbo_v2\",\n            \"voice\": \"alice\",\n        },\n        Endpoint: \u0026interfaces.Endpoint{\n            URL: \"https://api.elevenlabs.io/v1/text-to-speech\",\n            Headers: map[string]interface{}{\n                \"authorization\": \"Bearer {{ELEVENLABS_API_KEY}}\",\n            },\n        },\n    },\n}\n\n// Note: The system will use the primary provider first, then fallback to\n// the providers in SpeakFallback if the primary fails\n\noptions.Agent.Greeting = \"Hello, I'm your AI assistant.\"\n\n// Create Deepgram client (uses default handler that prints to console)\ndgClient, err := client.NewWSUsingChanForDemo(ctx, options)\nif err != nil {\n    fmt.Printf(\"Error creating client: %v\\n\", err)\n    os.Exit(1)\n}\n\n// Connect to Deepgram\ndgClient.Connect()\n\n// Keep connection alive\ntime.Sleep(30 * time.Second)\n\n// Cleanup\ndgClient.Stop()\n```\n\nThis example demonstrates:\n\n- Setting up a WebSocket connection for Voice Agent\n- Configuring the agent with speech, language, and audio settings\n- Handling various agent events (speech, transcripts, audio)\n- Sending audio data and keeping the connection alive\n\nFor a complete implementation, you would need to:\n\n1. Add your audio input source (e.g., microphone)\n2. Implement audio playback for the agent's responses\n3. Handle any function calls if your agent uses them\n4. Add proper error handling and connection management\n\n[See our API reference for more info](https://developers.deepgram.com/reference/voice-agent-api/agent).\n\n## Text to Speech REST\n\nConvert text into speech using the REST API.\n\n```go\n// Define Deepgram options\noptions := \u0026interfaces.SpeakOptions{\n    Model:      \"aura-2-thalia-en\",\n}\n\n// Convert text to speech and save to file\ntext := \"Hello world!\"\nfilePath := \"output.wav\"\nres, err := dg.ToSave(ctx, filePath, text, options)\nif err != nil {\n    fmt.Printf(\"ToSave failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Audio saved to: %s\\n\", filePath)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/text-to-speech-api/speak).\n\n## Text to Speech Streaming\n\nConvert streaming text into speech using a WebSocket.\n\n```go\n// Define Deepgram options\noptions := \u0026interfaces.SpeakWSOptions{\n    Model:      \"aura-2-thalia-en\",\n    Encoding:   \"linear16\",\n    SampleRate: 16000,\n}\n\n// Create Deepgram client with custom callback\ndgClient, err := client.NewWSUsingCallback(ctx, \"\", \u0026interfaces.ClientOptions{}, options, callback)\n    if err != nil {\n    fmt.Printf(\"Error creating client: %v\\n\", err)\n        os.Exit(1)\n    }\n\n    // Connect to Deepgram\ndgClient.Connect()\n\n// Send text to convert to speech\ntext := \"Hello, this is a text to speech example.\"\ndgClient.SendText(text)\ndgClient.Flush()\n\n// Wait for completion and cleanup\ndgClient.WaitForComplete()\ndgClient.Stop()\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/text-to-speech-api/speak-streaming).\n\n## Text Intelligence\n\nAnalyze text.\n\n```go\n// Define Deepgram options\noptions := \u0026interfaces.AnalyzeOptions{\n    Model: \"Nova-3\"\n    // Read options\n}\n\n// Define text file to analyze\nfilePath := \"text_to_analyze.txt\"\n\n// Analyze text content from file\nres, err := dg.FromFile(ctx, filePath, options)\nif err != nil {\n    fmt.Printf(\"FromFile failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\n// Display results\nfmt.Printf(\"Analysis Results: %+v\\n\", res.Results)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/text-intelligence-api/text-read).\n\n## Authentication\n\nThe Deepgram Go SDK supports **dual authentication** with both traditional API Keys and modern JWT Bearer tokens. This provides flexibility for different authentication workflows while maintaining 100% backward compatibility.\n\n### Authentication Methods\n\n#### 1. API Key Authentication (Traditional)\n\nUse your Deepgram API Key directly:\n\n```go\n// Using API key in client options\nc := client.NewREST(\"YOUR_API_KEY\", \u0026interfaces.ClientOptions{\n    Host: \"https://api.deepgram.com\",\n})\n\n// Or using environment variable\n// Set DEEPGRAM_API_KEY=your_api_key\nc := client.NewWithDefaults()\n```\n\n#### 2. Bearer Token Authentication (Modern)\n\nUse JWT Bearer tokens for enhanced security:\n\n```go\n// Using Bearer token in client options\nc := client.NewREST(\"\", \u0026interfaces.ClientOptions{\n    Host:        \"https://api.deepgram.com\",\n    AccessToken: \"YOUR_ACCESS_TOKEN\",\n})\n\n// Or using environment variable\n// Set DEEPGRAM_ACCESS_TOKEN=your_access_token\nc := client.NewWithDefaults()\n```\n\n#### 3. Dynamic Authentication Switching\n\nSwitch between authentication methods at runtime:\n\n```go\n// Initialize client\nc := client.NewREST(\"YOUR_API_KEY\", \u0026interfaces.ClientOptions{\n    Host: \"https://api.deepgram.com\",\n})\n\n// Switch to Bearer token authentication\nc.SetAccessToken(\"YOUR_ACCESS_TOKEN\")\n\n// Switch back to API key authentication\nc.SetAPIKey(\"YOUR_API_KEY\")\n\n// Get current effective authentication\ntoken, isBearer := c.GetAuthToken()\nif isBearer {\n    fmt.Printf(\"Using Bearer token: %s\\n\", token)\n} else {\n    fmt.Printf(\"Using API key: %s\\n\", token)\n}\n```\n\n### Authentication Priority\n\nWhen multiple authentication methods are provided, the SDK uses the following priority order:\n\n1. **Explicit AccessToken parameter** (highest priority)\n2. **Explicit APIKey parameter**\n3. **DEEPGRAM_ACCESS_TOKEN environment variable**\n4. **DEEPGRAM_API_KEY environment variable** (lowest priority)\n\n```go\n// Example: AccessToken takes precedence over APIKey\nc := client.NewREST(\"fallback_api_key\", \u0026interfaces.ClientOptions{\n    AccessToken: \"preferred_access_token\", // This will be used\n    Host:        \"https://api.deepgram.com\",\n})\n```\n\n### Environment Variables\n\nSet your credentials using environment variables:\n\n```bash\n# API Key authentication\nexport DEEPGRAM_API_KEY=\"your_api_key\"\n\n# Bearer token authentication (takes precedence if both are set)\nexport DEEPGRAM_ACCESS_TOKEN=\"your_access_token\"\n\n# Optional: Custom host\nexport DEEPGRAM_HOST=\"https://api.deepgram.com\"\n```\n\nThen initialize the client without explicit credentials:\n\n```go\n// Automatically uses environment variables based on priority\nc := client.NewWithDefaults()\n```\n\n### OAuth-Style Workflow: API Key → Bearer Token\n\nThe SDK supports a complete OAuth-style authentication workflow where you use an API key to obtain a Bearer token, then use that token for subsequent requests:\n\n```go\nimport (\n    \"context\"\n\n    authAPI \"github.com/deepgram/deepgram-go-sdk/v3/pkg/api/auth/v1\"\n    authClient \"github.com/deepgram/deepgram-go-sdk/v3/pkg/client/auth\"\n    interfaces \"github.com/deepgram/deepgram-go-sdk/v3/pkg/client/interfaces/v1\"\n    listenClient \"github.com/deepgram/deepgram-go-sdk/v3/pkg/client/listen\"\n)\n\nfunc main() {\n    ctx := context.Background()\n\n    // Step 1: Use API Key to get Bearer token\n    authOptions := \u0026interfaces.ClientOptions{\n        APIKey: \"YOUR_API_KEY\",\n    }\n\n    authClient := authClient.NewWithOptions(authOptions)\n    tokenResponse, err := authClient.GrantToken(ctx, \u0026authAPI.GrantTokenRequest{})\n    if err != nil {\n        log.Fatal(\"Failed to get token:\", err)\n    }\n\n    // Step 2: Use Bearer token for API calls\n    clientOptions := \u0026interfaces.ClientOptions{\n        AccessToken: tokenResponse.AccessToken, // Bearer token\n    }\n\n    listenClient := listenClient.NewRESTWithOptions(clientOptions)\n\n    // Step 3: Make API calls with Bearer authentication\n    result, err := listenClient.FromURL(ctx, \"https://dpgr.am/spacewalk.wav\", \u0026interfaces.PreRecordedTranscriptionOptions{\n        Model: \"nova-3\",\n    })\n    if err != nil {\n        log.Fatal(\"Transcription failed:\", err)\n    }\n\n    fmt.Printf(\"Transcript: %s\\n\", result.Results.Channels[0].Alternatives[0].Transcript)\n}\n```\n\n### Grant Token\n\nCreates a temporary token with a 30-second TTL using your API key:\n\n```go\n// Grant token using API key\nres, err := dg.GrantToken(ctx)\nif err != nil {\n    fmt.Printf(\"GrantToken failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Access Token: %s\\n\", res.AccessToken)\nfmt.Printf(\"Expires In: %d seconds\\n\", res.ExpiresIn)\n```\n\nThe generated token can then be used for Bearer authentication:\n\n```go\n// Use the granted token for Bearer authentication\nclientOptions := \u0026interfaces.ClientOptions{\n    AccessToken: res.AccessToken,\n}\ndgClient := client.NewRESTWithOptions(clientOptions)\n```\n\n### Migration Guide\n\n**Existing code continues to work unchanged!** No migration is required for current implementations.\n\n**To adopt Bearer tokens:**\n\n```go\n// Old way (still works)\nc := client.NewREST(\"YOUR_API_KEY\", \u0026interfaces.ClientOptions{})\n\n// New way with Bearer token\nc := client.NewREST(\"\", \u0026interfaces.ClientOptions{\n    AccessToken: \"YOUR_ACCESS_TOKEN\",\n})\n\n// Best practice: Use environment variables\n// Set DEEPGRAM_ACCESS_TOKEN or DEEPGRAM_API_KEY\nc := client.NewWithDefaults()\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/token-based-auth-api/grant-token).\n\n## Projects\n\n### Get Projects\n\nReturns all projects accessible by the API key.\n\n```go\n// Get all projects\nres, err := dg.ListProjects(ctx)\nif err != nil {\n    fmt.Printf(\"ListProjects failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Projects: %+v\\n\", res.Projects)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/projects/list).\n\n### Get Project\n\nRetrieves a specific project based on the provided project_id.\n\n```go\n// Get specific project\nres, err := dg.GetProject(ctx, myProjectId)\nif err != nil {\n    fmt.Printf(\"GetProject failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Project: %+v\\n\", res.Project)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/projects/get).\n\n### Update Project\n\nUpdate a project.\n\n```go\n// Update project\noptions := \u0026interfaces.ProjectUpdateRequest{\n    Name: \"Updated Project Name\",\n}\nres, err := dg.UpdateProject(ctx, myProjectId, options)\nif err != nil {\n    fmt.Printf(\"UpdateProject failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Update result: %s\\n\", res.Message)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/projects/update).\n\n### Delete Project\n\nDelete a project.\n\n```go\n// Delete project\nres, err := dg.DeleteProject(ctx, myProjectId)\nif err != nil {\n    fmt.Printf(\"DeleteProject failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Delete result: %s\\n\", res.Message)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/projects/delete).\n\n## Keys\n\n### List Keys\n\nRetrieves all keys associated with the provided project_id.\n\n```go\n// List all keys\nres, err := dg.ListKeys(ctx, myProjectId)\nif err != nil {\n    fmt.Printf(\"ListKeys failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Keys: %+v\\n\", res.APIKeys)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/keys/list)\n\n### Get Key\n\nRetrieves a specific key associated with the provided project_id.\n\n```go\n// Get specific key\nres, err := dg.GetKey(ctx, myProjectId, myKeyId)\nif err != nil {\n    fmt.Printf(\"GetKey failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Key: %+v\\n\", res.APIKey)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/keys/get)\n\n### Create Key\n\nCreates an API key with the provided scopes.\n\n```go\n// Create new key\noptions := \u0026interfaces.KeyCreateRequest{\n    Comment: \"My API Key\",\n    Scopes:  []string{\"admin\"},\n}\nres, err := dg.CreateKey(ctx, myProjectId, options)\nif err != nil {\n    fmt.Printf(\"CreateKey failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Created key: %s\\n\", res.APIKeyID)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/keys/create)\n\n### Delete Key\n\nDeletes a specific key associated with the provided project_id.\n\n```go\n// Delete key\nres, err := dg.DeleteKey(ctx, myProjectId, myKeyId)\nif err != nil {\n    fmt.Printf(\"DeleteKey failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Delete result: %s\\n\", res.Message)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/keys/delete)\n\n## Members\n\n### Get Members\n\nRetrieves account objects for all of the accounts in the specified project_id.\n\n```go\n// List all members\nres, err := dg.ListMembers(ctx, myProjectId)\nif err != nil {\n    fmt.Printf(\"ListMembers failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Members: %+v\\n\", res.Members)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/members/list).\n\n### Remove Member\n\nRemoves member account for specified member_id.\n\n```go\n// Remove member\nres, err := dg.RemoveMember(ctx, myProjectId, memberId)\n    if err != nil {\n    fmt.Printf(\"RemoveMember failed. Err: %v\\n\", err)\n        os.Exit(1)\n    }\n\nfmt.Printf(\"Remove result: %s\\n\", res.Message)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/members/delete).\n\n## Scopes\n\n### Get Member Scopes\n\nRetrieves scopes of the specified member in the specified project.\n\n```go\n// Get member scopes\nres, err := dg.GetMemberScopes(ctx, myProjectId, memberId)\nif err != nil {\n    fmt.Printf(\"GetMemberScopes failed. Err: %v\\n\", err)\n        os.Exit(1)\n    }\n\nfmt.Printf(\"Scopes: %+v\\n\", res.Scopes)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/scopes/list).\n\n### Update Scope\n\nUpdates the scope for the specified member in the specified project.\n\n```go\n// Update member scope\noptions := \u0026interfaces.ScopeUpdateRequest{\n    Scope: \"admin\",\n}\nres, err := dg.UpdateMemberScopes(ctx, myProjectId, memberId, options)\nif err != nil {\n    fmt.Printf(\"UpdateMemberScopes failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Update result: %s\\n\", res.Message)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/scopes/update).\n\n## Invitations\n\n### List Invites\n\nRetrieves all invitations associated with the provided project_id.\n\n```go\n// List all invitations\nres, err := dg.ListInvitations(ctx, myProjectId)\nif err != nil {\n    fmt.Printf(\"ListInvitations failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Invitations: %+v\\n\", res.Invites)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/invitations/list).\n\n### Send Invite\n\nSends an invitation to the provided email address.\n\n```go\n// Send invitation\noptions := \u0026interfaces.InvitationCreateRequest{\n    Email: \"user@example.com\",\n    Scope: \"admin\",\n}\nres, err := dg.SendInvitation(ctx, myProjectId, options)\nif err != nil {\n    fmt.Printf(\"SendInvitation failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Invitation sent: %s\\n\", res.Message)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/invitations/create).\n\n### Delete Invite\n\nRemoves the specified invitation from the project.\n\n```go\n// Delete invitation\nres, err := dg.DeleteInvitation(ctx, myProjectId, email)\nif err != nil {\n    fmt.Printf(\"DeleteInvitation failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Delete result: %s\\n\", res.Message)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/invitations/delete).\n\n### Leave Project\n\n```go\n// Leave project\nres, err := dg.LeaveProject(ctx, myProjectId)\nif err != nil {\n    fmt.Printf(\"LeaveProject failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Leave result: %s\\n\", res.Message)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/invitations/leave).\n\n## Usage\n\n### Get All Requests\n\nRetrieves all requests associated with the provided project_id based on the provided options.\n\n```go\n// Get all requests\nres, err := dg.GetUsageRequests(ctx, myProjectId)\nif err != nil {\n    fmt.Printf(\"GetUsageRequests failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Requests: %+v\\n\", res.Requests)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/usage/list-requests).\n\n### Get Request\n\nRetrieves a specific request associated with the provided project_id\n\n```go\n// Get specific request\nres, err := dg.GetUsageRequest(ctx, myProjectId, requestId)\nif err != nil {\n    fmt.Printf(\"GetUsageRequest failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Request: %+v\\n\", res.Request)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/usage/get-request).\n\n### Get Fields\n\nLists the features, models, tags, languages, and processing method used for requests in the specified project.\n\n```go\n// Get usage fields\nres, err := dg.GetUsageFields(ctx, myProjectId)\nif err != nil {\n    fmt.Printf(\"GetUsageFields failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Fields: %+v\\n\", res.Fields)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/usage/list-fields).\n\n### Summarize Usage\n\n`Deprecated` Retrieves the usage for a specific project. Use Get Project Usage Breakdown for a more comprehensive usage summary.\n\n```go\n// Get usage summary\nres, err := dg.GetUsageSummary(ctx, myProjectId)\nif err != nil {\n    fmt.Printf(\"GetUsageSummary failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Usage summary: %+v\\n\", res.Usage)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/usage/get).\n\n## Billing\n\n### Get All Balances\n\nRetrieves the list of balance info for the specified project.\n\n```go\n// Get all balances\nres, err := dg.GetBalances(ctx, myProjectId)\nif err != nil {\n    fmt.Printf(\"GetBalances failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Balances: %+v\\n\", res.Balances)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/balances/list).\n\n### Get Balance\n\nRetrieves the balance info for the specified project and balance_id.\n\n```go\n// Get specific balance\nres, err := dg.GetBalance(ctx, myProjectId, balanceId)\nif err != nil {\n    fmt.Printf(\"GetBalance failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Balance: %+v\\n\", res.Balance)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/balances/get).\n\n## Models\n\n### Get All Project Models\n\nRetrieves all models available for a given project.\n\n```go\n// Get all project models\nres, err := dg.GetProjectModels(ctx, myProjectId)\nif err != nil {\n    fmt.Printf(\"GetProjectModels failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Models: %+v\\n\", res)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/projects/list-models).\n\n### Get Model\n\nRetrieves details of a specific model.\n\n```go\n// Get specific model\nres, err := dg.GetProjectModel(ctx, myProjectId, modelId)\n    if err != nil {\n    fmt.Printf(\"GetProjectModel failed. Err: %v\\n\", err)\n        os.Exit(1)\n    }\n\nfmt.Printf(\"Model: %+v\\n\", res.Model)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/management-api/projects/get-model).\n\n## On-Prem APIs\n\n### List On-Prem credentials\n\nLists sets of distribution credentials for the specified project.\n\n```go\n// List on-prem credentials\nres, err := dg.ListSelfhostedCredentials(ctx, projectId)\nif err != nil {\n    fmt.Printf(\"ListSelfhostedCredentials failed. Err: %v\\n\", err)\n        os.Exit(1)\n    }\n\nfmt.Printf(\"Credentials: %+v\\n\", res.Credentials)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/self-hosted-api/list-credentials).\n\n### Get On-Prem credentials\n\nReturns a set of distribution credentials for the specified project.\n\n```go\n// Get specific on-prem credentials\nres, err := dg.GetSelfhostedCredentials(ctx, projectId, distributionCredentialsId)\nif err != nil {\n    fmt.Printf(\"GetSelfhostedCredentials failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Credentials: %+v\\n\", res.Credentials)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/self-hosted-api/get-credentials).\n\n### Create On-Prem credentials\n\nCreates a set of distribution credentials for the specified project.\n\n```go\n// Create on-prem credentials\noptions := \u0026interfaces.SelfhostedCredentialsCreateRequest{\n    Comment: \"My on-prem credentials\",\n}\nres, err := dg.CreateSelfhostedCredentials(ctx, projectId, options)\nif err != nil {\n    fmt.Printf(\"CreateSelfhostedCredentials failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Created credentials: %s\\n\", res.CredentialsID)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/self-hosted-api/create-credentials).\n\n### Delete On-Prem credentials\n\nDeletes a set of distribution credentials for the specified project.\n\n```go\n// Delete on-prem credentials\nres, err := dg.DeleteSelfhostedCredentials(ctx, projectId, distributionCredentialId)\nif err != nil {\n    fmt.Printf(\"DeleteSelfhostedCredentials failed. Err: %v\\n\", err)\n    os.Exit(1)\n}\n\nfmt.Printf(\"Delete result: %s\\n\", res.Message)\n```\n\n[See our API reference for more info](https://developers.deepgram.com/reference/self-hosted-api/delete-credentials).\n\n## Logging\n\nThis SDK provides logging as a means to troubleshoot and debug issues encountered. By default, this SDK will enable `Information` level messages and higher (ie `Warning`, `Error`, etc) when you initialize the library as follows:\n\n```go\nclient.InitWithDefault();\n```\n\nTo increase the logging output/verbosity for debug or troubleshooting purposes, you can set the `TRACE` level but using this code:\n\n```go\n// init library\nclient.Init(client.InitLib{\n    LogLevel: client.LogLevelTrace,\n})\n```\n\n## Testing\n\nThere are several test folders in [/tests](./tests/) you can run:\n\n- unit_test/ - Unit tests\n- daily_test/ - Integration/daily tests\n- edge_cases/ - Edge case testing\n- response_data/ - Test data\n- utils/ - Test utilities\n\nTo run the tests, you can use the following commands:\n\nRun specific tests in a directory:\n\n```bash\ngo test filename\n```\n\n## Backwards Compatibility\n\nWe follow semantic versioning (semver) to ensure a smooth upgrade experience. Within a major version (like `3.*`), we will maintain backward compatibility so your code will continue to work without breaking changes. When we release a new major version (like moving from `2.*` to `3.*`), we may introduce breaking changes to improve the SDK. We'll always document these changes clearly in our release notes to help you upgrade smoothly.\n\nOlder SDK versions will receive Priority 1 (P1) bug support only. Security issues, both in our code and dependencies, are promptly addressed. Significant bugs without clear workarounds are also given priority attention.\n\n## Development and Contributing\n\nInterested in contributing? We ❤️ pull requests!\n\nTo make sure our community is safe for all, be sure to review and agree to our [Code of Conduct](https://github.com/deepgram/deepgram-go-sdk/blob/main/.github/CODE_OF_CONDUCT.md). Then see the [Contribution](https://github.com/deepgram/deepgram-go-sdk/blob/main/.github/CONTRIBUTING.md) guidelines for more information.\n\n### Getting Help\n\nWe love to hear from you so if you have questions, comments or find a bug in the\nproject, let us know! You can either:\n\n- [Open an issue in this repository](https://github.com/deepgram/deepgram-go-sdk/issues/new)\n- [Join the Deepgram Github Discussions Community](https://github.com/orgs/deepgram/discussions)\n- [Join the Deepgram Discord Community](https://discord.gg/xWRaCDBtW4)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepgram%2Fdeepgram-go-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepgram%2Fdeepgram-go-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepgram%2Fdeepgram-go-sdk/lists"}