agents icon indicating copy to clipboard operation
agents copied to clipboard

AttributeError: 'str' object has no attribute 'type' in _handle_response_done_but_not_complete when using xAI-compatible Realtime API

Open areebkhan-tech opened this issue 5 months ago • 0 comments

Bug Description

When using an OpenAI-compatible Realtime API (e.g. xAI), the response.done event sometimes returns status_details as a plain string (e.g. "incomplete") instead of a structured object {"type": "incomplete", ...}.

In realtime_model.py, the event is constructed via ResponseDoneEvent.construct(**event) (line 1117), which bypasses Pydantic validation and leaves status_details as a raw string. Later, _handle_response_done_but_not_complete (line 2057) accesses status_details.type, crashing with:

AttributeError: 'str' object has no attribute 'type'

Full traceback: File "realtime_model.py", line 1117, in _recv_task self._handle_response_done(ResponseDoneEvent.construct(**event)) File "realtime_model.py", line 2023, in _handle_response_done self._handle_response_done_but_not_complete(event) File "realtime_model.py", line 2057, in _handle_response_done_but_not_complete status_type = status_details.type if status_details else None AttributeError: 'str' object has no attribute 'type'

Expected Behavior

Either:

  1. ResponseDoneEvent.construct() should be replaced with proper Pydantic parsing (e.g. ResponseDoneEvent.model_validate()) so status_details is always coerced into a RealtimeResponseStatus object, OR
  2. Lines 2057-2058 should guard against a plain string: status_type = status_details.type if hasattr(status_details, "type") else status_details status_reason = status_details.reason if hasattr(status_details, "reason") else None

Reproduction Steps

When using an OpenAI-compatible Realtime API (e.g. xAI), the `response.done` event 
sometimes returns `status_details` as a plain string (e.g. `"incomplete"`) instead 
of a structured object `{"type": "incomplete", ...}`.

Operating System

macOS

Models Used

No response

Package Versions

livekit ==1.1.8
livekit[agnet]==1.5.17

Session/Room/Call IDs

No response

Proposed Solution


Additional Context

No response

Screenshots and Recordings

No response

areebkhan-tech avatar Jun 07 '26 12:06 areebkhan-tech