Inworld error: Context `d6b3587d74a7` not found

Hi,

I’m trying to implement Inworld tts in my agent, a week ago it was working perfectly as a POC but now when added to staging it’s showing the following error:

Inworld error: Context d6b3587d74a7 is not found

I’m attaching the full traceback here:

agent-1  |     09:02:56.123 WARNI… livekit.agents     failed to synthesize speech:
agent-1  |                                            Inworld error: Context 8a7fc93930c9
agent-1  |                                            not found, retrying in 2.0s
agent-1  |                                          {"tts":
agent-1  | "livekit.plugins.inworld.tts.TTS", "attempt": 2, "streamed": true, "interview":
agent-1  | "69a9692736b631a8c43e634f", "pid": 286, "job_id": "AJ_3CYyjWscBLGP", "room_id":
agent-1  | "RM_nsZxNH44h28H"}
agent-1  |     09:02:58.440 WARNI… livekit.agents     failed to synthesize speech:
agent-1  |                                            Inworld error: Context 722d505d52ff
agent-1  |                                            not found, retrying in 2.0s
agent-1  |                                          {"tts":
agent-1  | "livekit.plugins.inworld.tts.TTS", "attempt": 3, "streamed": true, "interview":
agent-1  | "69a9692736b631a8c43e634f", "pid": 286, "job_id": "AJ_3CYyjWscBLGP", "room_id":
agent-1  | "RM_nsZxNH44h28H"}
agent-1  |     09:02:59.728 WARNI… livekit.agents     process memory usage is high
agent-1  |                                          {"memory_usage_mb": 702.38671875,
agent-1  | "memory_warn_mb": 500, "memory_limit_mb": 0, "pid": 286, "job_id":
agent-1  | "AJ_3CYyjWscBLGP", "room_id": "RM_nsZxNH44h28H"}
agent-1  |     09:03:00.758 ERROR… livekit.agents     Error in _tts_inference_task
agent-1  |                                            Traceback (most recent call last):
agent-1  |                                              File
agent-1  |                                            "/app/.venv/lib/python3.13/site-pa…
agent-1  |                                            line 631, in __anext__
agent-1  |                                                val = await
agent-1  |                                            self._event_aiter.__anext__()
agent-1  |                                                      ^^^^^^^^^^^^^^^^^^^^^^^^…
agent-1  |                                            StopAsyncIteration
agent-1  |
agent-1  |                                            During handling of the above
agent-1  |                                            exception, another exception
agent-1  |                                            occurred:
agent-1  |
agent-1  |                                            Traceback (most recent call last):
agent-1  |                                              File
agent-1  |                                            "/app/.venv/lib/python3.13/site-pa…
agent-1  |                                            line 17, in async_fn_logs
agent-1  |                                                return await fn(*args,
agent-1  |                                            **kwargs)
agent-1  |                                                       ^^^^^^^^^^^^^^^^^^^^^^^…
agent-1  |                                              File
agent-1  |                                            "/app/.venv/lib/python3.13/site-pa…
agent-1  |                                            line 295, in _tts_inference_task
agent-1  |                                                pushed_duration += await
agent-1  |                                            _tts_node_inference(input_segment,
agent-1  |                                            pushed_duration)
agent-1  |                                                                   ^^^^^^^^^^^…
agent-1  |                                              File
agent-1  |                                            "/app/.venv/lib/python3.13/site-pa…
agent-1  |                                            line 71, in async_wrapper
agent-1  |                                                return await func(*args,
agent-1  |                                            **kwargs)  # type: ignore
agent-1  |                                                       ^^^^^^^^^^^^^^^^^^^^^^^…
agent-1  |                                              File
agent-1  |                                            "/app/.venv/lib/python3.13/site-pa…
agent-1  |                                            line 253, in _tts_node_inference
agent-1  |                                                async for audio_frame in
agent-1  |                                            tts_node:
agent-1  |                                                ...<13 lines>...
agent-1  |                                                    audio_duration +=
agent-1  |                                            audio_frame.duration
agent-1  |                                              File
agent-1  |                                            "/app/.venv/lib/python3.13/site-pa…
agent-1  |                                            line 454, in tts_node
agent-1  |                                                async for ev in stream:
agent-1  |                                                    yield ev.frame
agent-1  |                                              File
agent-1  |                                            "/app/.venv/lib/python3.13/site-pa…
agent-1  |                                            line 634, in __anext__
agent-1  |                                                raise exc  # noqa: B904
agent-1  |                                                ^^^^^^^^^
agent-1  |                                              File
agent-1  |                                            "/app/.venv/lib/python3.13/site-pa…
agent-1  |                                            line 421, in _traceable_main_task
agent-1  |                                                await self._main_task()
agent-1  |                                              File
agent-1  |                                            "/app/.venv/lib/python3.13/site-pa…
agent-1  |                                            line 455, in _main_task
agent-1  |                                                await self._run(output_emitter)
agent-1  |                                              File
agent-1  |                                            "/app/.venv/lib/python3.13/site-pa…
agent-1  |                                            line 1196, in _run
agent-1  |                                                await asyncio.wait_for(waiter,
agent-1  |                                            timeout=self._conn_options.timeout
agent-1  |                                            + 60)
agent-1  |                                              File
agent-1  |                                            "/usr/local/lib/python3.13/asyncio…
agent-1  |                                            line 507, in wait_for
agent-1  |                                                return await fut
agent-1  |                                                       ^^^^^^^^^
agent-1  |                                            livekit.agents._exceptions.APIErro…
agent-1  |                                            Inworld error: Context d6b3587d74a7
agent-1  |                                            not found
agent-1  |                                          {"interview":
agent-1  | "69a9692736b631a8c43e634f", "pid": 286, "job_id": "AJ_3CYyjWscBLGP", "room_id":
agent-1  | "RM_nsZxNH44h28H"}
agent-1  | Traceback (most recent call last):
agent-1  |   File "/app/.venv/lib/python3.13/site-packages/livekit/agents/tts/tts.py", line
agent-1  | 631, in __anext__
agent-1  |     val = await self._event_aiter.__anext__()
agent-1  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
agent-1  | StopAsyncIteration
agent-1  |
agent-1  | During handling of the above exception, another exception occurred:
agent-1  |
agent-1  | Traceback (most recent call last):
agent-1  |   File "/app/.venv/lib/python3.13/site-packages/livekit/agents/utils/log.py",
agent-1  | line 17, in async_fn_logs
agent-1  |     return await fn(*args, **kwargs)
agent-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^
agent-1  |   File
agent-1  | "/app/.venv/lib/python3.13/site-packages/livekit/agents/voice/generation.py",
agent-1  | line 295, in _tts_inference_task
agent-1  |     pushed_duration += await _tts_node_inference(input_segment, pushed_duration)
agent-1  |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
agent-1  |   File
agent-1  | "/app/.venv/lib/python3.13/site-packages/opentelemetry/util/_decorator.py", line
agent-1  | 71, in async_wrapper
agent-1  |     return await func(*args, **kwargs)  # type: ignore
agent-1  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
agent-1  |   File
agent-1  | "/app/.venv/lib/python3.13/site-packages/livekit/agents/voice/generation.py",
agent-1  | line 253, in _tts_node_inference
agent-1  |     async for audio_frame in tts_node:
agent-1  |     ...<13 lines>...
agent-1  |         audio_duration += audio_frame.duration
agent-1  |   File "/app/.venv/lib/python3.13/site-packages/livekit/agents/voice/agent.py",
agent-1  | line 454, in tts_node
agent-1  |     async for ev in stream:
agent-1  |         yield ev.frame
agent-1  |   File "/app/.venv/lib/python3.13/site-packages/livekit/agents/tts/tts.py", line
agent-1  | 634, in __anext__
agent-1  |     raise exc  # noqa: B904
agent-1  |     ^^^^^^^^^
agent-1  |   File "/app/.venv/lib/python3.13/site-packages/livekit/agents/tts/tts.py", line
agent-1  | 421, in _traceable_main_task
agent-1  |     await self._main_task()
agent-1  |   File "/app/.venv/lib/python3.13/site-packages/livekit/agents/tts/tts.py", line
agent-1  | 455, in _main_task
agent-1  |     await self._run(output_emitter)
agent-1  |   File "/app/.venv/lib/python3.13/site-packages/livekit/plugins/inworld/tts.py",
agent-1  | line 1196, in _run
agent-1  |     await asyncio.wait_for(waiter, timeout=self._conn_options.timeout + 60)
agent-1  |   File "/usr/local/lib/python3.13/asyncio/tasks.py", line 507, in wait_for
agent-1  |     return await fut
agent-1  |            ^^^^^^^^^
agent-1  | livekit.agents._exceptions.APIError: Inworld error: Context d6b3587d74a7 not
agent-1  | found

More Details:

  • Inworld model: inworld-tts-1.5-mini
  • Inworld voice: Oliver
  • livekit-agents[inworld]==1.4.3
  • Environment: Docker

inworld2.py (5.2 KB)

I tried reproducing this with our agent starter and didn’t see any issues, I suspect there is something wrong with your Inworld API key. Couple of suggestions:

  • Could you try using LiveKit Inference, which does not need the separate API key: Inworld TTS | LiveKit Documentation
  • Could you try the attached file (I did ensure I was also using 1.4.3)

Hi Darry,

I’m using the Base64 version of the API token, could that be a issue?

Let me try with that once with the same API key that I have.

If it worked previously, I don’t think the format of the API key would be the issue - I was thinking more some issue with your Inworld account, perhaps.

API key was different previously but was of the same Base64 type.

WAIT,

I just ran the demo script given in InWorld documentation and it worked with the same API key then why isn’t it working in the livekit pipeline?

This script worked successfully with the same API key:

import requests
import base64
import os
import json
import wave
import io
import time

url = "https://api.inworld.ai/tts/v1/voice:stream"

payload = {
    "text": "What a wonderful day to be a text-to-speech model! I'm super excited to show you how streaming works.",
    "voice_id": "Oliver",
    "model_id": "inworld-tts-1.5-mini",
    "audio_config": {
        "audio_encoding": "LINEAR16",
        "sample_rate_hertz": 48000,
    },
}

# Use a persistent session for connection reuse (TCP+TLS keep-alive)
session = requests.Session()
session.headers.update({
    "Authorization": f"Basic {os.getenv('INWORLD_API_KEY')}",
    "Content-Type": "application/json",
    "Connection": "keep-alive",
})

start_time = time.time()
ttfb = None
raw_audio_data = io.BytesIO()

with session.post(url, json=payload, stream=True) as response:
    response.raise_for_status()

    for line in response.iter_lines(decode_unicode=True):
        if line.strip():
            try:
                chunk = json.loads(line)
                result = chunk.get("result")
                if result and "audioContent" in result:
                    audio_chunk = base64.b64decode(result["audioContent"])
                    if ttfb is None:
                        ttfb = time.time() - start_time
                    # Skip WAV header (first 44 bytes) from each chunk
                    if len(audio_chunk) > 44:
                        raw_audio_data.write(audio_chunk[44:])
                        print(f"Received {len(audio_chunk)} bytes")
            except json.JSONDecodeError:
                continue

total_time = time.time() - start_time

with wave.open("output_stream.wav", "wb") as wf:
    wf.setnchannels(1)
    wf.setsampwidth(2)
    wf.setframerate(payload["audio_config"]["sample_rate_hertz"])
    wf.writeframes(raw_audio_data.getvalue())

print("Audio saved to output_stream.wav")
print(f"Time to first chunk: {ttfb:.3f}s" if ttfb else "No chunks received")
print(f"Total time: {total_time:.3f}s")

session.close()

If the same agent code works in one environment but not in another, this is almost always an indication of differences between the environments. I would start with checking that the InWorld environment variables are set properly. Maybe temporarily log them to make sure there are no extra spaces or any variable escaping that might be corrupting the token.

Probably less likely but worth a check is that the InWorld API servers are accessible from the target system.