Skip to main content
This example runs a Session WebSocket demo from the terminal using the Vatel Go SDK: your microphone is streamed to Vatel, and the agent’s audio is played through your speaker. Transcripts and events are printed to the console. Response audio can also be written to a raw PCM file. It uses PortAudio (via 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
  • 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

Or set 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

  1. Client and token - A client is created with vatel.New(baseURL, apiKey). The program gets a session token with client.SessionToken(ctx, agentID).
  2. Connection - client.DialConnection(ctx, token) opens the WebSocket. A goroutine runs runMic(ctx, conn): it opens the default PortAudio input stream (24 kHz, mono, 16-bit), reads blocks, and sends them with conn.SendInputAudioBytes(pcm).
  3. Playback - A PortAudio output stream runs with a callback. When response_audio messages arrive, the base64 payload is decoded and pushed into a buffer; the callback drains the buffer and plays PCM. If -output is set, the same decoded PCM is written to that file.
  4. Events - The main loop consumes conn.Messages(). It prints session_started, response_text, and session_ended, and logs tool calls while sending "ok" via conn.SendToolCallOutput. On session_ended or context cancel (SIGINT/SIGTERM), the mic goroutine is stopped and the program exits.

Project structure

Code

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 -output is set, written to that file. To play the file: