{"record":{"id":"b1e5b3976f3f664c","repo":"BerriAI/litellm","slug":"raw-response-text-b1e5b3","errorCode":null,"errorMessage":"{raw_response.text}","messagePattern":"\\{raw_response\\.text\\}","errorType":"http","errorClass":"NLPCloudError","httpStatus":null,"severity":"error","filePath":"litellm/llms/nlp_cloud/chat/transformation.py","lineNumber":192,"sourceCode":"        optional_params: dict,\n        litellm_params: dict,\n        encoding: Any,\n        api_key: str | None = None,\n        json_mode: bool | None = None,\n    ) -> ModelResponse:\n        ## LOGGING\n        logging_obj.post_call(\n            input=None,\n            api_key=api_key,\n            original_response=raw_response.text,\n            additional_args={\"complete_input_dict\": request_data},\n        )\n\n        ## RESPONSE OBJECT\n        try:\n            completion_response: Final = raw_response.json()\n        except Exception:\n            raise NLPCloudError(message=raw_response.text, status_code=raw_response.status_code)\n        if \"error\" in completion_response:\n            raise NLPCloudError(\n                message=completion_response[\"error\"],\n                status_code=raw_response.status_code,\n            )\n        else:\n            try:\n                if len(completion_response[\"generated_text\"]) > 0:\n                    model_response.choices[0].message.content = completion_response[\"generated_text\"]\n            except Exception:\n                raise NLPCloudError(\n                    message=json.dumps(completion_response),\n                    status_code=raw_response.status_code,\n                )\n\n        ## CALCULATING USAGE - baseten charges on time, not tokens - have some mapping of cost here.\n        prompt_tokens: Final = completion_response[\"nb_input_tokens\"]\n        completion_tokens: Final = completion_response[\"nb_generated_tokens\"]","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/nlp_cloud/chat/transformation.py#L174-L210","documentation":"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.","triggerScenarios":"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.","commonSituations":"Free-tier rate limits returning an HTML block page, expired API key, or an outage of nlpcloud.io infrastructure.","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."],"exampleFix":"# before\nout = litellm.completion(model=\"nlp_cloud/finetuned-llama-3-70b\", messages=msgs)\n\n# after — retry transient gateway failures\nfrom tenacity import retry, wait_exponential, stop_after_attempt\n@retry(wait=wait_exponential(multiplier=1, max=10), stop=stop_after_attempt(3), reraise=True)\ndef ask(msgs):\n    return litellm.completion(model=\"nlp_cloud/finetuned-llama-3-70b\", messages=msgs)\nout = ask(msgs)","handlingStrategy":"retry","validationCode":"import os\nassert os.getenv(\"NLP_CLOUD_API_KEY\"), \"NLP_CLOUD_API_KEY not set\"","typeGuard":null,"tryCatchPattern":"from litellm.exceptions import APIError\nimport time\nfor attempt in range(3):\n    try:\n        out = litellm.completion(model=\"nlp_cloud/finetuned-llama-3-70b\", messages=msgs)\n        break\n    except APIError as e:\n        status = getattr(e, \"status_code\", None)\n        if status and status >= 500 and attempt < 2:\n            time.sleep(2 ** attempt)\n            continue\n        raise","preventionTips":["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."],"tags":["nlp-cloud","chat","json-parse","gateway"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}