Repository navigation
Description
Bug Description
Batch transcription with the ElevenLabs plugin has no request timeout. STT._recognize_impl posts to /speech-to-text without a timeout, so the request falls back to the session default, 5 minutes for the shared http_context session. conn_options.timeout has no effect.
The ElevenLabs TTS (ChunkedStream) and other batch STT plugins such as Deepgram pass aiohttp.ClientTimeout(total=30, sock_connect=conn_options.timeout). In a voice pipeline using the batch model behind a StreamAdapter, a stalled request holds the turn for up to 5 minutes per attempt instead of failing and retrying or falling back.
Related: the same gap in the Mistral plugin, #8643.
Expected Behavior
recognize() raises APITimeoutError within a bounded time, using the same timeout as the plugin's TTS.
Reproduction Steps
import asyncio, json, threading, time
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
import aiohttp
from livekit import rtc
from livekit.agents import APIConnectOptions
from livekit.plugins.elevenlabs import STT
class Slow(BaseHTTPRequestHandler):
def do_POST(self):
self.rfile.read(int(self.headers.get("content-length", 0)))
time.sleep(40)
body = json.dumps({"text": "hello", "language_code": "en", "words": []}).encode()
self.send_response(200)
self.send_header("content-type", "application/json")
self.send_header("content-length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, *a):
pass
async def main():
srv = ThreadingHTTPServer(("127.0.0.1", 0), Slow)
threading.Thread(target=srv.serve_forever, daemon=True).start()
async with aiohttp.ClientSession() as session:
stt = STT(api_key="test", base_url=f"http://127.0.0.1:{srv.server_port}", model="scribe_v2", http_session=session)
frame = rtc.AudioFrame(data=b"\x00\x00" * 1600, sample_rate=16000, num_channels=1, samples_per_channel=1600)
t0 = time.monotonic()
try:
await stt.recognize([frame], conn_options=APIConnectOptions(timeout=1.0, max_retry=0))
print(f"returned after {time.monotonic() - t0:.1f}s")
except Exception as e:
print(f"raised {type(e).__name__} after {time.monotonic() - t0:.1f}s")
srv.shutdown()
asyncio.run(main())On main (07b46de) this prints returned after 40.0s, and a slower server would be waited on for up to 5 minutes. With the TTS timeout applied it prints raised APITimeoutError after 30.6s.
Operating System
macOS 26 (the code path is platform independent)
Models Used
ElevenLabs batch STT: scribe_v2
Package Versions
livekit-agents==1.8.12
livekit-plugins-elevenlabs==1.8.12Session/Room/Call IDs
No response
Proposed Solution
Pass timeout=aiohttp.ClientTimeout(total=30, sock_connect=conn_options.timeout) to the post() in STT._recognize_impl, matching the plugin's TTS, plus a unit test. I have the change ready and will open a PR.
Activity