BerriAI/litellm · error · ValueError
chunk
Error message
chunk
What it means
Second guard in the Predibase handler: if the raw (non-SSE) chunk string itself contains the substring 'error', the whole chunk is re-raised as ValueError, because a chunk-level 'error' token means the stream body is an error response rather than token data.
Source
Thrown at litellm/litellm_core_utils/streaming_handler.py:491
print_verbose(f"data json: {data_json}")
if "token" in data_json and "text" in data_json["token"]:
text = data_json["token"]["text"]
if data_json.get("details", False) and data_json["details"].get("finish_reason", False):
is_finished = True
finish_reason = data_json["details"]["finish_reason"]
elif data_json.get("generated_text", False): # if full generated text exists, then stream is complete
text = "" # don't return the final bos token
is_finished = True
finish_reason = "stop"
elif data_json.get("error", False):
raise Exception(data_json.get("error"))
return {
"text": text,
"is_finished": is_finished,
"finish_reason": finish_reason,
}
elif "error" in chunk:
raise ValueError(chunk)
return {
"text": text,
"is_finished": is_finished,
"finish_reason": finish_reason,
}
except Exception as e:
raise e
def handle_ai21_chunk(self, chunk): # fake streaming
chunk = chunk.decode("utf-8")
data_json: Final[_Ai21StreamData] = json.loads(chunk)
try:
text: Final = data_json["completions"][0]["data"]["text"]
is_finished: Final = True
finish_reason: Final = "stop"
return {
"text": text,
"is_finished": is_finished,View on GitHub (pinned to 6c2dcb801b)
Solutions
- Print the chunk captured in the ValueError to identify the producer (Predibase vs proxy).
- Fix the underlying request (auth, model id) that caused the error response.
- If a proxy injects error pages, bypass it or fix its configuration for SSE endpoints.
Defensive patterns
Strategy: try-catch
Try / catch
try:
for part in stream:
...
except ValueError as e:
if "predibase" in str(e) or "error" in str(e).lower():
diagnose_from_chunk(str(e)) Prevention
- Bypass transforming proxies for SSE endpoints.
- Log the raw failing chunk at debug level to identify error sources fast.
When it happens
Trigger: Non-stream-shaped or error responses from Predibase that reach the streaming parser — e.g. a JSON error body delivered as one chunk, or proxy/gateway error text containing the word 'error'.
Common situations: Corporate proxies returning HTML/text error pages; Predibase returning a non-SSE JSON error; mismatch between stream=True and the endpoint's actual behavior.
Related errors
- data_json.get("error")
- An unknown error occurred with the stream
- Error receiving chunk from stream: {e}
- Braintrust API error: {e.response.text}
- Failed to connect to Braintrust API: {str(e)}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/fddb6e4642baccd1.
Report an issue: GitHub.