Bug
When a provider returns a non-200 HTTP response with a binary (non-UTF-8) body, _handle_error_response raises UnicodeDecodeError instead of the expected httpx.HTTPStatusError.
Root cause
In client.py, _handle_error_response:
except (JSONDecodeError, KeyError, TypeError, IndexError):
error_msg = response.text or f"HTTP {response.status_code}"
response.text is httpx's UTF-8-decoded property. When the error body contains binary bytes (e.g. 0xff), it raises UnicodeDecodeError — which is not in the caught exception list — so httpx.HTTPStatusError is never raised.
Observed
ElevenLabs occasionally returns a binary error body, causing:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 45
Fix
except (JSONDecodeError, KeyError, TypeError, IndexError):
error_msg = response.content.decode("utf-8", errors="replace") or f"HTTP {response.status_code}"
response.content is the raw bytes. errors="replace" substitutes U+FFFD for undecodable bytes instead of raising.
Bug
When a provider returns a non-200 HTTP response with a binary (non-UTF-8) body,
_handle_error_responseraisesUnicodeDecodeErrorinstead of the expectedhttpx.HTTPStatusError.Root cause
In
client.py,_handle_error_response:response.textis httpx's UTF-8-decoded property. When the error body contains binary bytes (e.g.0xff), it raisesUnicodeDecodeError— which is not in the caught exception list — sohttpx.HTTPStatusErroris never raised.Observed
ElevenLabs occasionally returns a binary error body, causing:
Fix
response.contentis the raw bytes.errors="replace"substitutesU+FFFDfor undecodable bytes instead of raising.