Skip to main content
The X Calls API is in development. It isn’t generally available yet, and endpoints and payloads may still change.
This agent joins a call, plays a greeting tone where your text-to-speech would speak, stops talking when someone interrupts, and logs events and audio levels. It runs on Node.js 22 or later with no dependencies.
agent.mjs

Bridging a realtime model

To connect a realtime speech-to-speech model instead, keep the same loop:
  1. Join at the model’s native rate (for example 24 kHz) so no resampling is needed.
  2. Forward each binary frame from X to the model’s audio input.
  3. Forward each audio chunk the model produces to X as a binary frame.
  4. When the model reports that the user started speaking (or X sends speech.started), send audio.clear.
  5. On session.ended, close the model session.
See Media WebSocket for every event and command.