BerriAI/litellm · error · ValueError
Invalid JSON message
Error message
Invalid JSON message: {message_str} What it means
Error "Invalid JSON message: {message_str}" thrown in BerriAI/litellm.
Solutions
- A non-JSON frame arrived on the realtime websocket; ensure you only send/receive JSON text frames and check for proxy interference.
When it happens
Trigger: Thrown at litellm/llms/gemini/realtime/transformation.py:535 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/19f3b870b3e5e07f.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/gemini/realtime/transformation.py:535
}
return [json.dumps(client_content_message)]
def transform_realtime_request(
self,
message: str,
model: str,
session_configuration_request: str | None = None,
) -> list[str]:
realtime_input_dict: BidiGenerateContentRealtimeInput = {}
try:
json_message: Final = json.loads(message)
except json.JSONDecodeError:
if isinstance(message, bytes):
message_str = message.decode("utf-8", errors="replace")
else:
message_str = str(message)
raise ValueError(f"Invalid JSON message: {message_str}")
messages: Final[list[str]] = []
msg_type: Final = json_message.get("type")
if msg_type == "session.update":
return self._handle_session_update(json_message, model, session_configuration_request)
if msg_type == "response.create":
return [] # Gemini responds automatically; nothing to forward
if msg_type == "conversation.item.create":
return self._handle_conversation_item(json_message)
if msg_type == "input_audio_buffer.append":
realtime_input_dict["audio"] = HttpxBlobType(
mimeType=self.get_audio_mime_type(), data=json_message["audio"]
)
View on GitHub (pinned to 77b7c6c40c)