BerriAI/litellm · error · GigaChatError
Invalid JSON response
Error message
Invalid JSON response: {raw_response.text} What it means
Error "Invalid JSON response: {raw_response.text}" thrown in BerriAI/litellm.
Solutions
- GigaChat returned a non-JSON body; inspect the raw response in the error and check the api_base and proxy settings.
When it happens
Trigger: Thrown at litellm/llms/gigachat/chat/transformation.py:402 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/96fe10b3f4490b8c.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/llms/gigachat/chat/transformation.py:402
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: Any,
api_key: str | None = None,
json_mode: bool | None = None,
) -> ModelResponse:
"""Transform GigaChat response to OpenAI format."""
try:
response_json: Final = raw_response.json()
except Exception:
raise GigaChatError(
status_code=raw_response.status_code,
message=f"Invalid JSON response: {raw_response.text}",
)
is_structured_output: Final = optional_params.get("_structured_output", False)
choices: Final = []
for choice in response_json.get("choices", []):
message_data = choice.get("message", {})
finish_reason = choice.get("finish_reason", "stop")
# Transform function_call to tool_calls or content
if finish_reason == "function_call" and message_data.get("function_call"):
func_call = message_data["function_call"]
args = func_call.get("arguments", {})
if is_structured_output:
# Convert to content for structured outputView on GitHub (pinned to 77b7c6c40c)