Skip to main content
This page is part of an AI coding agent skill and is written for agents, not humans. For the human-readable Base44 docs, see the developer documentation.

Voice Module

Live voice conversations between your app’s users and an AI agent, via base44.asServiceRole.voice.
Backend only, beta. This module is only available on a client in service role authentication mode — base44.asServiceRole.voice. It cannot be used from the browser. The module is in beta and may change.

Contents


Overview

The voice agent can use your app’s tools through one of the app’s MCP profiles, acting as the current user. Audio flows directly between the browser and the voice model over WebRTC — your backend only creates and ends the session, it never touches the audio stream. A session takes three steps:
  1. The browser creates a WebRTC SDP offer (RTCPeerConnection.createOffer()) and sends it to one of your backend functions.
  2. The backend function calls createSession() with the offer and your voice settings, and returns the SDP answer to the browser.
  3. The browser applies the answer with RTCPeerConnection.setRemoteDescription(), and the conversation starts.
Keep the instructions, models, and MCP profile ID in the backend function — only the SDP offer should come from the browser. If the current request has no authenticated user, the app’s tools run as a guest, which only works in apps that allow anonymous access.

Methods

createSession(options)

Parameters (VoiceSessionOptions): There’s no app ID parameter — the service-role client already identifies the app, so the route isn’t app-scoped. Returns: Promise<VoiceSession> (see Type Definitions). Each call uses credits from the workspace that owns the app. The session ends on its own when idle or at its maximum duration; call endSession() to end it sooner. Throws: a Base44Error with one of these code values:
  • insufficient_credits — the workspace is out of credits.
  • authentication_required — the app requires a current user, and the request had none.
  • unsupported_voice_model — the voice model isn’t supported.
  • unsupported_agent_model — the agent model isn’t supported.
  • voice_settings_rejected — the voice provider rejected the settings (e.g. instructions too long).
  • invalid_request — a value in options is invalid.
  • rate_limited — too many sessions created in a short time.
  • voice_capacity_exceeded — voice capacity is temporarily unavailable.
  • voice_connection_failed — the voice provider couldn’t be reached or rejected the request.
Example:

endSession(sessionId)

Parameters: Returns: Promise<void> that resolves when Base44 accepts the request; the session closes in the background. Ending a session that already ended succeeds, so it’s safe to call more than once. Throws: a Base44Error with one of these code values:
  • voice_session_not_found — the session ID wasn’t issued to your app.
  • voice_connection_failed — Base44 couldn’t reach its background processing (it closes the session directly where possible; retrying is safe).
The SDK also validates sessionId locally before making the request: a missing or non-string value throws a plain Error("Session ID is required and must be a string"), not a Base44Error. Example:

Notes

  • Service role only, backend only. voice exists solely on base44.asServiceRole.voice; there is no frontend-accessible base44.voice. Call it from a Base44-hosted backend function.
  • Beta. The shape of this module may change.
  • Audio never passes through your backend — only the SDP offer/answer handshake does. The browser and the voice model exchange audio directly over WebRTC after your backend returns the SDP answer.
  • environment on the returned session tells you whether the voice agent is using the published ('live') or draft ('draft') MCP profile. 'draft' is served when the app’s owner or an editor starts the session from the app editor preview, so voice works before the app is published.
  • This module intentionally documents no fixed list of voice/model names, instruction length limits, session durations, or prices — Base44 validates those server-side so a backend rule change doesn’t require an SDK release. Handle the Base44Error codes above instead of hardcoding assumed limits.

Type Definitions