anthropics / anthropics/anthropic-sdk-python

Bedrock streaming SSE events errors are not handled gracefully

未關閉
#1,477 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
bedrock
主要語言
Python
星號
3.9k
分支
853
平均合併
1 天 18 小時
30 天內合併 PR
11

描述

In some cases bedrock SSE stream produce error SSE events like following:
```
{'status_code': 400, 'headers': {':exception-type': 'internalServerException', ':content-type': 'application/json', ':message-type': 'exception'}, 'body': b'{"message":"The system encountered an unexpected error during processing. Try your request again."}
```

**Current behaviour**
Anthropic SDK raises `ValueError`
```python
File "/app/.venv/lib/python3.12/site-packages/anthropic/_streaming.py", line 211, in __aiter__
async for item in self._iterator:
File "/app/.venv/lib/python3.12/site-packages/anthropic/_streaming.py", line 225, in __stream__
async for sse in iterator:
File "/app/.venv/lib/python3.12/site-packages/anthropic/_streaming.py", line 215, in _iter_events
async for sse in self._decoder.aiter_bytes(self.response.aiter_bytes()):
File "/app/.venv/lib/python3.12/site-packages/anthropic/lib/bedrock/_stream_decoder.py", line 50, in aiter_bytes
message = self._parse_message_from_event(event)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/app/.venv/lib/python3.12/site-packages/anthropic/lib/bedrock/_stream_decoder.py", line 58, in _parse_message_from_event
raise ValueError(f"Bad response code, expected 200: {response_dict}")
ValueError: Bad response code, expected 200: {'status_code': 400, 'headers': {':exception-type': 'internalServerException', ':content-type': 'application/json', ':message-type': 'exception'}, 'body': b'{"message":"The system encountered an unexpected error during processing. Try your request again."}'}
```

**Expected behaviour**
SDK should either retry this internally or propagate to user-facing `APIStatusError`

**Environment**
anthropic SDK v0.96.0
python 3.12

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。