BerriAI/litellm · error · AnthropicTextError
{raw_response.text}
Error message
{raw_response.text} What it means
Error "{raw_response.text}" thrown in BerriAI/litellm.
Source
Thrown at litellm/llms/anthropic/completion/transformation.py:192
def transform_response(
self,
model: str,
raw_response: httpx.Response,
model_response: ModelResponse,
logging_obj: LiteLLMLoggingObj,
request_data: dict,
messages: list[AllMessageValues],
optional_params: dict,
litellm_params: dict,
encoding: str,
api_key: str | None = None,
json_mode: bool | None = None,
) -> ModelResponse:
try:
completion_response: Final = raw_response.json()
except Exception:
raise AnthropicTextError(message=raw_response.text, status_code=raw_response.status_code)
prompt: Final = self._get_anthropic_text_prompt_from_messages(messages=messages, model=model)
if "error" in completion_response:
raise AnthropicTextError(
message=str(completion_response["error"]),
status_code=raw_response.status_code,
)
else:
if len(completion_response["completion"]) > 0:
model_response.choices[0].message.content = completion_response["completion"]
model_response.choices[0].finish_reason = completion_response["stop_reason"]
## CALCULATING USAGE
prompt_tokens: Final = len(encoding.encode(prompt)) ##[TODO] use the anthropic tokenizer here
completion_tokens: Final = len(
encoding.encode(model_response["choices"][0]["message"].get("content", ""))
) ##[TODO] use the anthropic tokenizer here
model_response.created = int(time.time())View on GitHub (pinned to 6c2dcb801b)
Solutions
- Inspect the Anthropic response text for the error detail.
When it happens
Trigger: Thrown at litellm/llms/anthropic/completion/transformation.py:192 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/b47d9193c76fabe1.
Report an issue: GitHub.