{"record":{"id":"20e6bdd39b3f1bb0","repo":"langchain-ai/langchain","slug":"response-text","errorCode":null,"errorMessage":"{response.text}","messagePattern":"\\{response\\.text\\}","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/utils/utils.py","lineNumber":70,"sourceCode":"\n        return wrapper\n\n    return decorator\n\n\ndef raise_for_status_with_text(response: Response) -> None:\n    \"\"\"Raise an error with the response text.\n\n    Args:\n        response: The response to check for errors.\n\n    Raises:\n        ValueError: If the response has an error status code.\n    \"\"\"\n    try:\n        response.raise_for_status()\n    except HTTPError as e:\n        raise ValueError(response.text) from e\n\n\n@contextlib.contextmanager\ndef mock_now(dt_value: datetime.datetime) -> Iterator[type]:\n    \"\"\"Context manager for mocking out datetime.now() in unit tests.\n\n    Args:\n        dt_value: The datetime value to use for datetime.now().\n\n    Yields:\n        The mocked datetime class.\n\n    Example:\n        ```python\n        with mock_now(datetime.datetime(2011, 2, 3, 10, 11)):\n            assert datetime.datetime.now() == datetime.datetime(2011, 2, 3, 10, 11)\n        ```\n    \"\"\"","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/utils/utils.py#L52-L88","documentation":"Raised by `raise_for_status_with_text` in `langchain_core.utils.utils`: it wraps `requests.Response.raise_for_status()` and, on any `HTTPError`, re-raises as `ValueError(response.text)` so the provider's error body is visible in the exception message. Seeing this error means the HTTP call to the model/provider API returned a 4xx/5xx status; the message text is the server's response body.","triggerScenarios":"An LLM/provider client (commonly in `langchain-classic` community integrations) receives a 401/403 (bad API key), 404 (wrong endpoint/model name), 429 (rate limit), or 500/503 (provider outage) and calls `raise_for_status_with_text(response)`; the resulting `ValueError` message contains the JSON error body from the provider.","commonSituations":"Missing/expired API key env var; hitting rate limits or quota; wrong base URL or model identifier; provider incidents; proxy/firewall returning an HTML error page (so the message looks like HTML).","solutions":["Read the message body — it is the provider's own error JSON and names the real cause (auth, quota, model name).","Fix credentials/endpoints: verify the API key env var is set and the model name/base_url are correct for the provider.","For 429/5xx add retry with exponential backoff and honor `Retry-After`.","If the message is HTML, a proxy or captive portal intercepted the request — check network egress and proxy settings."],"exampleFix":"# before\nresp = requests.post(url, json=payload, headers=headers)\nraise_for_status_with_text(resp)  # ValueError: {\"error\": {\"message\": \"Invalid API key\"}}\n# fix: set the real key / endpoint before the call\nos.environ[\"<PROVIDER>_API_KEY\"] = \"sk-...\"  # correct key\n\n# defensive caller-side handling\nfrom requests.adapters import HTTPAdapter, Retry\nsession = requests.Session()\nsession.mount(\"https://\", HTTPAdapter(max_retries=Retry(total=5, backoff_factor=1, status_forcelist=[429, 500, 502, 503])))","handlingStrategy":"retry","validationCode":"def ok_to_send(response) -> bool:\n    return response.status_code < 400\n\nif not ok_to_send(resp):\n    raise ValueError(resp.text)  # caller decides retry vs abort","typeGuard":null,"tryCatchPattern":"import time\nfor attempt in range(5):\n    resp = session.post(url, json=payload, timeout=30)\n    if resp.status_code in (429, 500, 502, 503):\n        time.sleep(2 ** attempt)\n        continue\n    try:\n        raise_for_status_with_text(resp)\n    except ValueError:\n        # message body names the real cause: auth, quota, model name\n        raise\n    break","preventionTips":["Check status_code before raise_for_status_with_text so 4xx auth/model errors fail fast without retries.","Use requests Retry with status_forcelist for 429/5xx and honor Retry-After.","Fail fast on 4xx; only retry 429/5xx.","Keep provider error JSON visible in logs — it names the root cause."],"tags":["http","api","rate-limit","provider"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}