### Install Example Dependencies Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/CONTRIBUTING.md Install dependencies required for running the project examples. ```bash poetry run pip install -r examples/requirements.txt ``` -------------------------------- ### Run Live WebSocket Example Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/README.md Runs the live transcription example using a WebSocket connection. Ensure Python is installed. ```bash python -u examples/07-transcription-live-websocket.py ``` -------------------------------- ### Run an Example Script Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/README.md Execute a specific example script from the `examples` directory. Replace the filename with the desired example. ```bash python examples/01-authentication-api-key.py ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/CONTRIBUTING.md Install all necessary project dependencies using Poetry. ```bash poetry install ``` -------------------------------- ### Install Poetry Version Manager Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/CONTRIBUTING.md Install Poetry version 1.5.1 using the official installation script. Ensure Poetry is added to your system's PATH. ```bash curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1 ``` -------------------------------- ### Run a Deepgram Python Example Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/CONTRIBUTING.md Execute a specific example script to transcribe audio from a URL, passing additional query parameters. ```bash poetry run python -u examples/listen/v1/media/transcribe_url/with_additional_query_parameters.py ``` -------------------------------- ### Verify Installations Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/CONTRIBUTING.md Check the installed Poetry version and ensure Docker is running by listing active containers. ```bash poetry --version docker ps ``` -------------------------------- ### Install Dependencies Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/README.md Install the required Python packages for the Deepgram SDK. Ensure you have a `requirements.txt` file. ```bash pip install -r requirements.txt ``` -------------------------------- ### Install Deepgram Python SDK Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/README.md Install the Deepgram Python SDK using pip. ```bash pip install deepgram-sdk ``` -------------------------------- ### GET /v1/projects/{project_id}/invites Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Generates a list of invites for a specific project. ```APIDOC ## GET /v1/projects/{project_id}/invites ### Description Generates a list of invites for a specific project. ### Method GET ### Endpoint /v1/projects/{project_id}/invites ### Parameters #### Path Parameters - **project_id** (str) - Required - The unique identifier of the project ``` -------------------------------- ### Manage V1 Projects - Get Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves detailed information about a specific project using its ID. ```APIDOC ## GET /v1/projects/{project_id} ### Description Retrieves information about the specified project. ### Method GET ### Endpoint /v1/projects/{project_id} ### Parameters #### Path Parameters - **project_id** (string) - Required - The ID of the project #### Query Parameters - **limit** (float) - Optional - The number of results to return per page. - **page** (float) - Optional - The page number to retrieve. - **request_options** (RequestOptions) - Optional - Request-specific configuration. ### Request Example ```python from deepgram import DeepgramClient client = DeepgramClient(api_key="YOUR_API_KEY") client.manage.v1.projects.get(project_id="123456-7890-1234-5678-901234", limit=1.1, page=1.1) ``` ### Response #### Success Response (200) - **project** (GetProjectV1Response) - The project object. #### Response Example ```json { "id": "123456-7890-1234-5678-901234", "name": "My Project", "created": "2023-01-01T12:00:00Z" } ``` ``` -------------------------------- ### GET /v1/projects/{project_id}/usage Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves the usage for a specific project. Use Get Project Usage Breakdown for a more comprehensive usage summary. ```APIDOC ## GET /v1/projects/{project_id}/usage ### Description Retrieves the usage for a specific project. Use Get Project Usage Breakdown for a more comprehensive usage summary. ### Method GET ### Endpoint /v1/projects/{project_id}/usage ### Parameters #### Path Parameters - **project_id** (string) - Required - The unique identifier of the project #### Query Parameters - **start** (string) - Required - The start date for the usage period. - **end** (string) - Required - The end date for the usage period. - **accessor** (string) - Optional - The unique identifier of the accessor. - **alternatives** (boolean) - Optional - Whether to include alternative data. - **callback_method** (boolean) - Optional - Whether to include callback method. - **callback** (boolean) - Optional - Whether to include callback information. - **channels** (boolean) - Optional - Whether to include channel information. - **custom_intent_mode** (boolean) - Optional - Whether to include custom intent mode. - **custom_intent** (boolean) - Optional - Whether to include custom intent. - **custom_topic_mode** (boolean) - Optional - Whether to include custom topic mode. - **custom_topic** (boolean) - Optional - Whether to include custom topic. - **deployment** (string) - Optional - The deployment type. - **detect_entities** (boolean) - Optional - Whether to detect entities. - **detect_language** (boolean) - Optional - Whether to detect language. - **diarize** (boolean) - Optional - Whether to diarize. - **dictation** (boolean) - Optional - Whether to enable dictation. - **encoding** (boolean) - Optional - Whether to include encoding information. - **endpoint** (string) - Optional - The endpoint to use. - **extra** (boolean) - Optional - Whether to include extra information. - **filler_words** (boolean) - Optional - Whether to detect filler words. - **intents** (boolean) - Optional - Whether to include intents. - **keyterm** (boolean) - Optional - Whether to include keyterms. - **keywords** (boolean) - Optional - Whether to include keywords. - **language** (boolean) - Optional - Whether to include language information. - **measurements** (boolean) - Optional - Whether to include measurements. - **method** (string) - Optional - The method to use. - **model** (string) - Optional - The model to use. - **multichannel** (boolean) - Optional - Whether to process multichannel audio. - **numerals** (boolean) - Optional - Whether to process numerals. - **paragraphs** (boolean) - Optional - Whether to include paragraphs. - **profanity_filter** (boolean) - Optional - Whether to apply profanity filter. - **punctuate** (boolean) - Optional - Whether to punctuate. - **redact** (boolean) - Optional - Whether to redact sensitive information. - **replace** (boolean) - Optional - Whether to replace information. - **sample_rate** (boolean) - Optional - Whether to include sample rate information. - **search** (boolean) - Optional - Whether to perform a search. - **sentiment** (boolean) - Optional - Whether to detect sentiment. - **smart_format** (boolean) - Optional - Whether to use smart formatting. - **summarize** (boolean) - Optional - Whether to summarize. - **tag** (string) - Optional - The tag to filter by. - **topics** (boolean) - Optional - Whether to include topics. - **utt_split** (boolean) - Optional - Whether to split utterances. - **utterances** (boolean) - Optional - Whether to include utterances. - **version** (boolean) - Optional - Whether to include version information. ### Request Example ```json { "example": "request body" } ``` ### Response #### Success Response (200) - **UsageV1Response** (object) - The usage data for the project. #### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### List All Models Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves metadata for all available public models. Set `include_outdated` to true to also get non-latest versions. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.manage.v1.models.list( include_outdated=True, ) ``` -------------------------------- ### Retrieve Project Usage with DeepgramClient Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Initializes the DeepgramClient and calls the get method to fetch usage data for a specific project with various optional parameters. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.manage.v1.projects.usage.get( project_id="123456-7890-1234-5678-901234", start="start", end="end", accessor="12345678-1234-1234-1234-123456789012", alternatives=True, callback_method=True, callback=True, channels=True, custom_intent_mode=True, custom_intent=True, custom_topic_mode=True, custom_topic=True, deployment="hosted", detect_entities=True, detect_language=True, diarize=True, dictation=True, encoding=True, endpoint="listen", extra=True, filler_words=True, intents=True, keyterm=True, keywords=True, language=True, measurements=True, method="sync", model="6f548761-c9c0-429a-9315-11a1d28499c8", multichannel=True, numerals=True, paragraphs=True, profanity_filter=True, punctuate=True, redact=True, replace=True, sample_rate=True, search=True, sentiment=True, smart_format=True, summarize=True, tag="tag1", topics=True, utt_split=True, utterances=True, version=True, ) ``` -------------------------------- ### GET /v1/projects/{project_id}/balances/{balance_id} Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves details about the specified balance. ```APIDOC ## GET /v1/projects/{project_id}/balances/{balance_id} ### Description Retrieves details about the specified balance. ### Method GET ### Endpoint /v1/projects/{project_id}/balances/{balance_id} ### Parameters #### Path Parameters - **project_id** (str) - Required - The unique identifier of the project - **balance_id** (str) - Required - The unique identifier of the balance #### Request Body - **request_options** (RequestOptions) - Optional - Request-specific configuration. ``` -------------------------------- ### Get Project Usage Breakdown Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves detailed usage metrics for a project, supporting various filters for features and groupings. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.manage.v1.projects.usage.breakdown.get( project_id="123456-7890-1234-5678-901234", start="start", end="end", grouping="accessor", accessor="12345678-1234-1234-1234-123456789012", alternatives=True, callback_method=True, callback=True, channels=True, custom_intent_mode=True, custom_intent=True, custom_topic_mode=True, custom_topic=True, deployment="hosted", detect_entities=True, detect_language=True, diarize=True, dictation=True, encoding=True, endpoint="listen", extra=True, filler_words=True, intents=True, keyterm=True, keywords=True, language=True, measurements=True, method="sync", model="6f548761-c9c0-429a-9315-11a1d28499c8", multichannel=True, numerals=True, paragraphs=True, profanity_filter=True, punctuate=True, redact=True, replace=True, sample_rate=True, search=True, sentiment=True, smart_format=True, summarize=True, tag="tag1", topics=True, utt_split=True, utterances=True, version=True, ) ``` -------------------------------- ### Implementing Custom Sync Transports Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/README.md Provides an example of creating and using a custom synchronous transport for WebSocket-based APIs, allowing for alternative protocols or test doubles. ```APIDOC ## Custom Transports Replace the built-in `websockets` transport with your own implementation for WebSocket-based APIs (Listen, Speak, Agent). This enables alternative protocols (HTTP/2, SSE), test doubles, or proxied connections. Any class that implements the right methods can be used as a transport — no inheritance required. Pass your class (or a factory callable) as `transport_factory` when creating a client. #### Sync transports Implement `send()`, `recv()`, `__iter__()`, and `close()`, then pass the class to `DeepgramClient`: ```python from deepgram import DeepgramClient from deepgram.core.events import EventType class MyTransport: def __init__(self, url: str, headers: dict): ... # establish your connection def send(self, data): ... # send str or bytes def recv(self): ... # return next message def __iter__(self): ... # yield messages until closed def close(self): ... # tear down connection client = DeepgramClient(api_key="...", transport_factory=MyTransport) with client.listen.v1.connect(model="nova-3") as connection: connection.on(EventType.MESSAGE, on_message) connection.start_listening() ``` ``` -------------------------------- ### GET /projects/{project_id}/keys Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves all API keys associated with the specified project. ```APIDOC ## GET /projects/{project_id}/keys ### Description Retrieves all API keys associated with the specified project. ### Parameters #### Path Parameters - **project_id** (str) - Required - The unique identifier of the project #### Query Parameters - **status** (KeysListRequestStatus) - Optional - Only return keys with a specific status - **request_options** (RequestOptions) - Optional - Request-specific configuration. ``` -------------------------------- ### GET /v1/projects/{project_id}/usage/fields Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Lists the features, models, tags, languages, and processing methods used for requests in a specified project. ```APIDOC ## GET /v1/projects/{project_id}/usage/fields ### Description Lists the features, models, tags, languages, and processing method used for requests in the specified project. ### Method GET ### Endpoint /v1/projects/{project_id}/usage/fields ### Parameters #### Path Parameters - **project_id** (str) - Required - The unique identifier of the project #### Query Parameters - **start** (str) - Optional - Start date of the requested date range. Format accepted is YYYY-MM-DD - **end** (str) - Optional - End date of the requested date range. Format accepted is YYYY-MM-DD ### Response #### Success Response (200) - **UsageFieldsV1Response** (object) - The response containing project usage fields. ``` -------------------------------- ### GET /v1/projects/{project_id}/balances Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Generates a list of outstanding balances for the specified project. ```APIDOC ## GET /v1/projects/{project_id}/balances ### Description Generates a list of outstanding balances for the specified project. ### Method GET ### Endpoint /v1/projects/{project_id}/balances ### Parameters #### Path Parameters - **project_id** (str) - Required - The unique identifier of the project #### Request Body - **request_options** (RequestOptions) - Optional - Request-specific configuration. ``` -------------------------------- ### Get Specific Project Billing Balance - Python Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Use this to retrieve details about a specific balance for a project. Requires both project ID and balance ID. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.manage.v1.projects.billing.balances.get( project_id="123456-7890-1234-5678-901234", balance_id="123456-7890-1234-5678-901234", ) ``` -------------------------------- ### GET /v1/projects/{project_id}/billing/fields Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Lists the accessors, deployment types, tags, and line items used for billing data in the specified time period. ```APIDOC ## GET /v1/projects/{project_id}/billing/fields ### Description Lists the accessors, deployment types, tags, and line items used for billing data in the specified time period. Use this endpoint if you want to filter your results from the Billing Breakdown endpoint and want to know what filters are available. ### Method GET ### Endpoint /v1/projects/{project_id}/billing/fields ### Parameters #### Path Parameters - **project_id** (str) - Required - The unique identifier of the project #### Query Parameters - **start** (str) - Optional - Start date of the requested date range. Format accepted is YYYY-MM-DD - **end** (str) - Optional - End date of the requested date range. Format accepted is YYYY-MM-DD ``` -------------------------------- ### Get Specific Project Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Fetches detailed information about a specified project using its project ID. Supports pagination with `limit` and `page` parameters. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.manage.v1.projects.get( project_id="123456-7890-1234-5678-901234", limit=1.1, page=1.1, ) ``` -------------------------------- ### Get Distribution Credentials Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves distribution credentials for a specified project. Requires project ID and distribution credentials ID. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.self_hosted.v1.distribution_credentials.get( project_id="123456-7890-1234-5678-901234", distribution_credentials_id="8b36cfd0-472f-4a21-833f-2d6343c3a2f3", ) ``` -------------------------------- ### Using a Custom HTTP Client Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/README.md Illustrates how to integrate a custom `httpx.Client` for advanced networking configurations like proxies and custom timeouts. ```APIDOC ## Custom HTTP Client Use a custom httpx client for advanced networking features: ```python import httpx from deepgram import DeepgramClient client = DeepgramClient( httpx_client=httpx.Client( proxies="http://proxy.example.com", timeout=httpx.Timeout(30.0) ) ) ``` ``` -------------------------------- ### Manage V1 Projects - List Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves basic information about projects associated with the API key. ```APIDOC ## GET /v1/projects ### Description Retrieves basic information about the projects associated with the API key. ### Method GET ### Endpoint /v1/projects ### Parameters #### Query Parameters - **request_options** (RequestOptions) - Optional - Request-specific configuration. ### Request Example ```python from deepgram import DeepgramClient client = DeepgramClient(api_key="YOUR_API_KEY") client.manage.v1.projects.list() ``` ### Response #### Success Response (200) - **projects** (ListProjectsV1Response) - A list of project objects. #### Response Example ```json { "projects": [ { "id": "123456-7890-1234-5678-901234", "name": "My Project" } ] } ``` ``` -------------------------------- ### Create Distribution Credentials Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Creates a set of distribution credentials for a specified project. Requires a project ID. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.self_hosted.v1.distribution_credentials.create( project_id="123456-7890-1234-5678-901234", ) ``` -------------------------------- ### Get Project Request Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves a specific request for a specific project. ```APIDOC ## GET /v1/projects/{project_id}/requests/{request_id} ### Description Retrieves a specific request for a specific project. ### Method GET ### Endpoint `/v1/projects/{project_id}/requests/{request_id}` ### Parameters #### Path Parameters - **project_id** (str) - Required - The unique identifier of the project. - **request_id** (str) - Required - The unique identifier of the request. ### Request Example ```python from deepgram import DeepgramClient client = DeepgramClient(api_key="YOUR_API_KEY") client.manage.v1.projects.requests.get( project_id="123456-7890-1234-5678-901234", request_id="123456-7890-1234-5678-901234" ) ``` ### Response #### Success Response (200) - **request** (GetProjectRequestV1Response) - The details of the requested project request. ``` -------------------------------- ### POST /projects/{project_id}/keys Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Creates a new API key with specified settings for the project. ```APIDOC ## POST /projects/{project_id}/keys ### Description Creates a new API key with specified settings for the project. ### Parameters #### Path Parameters - **project_id** (str) - Required - The unique identifier of the project #### Request Body - **request** (object) - Required - Key configuration settings ``` -------------------------------- ### Get API Key Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves information about a specified API key. ```APIDOC ## GET /v1/projects/{project_id}/keys/{key_id} ### Description Retrieves information about a specified API key. ### Method GET ### Endpoint /v1/projects/{project_id}/keys/{key_id} ### Parameters #### Path Parameters - **project_id** (str) - Required - The unique identifier of the project - **key_id** (str) - Required - The unique identifier of the API key #### Request Body - **request_options** (typing.Optional[RequestOptions]) - Optional - Request-specific configuration. ### Response #### Success Response (200) - **key** (str) - The API key. - **id** (str) - The unique identifier of the API key. - **project_id** (str) - The unique identifier of the project. - **created** (str) - The creation date of the API key. - **last_accessed** (str) - The last accessed date of the API key. #### Response Example { "key": "YOUR_API_KEY", "id": "123456789012345678901234", "project_id": "123456-7890-1234-5678-901234", "created": "2023-01-01T12:00:00Z", "last_accessed": "2023-01-01T12:00:00Z" } ``` -------------------------------- ### Listen V2 Connect Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Establishes a real-time conversational speech recognition connection. ```APIDOC ## client.listen.v2.connect ### Description Real-time conversational speech recognition with contextual turn detection for natural voice conversations. ### Parameters #### Request Body - **model** (str) - Optional - AI model to use for the transcription - **callback** (str) - Optional - URL to which we'll make the callback request - **callback_method** (str) - Optional - HTTP method by which the callback request will be made - **channels** (str) - Optional - Number of independent audio channels contained in submitted audio - **diarize** (str) - Optional - Recognize speaker changes - **dictation** (str) - Optional - Dictation mode for controlling formatting - **encoding** (str) - Optional - Specify the expected encoding of your submitted audio - **endpointing** (str) - Optional - Control when speech recognition ends - **extra** (str) - Optional - Arbitrary key-value pairs attached to the API response - **filler_words** (str) - Optional - Include filler words like "uh" and "um" - **interim_results** (str) - Optional - Return partial transcripts - **keyterm** (str) - Optional - Boost or suppress specialized terminology - **keywords** (str) - Optional - Boost or suppress specialized terminology - **language** (str) - Optional - BCP-47 language tag - **mip_opt_out** (str) - Optional - Opts out of Model Improvement Program - **multichannel** (str) - Optional - Transcribe each audio channel independently - **numerals** (str) - Optional - Convert numbers to numerical format - **profanity_filter** (str) - Optional - Remove profanity - **punctuate** (str) - Optional - Add punctuation and capitalization - **redact** (str) - Optional - Redact sensitive information - **replace** (str) - Optional - Replace terms or phrases - **sample_rate** (str) - Optional - Sample rate of the submitted audio - **search** (str) - Optional - Search for terms or phrases - **smart_format** (str) - Optional - Apply formatting for readability - **tag** (str) - Optional - Label requests for usage reporting - **utterance_end_ms** (str) - Optional - Silence duration before finalizing speech - **vad_events** (str) - Optional - Return Voice Activity Detection events - **version** (str) - Optional - Version of the model to use - **authorization** (str) - Optional - API key or token for authentication - **request_options** (RequestOptions) - Optional - Request-specific configuration ``` -------------------------------- ### List Project Invites Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Generates a list of existing invites for a specific project. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.manage.v1.projects.members.invites.list( project_id="123456-7890-1234-5678-901234", ) ``` -------------------------------- ### Create a Project API Key Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Create a new API key for a project with specified settings. Requires project ID and request payload. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.manage.v1.projects.keys.create( project_id="project_id", request={"key": "value"}, ) ``` -------------------------------- ### Get Model Information Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves metadata for a specific model within a project. ```APIDOC ## GET /v1/projects/{project_id}/models/{model_id} ### Description Returns metadata for a specific model. ### Method GET ### Endpoint `/v1/projects/{project_id}/models/{model_id}` ### Parameters #### Path Parameters - **project_id** (str) - Required - The unique identifier of the project. - **model_id** (str) - Required - The specific UUID of the model. #### Query Parameters - **include_outdated** (Optional[bool]) - Optional - Returns non-latest versions of models. - **request_options** (Optional[RequestOptions]) - Optional - Request-specific configuration. ### Request Example ```python from deepgram import DeepgramClient client = DeepgramClient(api_key="YOUR_API_KEY") client.manage.v1.projects.models.get( project_id="123456-7890-1234-5678-901234", model_id="af6e9977-99f6-4d8f-b6f5-dfdf6fb6e291" ) ``` ### Response #### Success Response (200) - **metadata** (GetModelV1Response) - Description of the model metadata. ``` -------------------------------- ### Async Deepgram Agent Connection and Configuration Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Demonstrates how to establish an asynchronous connection to the Deepgram agent API, configure agent settings including audio input, listen, think, and speak providers, and set up event handlers for connection status and messages. Use this for real-time conversational AI applications. ```python import asyncio from deepgram import AsyncDeepgramClient from deepgram.core.events import EventType from deepgram.agent.v1.types import ( AgentV1Settings, AgentV1SettingsAgent, AgentV1SettingsAudio, AgentV1SettingsAudioInput, AgentV1SettingsAgentListen, AgentV1SettingsAgentListenProvider_V1, AgentV1Welcome, AgentV1SettingsApplied, AgentV1ConversationText, AgentV1UserStartedSpeaking, AgentV1AgentThinking, AgentV1FunctionCallRequest, AgentV1AgentStartedSpeaking, AgentV1AgentAudioDone, AgentV1Error, AgentV1Warning, ) from deepgram.types import ( ThinkSettingsV1, ThinkSettingsV1Provider_OpenAi, SpeakSettingsV1, SpeakSettingsV1Provider_Deepgram, ) client = AsyncDeepgramClient( api_key="YOUR_API_KEY", ) async def main(): async with client.agent.v1.connect() as agent: # Configure the agent settings = AgentV1Settings( audio=AgentV1SettingsAudio( input=AgentV1SettingsAudioInput( encoding="linear16", sample_rate=16000, ) ), agent=AgentV1SettingsAgent( listen=AgentV1SettingsAgentListen( provider=AgentV1SettingsAgentListenProvider_V1( type="deepgram", model="nova-3", smart_format=True, ) ), think=ThinkSettingsV1( provider=ThinkSettingsV1Provider_OpenAi( type="open_ai", model="gpt-4o-mini", temperature=0.7, ), ), speak=[SpeakSettingsV1( provider=SpeakSettingsV1Provider_Deepgram( type="deepgram", model="aura-2-asteria-en", ) )], ), ) await agent.send_settings(settings) def on_message(message) -> None: if isinstance(message, bytes): print("Received audio event") else: msg_type = getattr(message, "type", "Unknown") print(f"Received {msg_type} event") agent.on(EventType.OPEN, lambda _: print("Connection opened")) agent.on(EventType.MESSAGE, on_message) agent.on(EventType.CLOSE, lambda _: print("Connection closed")) agent.on(EventType.ERROR, lambda error: print(f"Caught: {error}")) # Start listening await agent.start_listening() # Send audio data (raw bytes) await agent.send_media(audio_bytes) # Send keep-alive await agent.send_keep_alive() asyncio.run(main()) ``` -------------------------------- ### Get Model Metadata Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves metadata for a specific model using the DeepgramClient. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.manage.v1.projects.models.get( project_id="123456-7890-1234-5678-901234", model_id="af6e9977-99f6-4d8f-b6f5-dfdf6fb6e291", ) ``` -------------------------------- ### List Project Billing Balances - Python Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Use this to generate a list of outstanding balances for a specified project. Requires the project ID. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.manage.v1.projects.billing.balances.list( project_id="123456-7890-1234-5678-901234", ) ``` -------------------------------- ### GET /v1/projects/{project_id}/billing/purchases Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Returns the original purchased amount on an order transaction. ```APIDOC ## GET /v1/projects/{project_id}/billing/purchases ### Description Returns the original purchased amount on an order transaction. ### Method GET ### Endpoint /v1/projects/{project_id}/billing/purchases ### Parameters #### Path Parameters - **project_id** (str) - Required - The unique identifier of the project #### Query Parameters - **limit** (float) - Optional - Number of results to return per page. Default 10. Range [1,1000] ``` -------------------------------- ### List Project Models Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Returns metadata for models accessible to the project, with an option to include outdated models. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.manage.v1.projects.models.list( project_id="123456-7890-1234-5678-901234", include_outdated=True, ) ``` -------------------------------- ### Get Specific Project Request Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves details for a specific request within a project. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.manage.v1.projects.requests.get( project_id="123456-7890-1234-5678-901234", request_id="123456-7890-1234-5678-901234", ) ``` -------------------------------- ### Create Project Invite Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Generates a new invite for a specific project using the invitee's email and scope. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.manage.v1.projects.members.invites.create( project_id="123456-7890-1234-5678-901234", email="email", scope="scope", ) ``` -------------------------------- ### Connect to Speak V1 API (Python) Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Use this synchronous connection for text-to-speech. Ensure you have your API key and specify the desired model, encoding, and sample rate. ```python from typing import Union from deepgram import DeepgramClient from deepgram.core.events import EventType from deepgram.speak.v1.types import ( SpeakV1Text, SpeakV1Metadata, SpeakV1Flushed, SpeakV1Cleared, SpeakV1Warning, ) SpeakV1Response = Union[bytes, SpeakV1Metadata, SpeakV1Flushed, SpeakV1Cleared, SpeakV1Warning] client = DeepgramClient( api_key="YOUR_API_KEY", ) with client.speak.v1.connect( model="aura-2-asteria-en", encoding="linear16", sample_rate=24000 ) as connection: def on_message(message: SpeakV1Response) -> None: if isinstance(message, bytes): print("Received audio event") else: msg_type = getattr(message, "type", "Unknown") print(f"Received {msg_type} event") connection.on(EventType.OPEN, lambda _: print("Connection opened")) connection.on(EventType.MESSAGE, on_message) connection.on(EventType.CLOSE, lambda _: print("Connection closed")) connection.on(EventType.ERROR, lambda error: print(f"Caught: {error}")) # Start listening connection.start_listening() # Send text to be converted to speech connection.send_text(SpeakV1Text(text="Hello, world!")) # Send control messages connection.send_flush() connection.send_close() ``` -------------------------------- ### GET /agent/v1/settings/think/models Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves the available think models that can be used for AI agent processing. ```APIDOC ## GET /agent/v1/settings/think/models ### Description Retrieves the available think models that can be used for AI agent processing. ### Method GET ### Parameters #### Request Body - **request_options** (typing.Optional[RequestOptions]) - Optional - Request-specific configuration. ``` -------------------------------- ### Create API Key Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Creates a new API key for a specified project. ```APIDOC ## POST /v1/projects/{project_id}/keys ### Description Creates a new API key for a specified project. ### Method POST ### Endpoint /v1/projects/{project_id}/keys ### Parameters #### Path Parameters - **project_id** (str) - Required - The unique identifier of the project #### Request Body - **request** (CreateKeyV1RequestOne) - Required - The request body for creating an API key. - **request_options** (typing.Optional[RequestOptions]) - Optional - Request-specific configuration. ### Response #### Success Response (200) - **key** (str) - The newly created API key. - **message** (str) - A confirmation message. #### Response Example { "key": "YOUR_NEW_API_KEY", "message": "Key created successfully" } ``` -------------------------------- ### Commit Changes to Repository Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/CONTRIBUTING.md Stage all changes and create a commit with a descriptive message. ```bash git add . git commit -m "feat: your change description" ``` -------------------------------- ### Use a Custom HTTP Client Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/README.md Integrate a custom httpx client for advanced networking features like proxies and custom timeouts. ```python import httpx from deepgram import DeepgramClient client = DeepgramClient( httpx_client=httpx.Client( proxies="http://proxy.example.com", timeout=httpx.Timeout(30.0) ) ) ``` -------------------------------- ### Manage V1 Models - Get Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves metadata for a specific public model using its ID. ```APIDOC ## GET /v1/models/{model_id} ### Description Returns metadata for a specific public model. ### Method GET ### Endpoint /v1/models/{model_id} ### Parameters #### Path Parameters - **model_id** (string) - Required - The specific UUID of the model #### Query Parameters - **request_options** (RequestOptions) - Optional - Request-specific configuration. ### Request Example ```python from deepgram import DeepgramClient client = DeepgramClient(api_key="YOUR_API_KEY") client.manage.v1.models.get(model_id="af6e9977-99f6-4d8f-b6f5-dfdf6fb6e291") ``` ### Response #### Success Response (200) - **model** (GetModelV1Response) - The model object. #### Response Example ```json { "id": "af6e9977-99f6-4d8f-b6f5-dfdf6fb6e291", "name": "nova-2", "created": "2023-01-01T12:00:00Z", "deprecated": false } ``` ``` -------------------------------- ### GET /v1/projects/{projectId}/usage/breakdown Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves the usage breakdown for a specific project with various filter options. ```APIDOC ## GET /v1/projects/{projectId}/usage/breakdown ### Description Retrieves the usage breakdown for a specific project, with various filter options by API feature or by groupings. Setting a feature (e.g. diarize) to true includes requests that used that feature, while false excludes requests that used it. Multiple true filters are combined with OR logic, while false filters use AND logic. ### Method GET ### Endpoint /v1/projects/{projectId}/usage/breakdown ### Parameters #### Path Parameters - **projectId** (str) - Required - The unique identifier of the project #### Query Parameters - **start** (str) - Optional - Start date for the usage data. - **end** (str) - Optional - End date for the usage data. - **grouping** (str) - Optional - Grouping criteria for the usage data (e.g., "accessor"). - **accessor** (str) - Optional - Filter usage by a specific accessor ID. - **alternatives** (bool) - Optional - Include requests that used the "alternatives" feature. - **callback_method** (bool) - Optional - Include requests that used the "callback_method" feature. - **callback** (bool) - Optional - Include requests that used the "callback" feature. - **channels** (bool) - Optional - Include requests that used the "channels" feature. - **custom_intent_mode** (bool) - Optional - Include requests that used the "custom_intent_mode" feature. - **custom_intent** (bool) - Optional - Include requests that used the "custom_intent" feature. - **custom_topic_mode** (bool) - Optional - Include requests that used the "custom_topic_mode" feature. - **custom_topic** (bool) - Optional - Include requests that used the "custom_topic" feature. - **deployment** (str) - Optional - Filter usage by deployment type (e.g., "hosted"). - **detect_entities** (bool) - Optional - Include requests that used the "detect_entities" feature. - **detect_language** (bool) - Optional - Include requests that used the "detect_language" feature. - **diarize** (bool) - Optional - Include requests that used the "diarize" feature. - **dictation** (bool) - Optional - Include requests that used the "dictation" feature. - **encoding** (bool) - Optional - Include requests that used the "encoding" feature. - **endpoint** (str) - Optional - Filter usage by endpoint type (e.g., "listen"). - **extra** (bool) - Optional - Include requests that used the "extra" feature. - **filler_words** (bool) - Optional - Include requests that used the "filler_words" feature. - **intents** (bool) - Optional - Include requests that used the "intents" feature. - **keyterm** (bool) - Optional - Include requests that used the "keyterm" feature. - **keywords** (bool) - Optional - Include requests that used the "keywords" feature. - **language** (bool) - Optional - Include requests that used the "language" feature. - **measurements** (bool) - Optional - Include requests that used the "measurements" feature. - **method** (str) - Optional - Filter usage by method (e.g., "sync"). - **model** (str) - Optional - Filter usage by model ID. - **multichannel** (bool) - Optional - Include requests that used the "multichannel" feature. - **numerals** (bool) - Optional - Include requests that used the "numerals" feature. - **paragraphs** (bool) - Optional - Include requests that used the "paragraphs" feature. - **profanity_filter** (bool) - Optional - Include requests that used the "profanity_filter" feature. - **punctuate** (bool) - Optional - Include requests that used the "punctuate" feature. - **redact** (bool) - Optional - Include requests that used the "redact" feature. - **replace** (bool) - Optional - Include requests that used the "replace" feature. - **sample_rate** (bool) - Optional - Include requests that used the "sample_rate" feature. - **search** (bool) - Optional - Include requests that used the "search" feature. - **sentiment** (bool) - Optional - Include requests that used the "sentiment" feature. - **smart_format** (bool) - Optional - Include requests that used the "smart_format" feature. - **summarize** (bool) - Optional - Include requests that used the "summarize" feature. - **tag** (str) - Optional - Filter usage by a specific tag. - **topics** (bool) - Optional - Include requests that used the "topics" feature. - **utt_split** (bool) - Optional - Include requests that used the "utt_split" feature. - **utterances** (bool) - Optional - Include requests that used the "utterances" feature. - **version** (bool) - Optional - Include requests that used the "version" feature. #### Request Body None ### Response #### Success Response (200) - **usage** (object) - Object containing usage breakdown details. #### Response Example ```json { "usage": { "total_seconds": 120, "total_characters": 12000, "features": { "diarize": { "seconds": 60, "characters": 6000 } } } } ``` ``` -------------------------------- ### List Projects Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves basic information about all projects associated with your API key. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.manage.v1.projects.list() ``` -------------------------------- ### Get Specific Model Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Fetches metadata for a particular public model using its unique model ID. ```python from deepgram import DeepgramClient client = DeepgramClient( api_key="YOUR_API_KEY", ) client.manage.v1.models.get( model_id="af6e9977-99f6-4d8f-b6f5-dfdf6fb6e291", ) ``` -------------------------------- ### GET /v1/projects/{projectId}/members/{memberId}/scopes Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Retrieves a list of scopes for a specific member within a project. ```APIDOC ## GET /v1/projects/{projectId}/members/{memberId}/scopes ### Description Retrieves a list of scopes for a specific member within a project. ### Method GET ### Endpoint /v1/projects/{projectId}/members/{memberId}/scopes ### Parameters #### Path Parameters - **projectId** (str) - Required - The unique identifier of the project - **memberId** (str) - Required - The unique identifier of the Member #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **scopes** (list[str]) - A list of scopes assigned to the member. #### Response Example ```json { "scopes": ["admin", "read"] } ``` ``` -------------------------------- ### Create Distribution Credentials Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/reference.md Creates a set of distribution credentials for the specified project. ```APIDOC ## POST /v1/distribution_credentials ### Description Creates a set of distribution credentials for the specified project. ### Method POST ### Endpoint /v1/distribution_credentials ### Parameters #### Query Parameters - **project_id** (str) - Required - The unique identifier of the project - **request_options** (RequestOptions) - Optional - Request-specific configuration. ### Request Body - **name** (str) - Required - Name of the distribution credentials ### Request Example ```json { "name": "my-distribution-credential" } ``` ### Response #### Success Response (200) - **id** (str) - The unique identifier of the distribution credentials - **name** (str) - The name of the distribution credentials - **secret** (str) - The secret key for the distribution credentials #### Response Example ```json { "id": "123e4567-e89b-12d3-a456-426614174000", "name": "my-distribution-credential", "secret": "a_very_secret_key" } ``` ``` -------------------------------- ### Create .env file for API Key Source: https://github.com/deepgram/deepgram-python-sdk/blob/main/examples/README.md Alternatively, create a `.env` file in your project root to store your Deepgram API key. ```bash DEEPGRAM_API_KEY=your-api-key-here ```