From 5906b60c9a25cb66911262bbb0a9315969f3822c Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 5 Jul 2024 15:31:06 -0700 Subject: [PATCH] fix - raise report Anthropic streaming errors --- litellm/llms/anthropic.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/litellm/llms/anthropic.py b/litellm/llms/anthropic.py index e87618f02e..a4521a7031 100644 --- a/litellm/llms/anthropic.py +++ b/litellm/llms/anthropic.py @@ -49,7 +49,7 @@ class AnthropicConstants(Enum): class AnthropicError(Exception): def __init__(self, status_code, message): self.status_code = status_code - self.message = message + self.message: str = message self.request = httpx.Request( method="POST", url="https://api.anthropic.com/v1/messages" ) @@ -830,6 +830,16 @@ class ModelResponseIterator: .get("usage", {}) .get("output_tokens", 0), ) + elif type_chunk == "error": + """ + {"type":"error","error":{"details":null,"type":"api_error","message":"Internal server error"} } + """ + _error_dict = chunk.get("error", {}) or {} + message = _error_dict.get("message", None) or str(chunk) + raise AnthropicError( + message=message, + status_code=500, # it looks like Anthropic API does not return a status code in the chunk error - default to 500 + ) returned_chunk = GenericStreamingChunk( text=text, tool_use=tool_use,