Back to home
Lanson Flow Docs

Realtime API

What it does

Real-time streaming speech transcription. Open a WebSocket, send PCM16LE audio frames, receive transcription events.

Endpoint

WSS /v1/audio/transcriptions/stream

Authentication

Three authentication methods:

MethodUsageUse case
Bearer headerAuthorization: Bearer sk-...Server-side clients
Query token?access_token=rt_...Browser (session token)
Query token (alias)?token=rt_...Browser (session token)

Session tokens are obtained via POST /v1/audio/transcriptions/session-token and are valid for 60 seconds. See Authentication.

Connection

Upgrade conditions

  • Request must be a WebSocket upgrade, otherwise 426 websocket_required
  • Gateway must be enabled, otherwise 503 gateway_disabled
  • Upstream circuit breaker must be closed, otherwise 503 upstream_unavailable with Retry-After header
  • Connection quota must pass (concurrent connections + handshake rate)
  • On success

    Receives a session.created event:

    {
      "type": "session.created",
      "request_id": "...",
      "session_id": "sess_...",
      "audio": { "format": "pcm_s16le", "sample_rate": 16000, "channels": 1 },
      "turn_detection": { "type": "server_vad" },
      "plan": "free",
      "limits": {
        "max_concurrent_utterances": 2,
        "max_session_seconds": 900,
        "idle_timeout_seconds": 60,
        "remaining_audio_seconds": 3600
      }
    }
    

    Message format

    All messages are JSON text frames or binary PCM audio frames.

  • Text frames: JSON objects, must contain a type field
  • Binary frames: raw PCM audio data (ArrayBuffer)
  • WebSocket close codes

    CodeClose reasonMeaning
    1000—Normal close
    1008session_audio_limitRealtime session audio budget exceeded
    1008audio_quota_exhaustedBilling-window audio budget exhausted
    1008session_duration_limitSession wall-clock duration exceeded
    1009frame_too_largeAudio frame exceeds 1 MiB
    1011client_errorClient socket error or unexpected gateway error
    1013upstream_unavailableRealtime upstream unavailable (circuit breaker open)
    1013upstream_backpressureUpstream is not draining fast enough
    1013client_backpressureClient is not reading events fast enough
    4408idle_timeoutNo audio received within idle timeout window

    Related

  • Client Messages — all client-sent messages
  • Server Events — all server-pushed events
  • Realtime Quickstart — complete example
  • Authentication — auth details