BerriAI/litellm · error · NLPCloudError
{raw_response.text}
Error message
{raw_response.text} What it means
Raised by litellm's NLPCloud chat transformer when raw_response.json() throws: nlp_cloud returned a body that is not JSON (typically an HTML error page or empty body). The message is the raw response text and the upstream status code is preserved on the NLPCloudError.
Source
Thrown at litellm/llms/nlp_cloud/chat/transformation.py:192
optional_params: dict,
litellm_params: dict,
encoding: Any,
api_key: str | None = None,
json_mode: bool | None = None,
) -> ModelResponse:
## LOGGING
logging_obj.post_call(
input=None,
api_key=api_key,
original_response=raw_response.text,
additional_args={"complete_input_dict": request_data},
)
## RESPONSE OBJECT
try:
completion_response: Final = raw_response.json()
except Exception:
raise NLPCloudError(message=raw_response.text, status_code=raw_response.status_code)
if "error" in completion_response:
raise NLPCloudError(
message=completion_response["error"],
status_code=raw_response.status_code,
)
else:
try:
if len(completion_response["generated_text"]) > 0:
model_response.choices[0].message.content = completion_response["generated_text"]
except Exception:
raise NLPCloudError(
message=json.dumps(completion_response),
status_code=raw_response.status_code,
)
## CALCULATING USAGE - baseten charges on time, not tokens - have some mapping of cost here.
prompt_tokens: Final = completion_response["nb_input_tokens"]
completion_tokens: Final = completion_response["nb_generated_tokens"]View on GitHub (pinned to 6c2dcb801b)
Solutions
- Read the exception message — it contains the literal upstream body revealing the real problem.
- Verify NLP_CLOUD_API_KEY is set and valid.
- If rate limited, add throttling/backoff on your side or upgrade the NLP Cloud plan.
- Retry transient 502/503 gateway errors with exponential backoff.
Example fix
# before
out = litellm.completion(model="nlp_cloud/finetuned-llama-3-70b", messages=msgs)
# after — retry transient gateway failures
from tenacity import retry, wait_exponential, stop_after_attempt
@retry(wait=wait_exponential(multiplier=1, max=10), stop=stop_after_attempt(3), reraise=True)
def ask(msgs):
return litellm.completion(model="nlp_cloud/finetuned-llama-3-70b", messages=msgs)
out = ask(msgs) Defensive patterns
Strategy: retry
Validate before calling
import os
assert os.getenv("NLP_CLOUD_API_KEY"), "NLP_CLOUD_API_KEY not set" Try / catch
from litellm.exceptions import APIError
import time
for attempt in range(3):
try:
out = litellm.completion(model="nlp_cloud/finetuned-llama-3-70b", messages=msgs)
break
except APIError as e:
status = getattr(e, "status_code", None)
if status and status >= 500 and attempt < 2:
time.sleep(2 ** attempt)
continue
raise Prevention
- Treat non-JSON bodies from NLP Cloud as rate-limit/outage signals; log the raw message.
- Throttle requests below your plan's rate limit.
- Wrap gateway-type failures (5xx) in bounded retries, never retry 4xx.
When it happens
Trigger: Calling litellm.completion() with model='nlp_cloud/<engine>' when the NLP Cloud gateway returns HTML (rate limit page, 502) or a plain-text error because of an invalid NLP_CLOUD_API_KEY.
Common situations: Free-tier rate limits returning an HTML block page, expired API key, or an outage of nlpcloud.io infrastructure.
Related errors
- {completion_response["error"]}
- {json.dumps(completion_response)}
- NLPCloudException - {error_str}
- An unknown error occurred with the stream
- Unable to get json response - {e}, Original Response: {raw_r
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/b1e5b3976f3f664c.
Report an issue: GitHub.