Skip to main content
AssemblyAI offers a Voice Agent API that runs speech-to-text, an LLM, and text-to-speech behind one WebSocket. By default the agent uses AssemblyAI’s managed model, but the llm field accepts any OpenAI-compatible chat completions endpoint. Pointing it at SambaCloud lets an AssemblyAI voice agent answer with SambaNova models. Because voice depends on how fast the first sound arrives, this guide also measures that for each model.

Prerequisites

macOS ships with Python 3.9 and exposes it as python3 rather than python. Check your version with python3 --version. If it is below 3.10, install a supported version with pyenv, uv, or brew install python@3.12 before continuing.

Installation and setup

1

Create a virtual environment

2

Install the dependencies

This guide was tested with requests 2.34.2 and websockets 17.4 on Python 3.12.
3

Set your API keys

Connect a voice agent to SambaCloud

You create the agent with an HTTP request and connect to it over a WebSocket. The part that changes for SambaNova is the llm field:
  • base_url is the SambaCloud base URL. AssemblyAI calls {base_url}/chat/completions, so keep the /v1.
  • model is a SambaCloud model ID.
  • api_key is your SambaCloud key. AssemblyAI encrypts it and never returns it in a response.
  • The list takes one entry. The model must support streamed chat completions, which SambaCloud models do.
This guide works with SambaCloud only. AssemblyAI requires the base_url to use https and a public host, so it cannot reach a private SambaStack instance.
The script below creates an agent with this llm entry, connects to it, and types a question to the agent with a conversation.message event instead of speaking it, so you can test without a microphone. It prints the reply and the time from the request to the first sound, and saves the spoken reply as reply.wav. The agent is deleted at the end, because it holds your SambaCloud key.
voice_agent.py
Output
Time to first audio is measured on the client, from the moment the script asks for a reply to the first audio chunk. It includes the model’s first token and AssemblyAI’s text-to-speech. Because this test sends text, it does not include speech-to-text time. Your numbers depend on the model, the prompt, and your network.

Choose a model for voice

The script uses MiniMax-M3.1-Flash. Voice is where first-sound latency matters most, so it is worth comparing models. Each row is the time to first audio over 5 runs of the script above, changing only MODEL, measured on 6 November 2026:
MiniMax-M3.1-Flash is a reasoning model. It thinks before it answers, and that time counts toward the first sound, so the reply starts later than with a non-reasoning model. For a voice agent where the pause matters most, set MODEL to gpt-oss-120b, the fastest model in the table.
Meta-Llama-3.3-70B-Instruct is not in the table because SambaCloud deprecated it on 17 November 2026. A request for it returns HTTP 503, and the script ends with reply.error: llm_provider_error. See Deprecations for the replacement, and confirm that GET https://api.sambanova.ai/v1/models lists any model before you choose it.
First-audio times vary between runs and between days. Every model except MiniMax-M3.1-Flash had at least one run about 2 seconds or more slower than its usual time, and gemma-4-31B-it was slower and less steady than the others. Measure over several runs before you quote a latency number.

Troubleshooting

An environment variable is not set in the shell you run Python from. Set it as shown in Installation and setup, then run the script again from the same shell.
AssemblyAI rejected ASSEMBLYAI_API_KEY. Copy a key from the API keys page and export it again.
AssemblyAI validated the agent and refused it. Print agent.text to read the reason. For example, llm[0].base_url ... must use https:// means the base_url starts with http://. Use https://api.sambanova.ai/v1.
The agent was created, but AssemblyAI’s request to SambaCloud failed because the api_key in the llm entry is not valid. Copy a key from the SambaCloud API keys page and run the script again.
The model value is not a SambaCloud model ID. See SambaCloud models for the current list.
This generic message was what AssemblyAI returned when the base_url was https://api.sambanova.ai without /v1. Set it to https://api.sambanova.ai/v1.
SambaCloud returned an error for the request. This is what a deprecated model produces: Meta-Llama-3.3-70B-Instruct was deprecated on 17 November 2026, and a direct SambaCloud request for it returns HTTP 503 “currently not available”. Call GET https://api.sambanova.ai/v1/models with your key and set model to one of the IDs it lists.
SambaCloud did not answer in time. This appeared once in 5 runs with gemma-4-31B-it, the model with the slowest and least steady first-audio times in the table. Run the script again, or set MODEL to a steadier model such as gpt-oss-120b.
A failed model request does not stop the session. AssemblyAI sends a reply.error event and then a normal reply.done, so the script ends quietly. Read the reply.error line the script prints for the cause. The reply.error event is not listed in AssemblyAI’s events reference, but the API sends it.
The script deletes its agent when it finishes, even after an error in the session. If the process is killed before then, delete the agent with DELETE https://agents.assemblyai.com/v1/agents/<agent-id>, because it stores your SambaCloud key.

Additional resources