Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ The former `Streaming*` names (`StreamingClient`, `AsyncStreamingClient`, `Strea
- `SpeechStarted` → `SpeechStartedEvent(timestamp: int)` (ms)
- `Warning` → `WarningEvent(warning_code: int, warning: str)`
- `Error` → `RealTimeError` (an `Exception` subclass) with `.code: int | None`; `str(error)` is the message. Server-side errors come through `on_error` rather than being raised, and the payload is a `RealTimeError`, **not** the wire `ErrorEvent` class.
- `LLMGatewayResponse` → `LLMGatewayResponseEvent(turn_order: int, transcript: str, data: Any)`
- `LLMGatewayResponse` → `LLMGatewayResponseEvent(turn_order: int, transcript: str, data: Any, error: str | None)` (`error` is set when the gateway call failed; `data` is then the gateway's error body or `None`)
- `SpeakerRevision` → `SpeakerRevisionEvent(revisions: list[SpeakerRevisionItem])` — diarization-only. Sent once per offline-recluster resolve. Each `SpeakerRevisionItem(turn_order: int, speaker_label: str | None, words: list[Word])` is an earlier Turn whose labels changed (unchanged turns are omitted). For each item, match by `turn_order` against the original Turn and replace its per-word `speaker` (and the turn-level `speaker_label`) with the revision's values. Text and word timestamps are unchanged. By default only the end-of-stream revision is sent; set `speaker_labels_revision_interval_ms` on `RealTimeParameters` (ms of audio time; values below 120_000 are raised to 120_000 server-side, larger values honored, 300_000 recommended) to also get them mid-stream — the first can only arrive after ~120 s of speech, and one is sent only when a label actually changed.

**Sync streaming:**
Expand Down
2 changes: 1 addition & 1 deletion assemblyai/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.10.12"
__version__ = "1.10.13"
4 changes: 3 additions & 1 deletion assemblyai/streaming/v3/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ class LLMGatewayResponseEvent(BaseModel):
type: Literal["LLMGatewayResponse"] = "LLMGatewayResponse"
turn_order: int
transcript: str
data: Any
data: Any = None
# Set when the gateway call failed; data is then the gateway's 4xx body or None.
error: Optional[str] = None


class SpeakerRevisionItem(BaseModel):
Expand Down
62 changes: 62 additions & 0 deletions tests/unit/test_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from assemblyai.streaming.v3.models import (
HeartbeatEvent,
KeepAlive,
LLMGatewayResponseEvent,
SilenceEvent,
TerminateSession,
UpdateConfiguration,
Expand Down Expand Up @@ -2626,6 +2627,67 @@ def test_silence_event_parses_from_wire_message():
assert event.end_ms == 13000


def test_llm_gateway_response_parses_success():
# Given: a successful LLMGatewayResponse wire message
data = {
"type": "LLMGatewayResponse",
"turn_order": 0,
"transcript": "Hello there.",
"data": {"choices": [{"message": {"role": "assistant", "content": "Hi!"}}]},
}

event = StreamingClient._parse_message(data)

# Then: data is carried through and error is unset
assert isinstance(event, LLMGatewayResponseEvent)
assert event.data["choices"][0]["message"]["content"] == "Hi!"
assert event.error is None


def test_llm_gateway_response_parses_gateway_error():
# Given: a failed turn carrying the gateway's 4xx body
data = {
"type": "LLMGatewayResponse",
"turn_order": 1,
"transcript": "I'm calling about my Best Buy order.",
"data": {
"metadata": {"errors": ["model qwen3.5-4b-32k-fast is not supported"]},
"request_id": "d5e3c268-257c-41f1-97b5-0de75037e723",
"message": "invalid request body",
"code": 400,
},
"error": "LLM Gateway returned 400: model qwen3.5-4b-32k-fast is not supported",
}

event = StreamingClient._parse_message(data)

# Then: both the error string and the gateway body are exposed
assert isinstance(event, LLMGatewayResponseEvent)
assert event.turn_order == 1
assert event.error == (
"LLM Gateway returned 400: model qwen3.5-4b-32k-fast is not supported"
)
assert event.data["code"] == 400


def test_llm_gateway_response_parses_timeout_with_null_data():
# Given: a timed-out turn with no gateway body
data = {
"type": "LLMGatewayResponse",
"turn_order": 1,
"transcript": "Hello there.",
"data": None,
"error": "LLM Gateway request timed out",
}

event = StreamingClient._parse_message(data)

# Then: data is None and error is set
assert isinstance(event, LLMGatewayResponseEvent)
assert event.data is None
assert event.error == "LLM Gateway request timed out"


def test_silence_event_dispatched_to_handler(mocker: MockFixture):
# Given: a Silence frame on the wire and a handler registered
silence_json = json.dumps(
Expand Down
Loading