Skip to main content
This example runs a Session WebSocket demo from the terminal: your microphone is streamed to Vatel, and the agent’s audio is played through your speaker. Transcripts and events are printed to the console. It uses the Vatel Python SDK with numpy and sounddevice for capture and playback.

Session token

REST endpoint used to obtain a short-lived JWT for the WebSocket connection.

Connection

WebSocket channel, message types, and request/response flow.

Prerequisites

  • Python 3.9+
  • Organization API key and agent ID (agent UUID)
  • Dependencies: Vatel Python SDK, numpy, sounddevice (for mic and speaker)

Setup

1

Clone or copy the example

Use the example from the vatel-nextjs-starters repo, or copy examples/python-cli/ (e.g. run_session.py and requirements.txt) into your project.
2

Install dependencies

From the directory that contains requirements.txt:
This installs the Vatel SDK (from the repo), numpy, and sounddevice.
3

Run the session

Pass your API key and agent ID via arguments or environment variables:
Or set VATEL_API_KEY and VATEL_AGENT_ID. Optional: --base-url or VATEL_BASE_URL to use a different API host.

How it works

  1. Client and token - A Client is created with the API key and base URL (default https://api.vatel.ai). The script gets a session token with client.session.generate_token_async(agent_id).
  2. Connection - client.connect(token=token, url=base_url) opens the WebSocket. A background thread captures microphone audio at 24 kHz mono 16-bit PCM, base64-encodes it, and feeds it into an async queue; a coroutine reads from the queue and sends chunks via conn.send_input_audio(chunk).
  3. Playback - A sounddevice output stream runs in a callback. When response_audio messages arrive, the base64 payload is decoded and pushed into a queue; the callback plays the PCM data.
  4. Events - The script prints session_started, response_text, input_audio_transcript, and session_ended to the console. For tool_call it sends a simple "ok" reply so the agent can continue.

Project structure

Code

Full-duplex session: mic → server, agent audio → speaker. Uses a thread for mic capture and a queue + sounddevice callback for playback.