Invoke a Deepgram SageMaker Endpoint
Once your endpoint is deployed and in service, you invoke it to transcribe audio. A real-time endpoint supports two invocation modes, depending on how you need the response returned.
Passing Deepgram parameters. For synchronous invocations, the Deepgram model and feature parameters are passed in the CustomAttributes field (the X-Amzn-SageMaker-Custom-Attributes header) as v1/listen?model=...&language=.... For streaming, the same values are split across ModelInvocationPath (v1/listen) and ModelQueryString. AWS limits ModelQueryString to 2048 characters; see Troubleshooting if a long query, such as a large keyterm list, fails or hangs. In all cases an API path such as v1/listen is required — without it the container returns a 404. The examples on this page use v1/listen (speech-to-text), but other routes are available (for example, v1/speak for text-to-speech).
When you need low latency and/or no traffic over the public internet, run your client in the same AWS Region as the endpoint and connect through a SageMaker Runtime interface VPC endpoint in your client’s Availability Zone. Your invocation code stays the same, including over FIPS endpoints.
Complete, runnable examples for both modes — in Python, TypeScript, and Java — are maintained in the deepgram-devs/dg-sagemaker repository. The sections below explain each mode and link to the corresponding example. See the repository’s README for setup and prerequisites.
Use the Deepgram SDKs with the SageMaker transport
You don’t have to call the AWS APIs directly. The Deepgram SDKs can target a SageMaker endpoint through a SageMaker transport, so you keep the same client-side request and response patterns whether you call the Deepgram-hosted API or your own SageMaker deployment. You swap the transport; your listen request and result-handling code stays the same.
For example, the Deepgram Java SDK pairs with the Deepgram SageMaker transport (com.deepgram:deepgram-sagemaker):
The remaining sections show the underlying AWS APIs directly, which apply to any language.
Streaming (real-time)
Use streaming for live, interactive transcription over a persistent bidirectional connection. You send audio chunks and receive transcription results as the audio is processed, up to 30 minutes per connection.
Streaming uses the HTTP/2 bidirectional streaming client (@aws-sdk/client-sagemaker-runtime-http2 in TypeScript, aws-sdk-sagemaker-runtime-http2 in Python) against the SageMaker bidirectional runtime endpoint (https://runtime.sagemaker.<region>.amazonaws.com:8443). The request Body is an async iterable of payload parts:
- Binary audio is sent as a
Bytespayload withDataType: "BINARY". - Control messages (for example,
KeepAliveandCloseStream) are sent as UTF-8 encoded JSON withDataType: "UTF8".
Always include :8443 in the endpoint URL. The bidirectional streaming runtime listens on port 8443, not 443. A streaming client that hangs with no error and never receives a response is almost always pointed at the endpoint without :8443.
Python
TypeScript
Requires aws-sdk-sagemaker-runtime-http2 0.11 or later with the awscrt extra (pip install "aws-sdk-sagemaker-runtime-http2[awscrt]>=0.11"). The client takes explicit credentials and an AWS CRT transport; payload events are typed.
For the complete examples — file and microphone capture, payload wrapping, keepalive handling, and stream processing — see:
- TypeScript:
js-stt/stt.file.tsandstt.microphone.ts - Python:
python-stt/stt_wav_stress.py(streamsubcommand)
Synchronous (real-time)
Use synchronous invocation to transcribe a single pre-recorded file and receive the full transcript in one immediate response. This is Deepgram’s “batch” transcription on a real-time endpoint — there’s no streaming connection and no queue. The request body is capped at 25 MB; use streaming for larger audio.
You send the audio as the request body to InvokeEndpoint, pass the Deepgram parameters via CustomAttributes, and parse the transcript from the JSON response.
For the complete example, see python-stt/stt_wav_stress.py (batch subcommand) in the repository.
Asynchronous
Asynchronous invocation (InvokeEndpointAsync, files up to 1 GB) is temporarily not supported for Marketplace-hosted Deepgram. If your use case needs it, contact a Deepgram representative.
Invoke through a SageMaker Runtime interface endpoint
Use an interface VPC endpoint for SageMaker Runtime, powered by AWS PrivateLink, when you need low latency and/or no traffic over the public internet. The interface endpoint places elastic network interfaces with private IP addresses in your VPC subnets. Clients in your VPC then reach SageMaker Runtime over the AWS network, without an internet gateway, a NAT gateway, or a public IP address.
Interface endpoints apply to every invocation mode on this page: streaming (InvokeEndpointWithBidirectionalStream), synchronous (InvokeEndpoint), and the Deepgram SDKs’ SageMaker transport. Your invocation code stays the same.
Create the interface endpoint
Create an interface endpoint for SageMaker Runtime in the same Region as your Deepgram SageMaker endpoint:
If you invoke over FIPS endpoints, create the endpoint for com.amazonaws.<region>.sagemaker.runtime-fips instead. See Combine with FIPS endpoints.
Configure it for latency:
- Place it in every Availability Zone your clients run in. Choose a subnet in each client Availability Zone so each client reaches an endpoint network interface in its own zone. AWS requires the interface endpoint in the client’s Availability Zone for private DNS resolution of the SageMaker Runtime hostname; without it, DNS resolution can fail.
- Enable private DNS. The standard hostname
runtime.sagemaker.<region>.amazonaws.comthen resolves to the interface endpoint’s private IP addresses inside your VPC, so existing clients use it without code changes. Your VPC must have DNS hostnames and DNS resolution enabled. - Allow both invocation ports in the security group. Attach a security group that allows inbound TCP from your clients on port
443(synchronous invocation) and port8443(bidirectional streaming). - Run clients in the endpoint’s Region. Cross-Region calls add round-trip time to every request and every streamed audio chunk.
Point your client at the interface endpoint
With private DNS enabled, keep the URLs shown elsewhere on this page. Streaming clients still connect to https://runtime.sagemaker.<region>.amazonaws.com:8443, and boto3 resolves the synchronous hostname itself.
If you don’t enable private DNS, use the endpoint-specific DNS name that AWS assigns to your interface endpoint, in the form <vpce-id>.runtime.sagemaker.<region>.vpce.amazonaws.com:
To list the DNS names AWS assigned to your interface endpoint, run aws ec2 describe-vpc-endpoints --vpc-endpoint-ids <vpce-id> --query 'VpcEndpoints[].DnsEntries'.
Combine with FIPS endpoints
SageMaker Runtime publishes its FIPS endpoint as a separate PrivateLink service, com.amazonaws.<region>.sagemaker.runtime-fips. An interface endpoint for sagemaker.runtime serves only the standard hostname, so a client configured for FIPS still resolves runtime-fips.sagemaker.<region>.amazonaws.com to a public address. To keep FIPS traffic private:
- Create the interface endpoint with
--service-name com.amazonaws.<region>.sagemaker.runtime-fipsand private DNS enabled, in a Region that offers FIPS endpoints. - Keep the per-client FIPS configuration from Use FIPS endpoints. With private DNS,
runtime-fips.sagemaker.<region>.amazonaws.comresolves to the interface endpoint’s private IP addresses, and streaming clients keep port8443on that hostname. - If you also call the control plane (
api-fips.sagemaker.<region>.amazonaws.com) from the VPC, create a separate interface endpoint forcom.amazonaws.<region>.sagemaker.api-fips.
VPC endpoint policies aren’t supported for InvokeEndpoint on FIPS SageMaker Runtime endpoints. To restrict which SageMaker endpoints a caller can invoke over FIPS, use IAM identity-based policies rather than an endpoint policy on the runtime-fips interface endpoint.
Confirm traffic uses the interface endpoint
From a client inside the VPC, resolve the hostname your client calls. With private DNS enabled, the answer is a private IP address from your subnets’ CIDR ranges rather than a public AWS address:
Interface endpoints control the network path your traffic takes; FIPS endpoints control the cryptography that protects it. For the security and compliance benefits of VPC endpoints, including endpoint policies that restrict which SageMaker endpoints callers can invoke, see Security and compliance. Interface endpoints incur AWS PrivateLink charges.