satham
An async Python client for satham's realtime speech-to-speech API. Your agent brings its own
instructions, greeting and tools; you connect with your API key, stream the caller's audio in and
the agent's audio out, follow transcripts, interruptions and language changes, answer tool calls, and
change any of the call's controls while it runs. It also speaks text with
kural-1, satham's text-to-speech model (Text to speech).
Python 3.11+. One dependency: websockets.
pip install satham
Framework adapters: livekit-plugins-satham for
LiveKit Agents and pipecat-satham for Pipecat.
A call
You pass your API key, created in the console at https://console.satham.ai/keys (or set
SATHAM_API_KEY). The endpoint is https://api.satham.ai; pass url or set SATHAM_URL only to use
another. Calls with satham-1 are enabled on request (https://satham.ai/contact).
import asyncio
import os
import satham
ROLE = "You are Asha, who books site visits for Example Homes. Keep every reply short."
async def main() -> None:
async with satham.connect(
api_key=os.environ["SATHAM_API_KEY"], # url= only for an endpoint other than api.satham.ai
instructions=ROLE, # the agent's role: your prompt
greeting="Hello, this is Asha from Example Homes. Is this a good time?",
language="en", # or "auto"; the call can follow the caller into another language
language_switch="auto",
sample_rate=16_000, # the caller audio you send: 16-bit mono PCM
) as call:
asyncio.create_task(stream_microphone(call)) # await call.send_audio(pcm) per packet
async for event in call:
match event:
case satham.ResponseAudio():
speaker.write(event.data) # PCM in call.output_audio's format
case satham.SpeechStarted() | satham.ResponseInterrupted():
speaker.clear() # the caller is talking: stop at once
case satham.TranscriptFinal():
print("caller:", event.text, event.language)
case satham.ResponseDone():
print("agent:", event.text)
case satham.SessionUpdated():
print("now in", event.language, "because of the", event.reason)
asyncio.run(main())
Without a greeting the caller speaks first. connect() raises AuthenticationError,
ServerBusyError, InvalidRequestError (a refused setting) or SathamError (connection failures
and timeouts; .code says which). A bad value fails in the client with ValueError before anything
is sent.
During the call, await call.update(...) changes any control (the same names as connect; only what
you pass is sent, and instructions can change too), call.commit() ends the caller's turn now
(push-to-talk), call.cancel() stops the reply, and call.close() ends the call. call.language
follows every language change.
Replies on demand: await call.create_response(instructions=None) asks for a reply now (to open the
call, or after a quiet spell; instructions guide that reply alone), and await call.say(text) has
the agent say fixed words in its voice. While a reply is under way, or the caller is speaking, the
server answers with a non-fatal response_in_progress error.
Controls
Every keyword of connect() and update() besides the URL, key and audio format is a control
(satham.SessionControls, a TypedDict). OpenAI's names are used where LiveKit's OpenAI realtime
plugin has one; groups (turn_detection, input_audio_noise_reduction, input_audio_transcription,
phrasing) are dicts of the keys shown. A control you leave out is not sent, so the server's default
holds. Values are checked against the ranges below, or against your server's once
await client.load_controls() has read them from GET /v1/info.
The controls marked "needs session controls" need a satham server with session controls (its
GET /v1/info lists controls, as the server does since 2026-11-16); an older server refuses them
when the call starts. greeting and agent belong to the start of a call. Setting
input_audio_noise_reduction's mode alone resets strength_db to that mode's preset, so send both
to keep a custom strength; None leaves noise reduction at the server's default (on), and "none"
turns it off. agent is
an optional preset on the server (such as a demo's) and is not needed.