Repository: livekit/agents
File: livekit-plugins/livekit-plugins-elevenlabs/livekit/plugins/elevenlabs/stt_v2.py (Python)

Code before:

        elif message_type == "session_started":
            # Session initialization message - informational only
            session_id = data.get("session_id", "unknown")
            config = data.get("config", {})

            # Capture max_tokens_to_recompute for deduplication logic
            if "max_tokens_to_recompute" in config:
                self._max_tokens_to_recompute = config["max_tokens_to_recompute"]
                logger.info(
                    "STTv2: Session started with ID: %s, max_tokens_to_recompute=%s",
                    session_id,
                    self._max_tokens_to_recompute,
                )
            else:
                logger.info("STTv2: Session started with ID: %s", session_id)

        # Error handling for known ElevenLabs error types
        elif message_type in (
            "auth_error",
            "quota_exceeded",
            "transcriber_error",
            "input_error",
            "error",
        ):
            error_msg = data.get("message", "Unknown error")
            error_details = data.get("details", "")
            details_suffix = " - " + error_details if error_details else ""
            logger.error(
                "STTv2: ElevenLabs error [%s]: %s%s",
                message_type,
                error_msg,
                details_suffix,
            )
        else:
            logger.warning("STTv2: Unknown message type: %s, data: %s", message_type, data)


Review comment (suggestion):
for unrecoverable errors, we need also raise an `APIConnectionError` to enable retry and fallback adapters.

Code after:
                # Empty commit signals end of speech segment (similar to Cartesia's is_final flag)
                # This groups multiple committed transcripts into one speech segment
                if self._speaking:
                    self._event_ch.send_nowait(stt.SpeechEvent(type=SpeechEventType.END_OF_SPEECH))
                    self._speaking = False

        elif message_type == "session_started":
            # Session initialization message - informational only
            session_id = data.get("session_id", "unknown")
            logger.info("STTv2: Session started with ID: %s", session_id)

        elif message_type == "committed_transcript_with_timestamps":
            logger.debug("Received message type committed_transcript_with_timestamps: %s", data)

        # Error handling for known ElevenLabs error types
        elif message_type in (
            "auth_error",
            "quota_exceeded",
            "transcriber_error",
            "input_error",
            "error",
        ):
            error_msg = data.get("message", "Unknown error")
            error_details = data.get("details", "")
            details_suffix = " - " + error_details if error_details else ""
            logger.error(
                "STTv2: ElevenLabs error [%s]: %s%s",
                message_type,
                error_msg,
                details_suffix,
            )
            raise APIConnectionError(f"{message_type}: {error_msg}{details_suffix}")
        else:
            logger.warning("STTv2: Unknown message type: %s, data: %s", message_type, data)