gordonklaus/portaudio) 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
- Go 1.21+ (with CGO enabled for PortAudio)
- PortAudio dev libraries:
- macOS:
brew install portaudio - Ubuntu/Debian:
apt-get install portaudio19-dev
- macOS:
- Organization API key and agent ID (agent UUID)
Setup
1
Clone or copy the example
Use the example from the vatel-nextjs-starters repo, or copy
examples/golang-cli/ (main.go, go.mod) into your project.2
Install dependencies
From the example directory:This pulls the Vatel Go SDK and
github.com/gordonklaus/portaudio.3
Build and run
VATEL_API_KEY and VATEL_AGENT_ID and run ./run_session. Optional: -base-url for a different API host; -output path to write response audio to a PCM file (default session_out.pcm).How it works
- Client and token - A client is created with
vatel.New(baseURL, apiKey). The program gets a session token withclient.SessionToken(ctx, agentID). - Connection -
client.DialConnection(ctx, token)opens the WebSocket. A goroutine runsrunMic(ctx, conn): it opens the default PortAudio input stream (24 kHz, mono, 16-bit), reads blocks, and sends them withconn.SendInputAudioBytes(pcm). - Playback - A PortAudio output stream runs with a callback. When
response_audiomessages arrive, the base64 payload is decoded and pushed into a buffer; the callback drains the buffer and plays PCM. If-outputis set, the same decoded PCM is written to that file. - Events - The main loop consumes
conn.Messages(). It printssession_started,response_text, andsession_ended, and logs tool calls while sending"ok"viaconn.SendToolCallOutput. Onsession_endedor context cancel (SIGINT/SIGTERM), the mic goroutine is stopped and the program exits.
Project structure
Code
- main.go
- go.mod
Full-duplex session: mic → server, agent audio → speaker (and optional PCM file). Uses PortAudio for mic and playback; graceful shutdown on SIGINT/SIGTERM.
Audio format
- Input: microphone only - PCM 16-bit, 24 kHz, mono.
-
Output: same format; played on the speaker and, if
-outputis set, written to that file. To play the file:

