BerriAI/litellm · error · ValueError

Error in response object format, got None

Error message

Error in response object format, got None

What it means

After a successful HTTP response, litellm calls response.json() and checks the result: if parsing yields None (e.g. body was the literal string 'null' or an empty/invalid JSON body), it raises ValueError('Error in response object format, got None') before transforming to the OpenAI image response shape.

Source

Thrown at litellm/llms/bedrock/image_generation/image_handler.py:324

        response: httpx.Response,
        data: dict,
    ) -> ImageResponse:
        """
        Transforms the Image Generation response from Bedrock to OpenAI format
        """

        ## LOGGING
        if logging_obj is not None:
            logging_obj.post_call(
                input=prompt,
                api_key="",
                original_response=response.text,
                additional_args={"complete_input_dict": data},
            )
        verbose_logger.debug("raw model_response: %s", response.text)
        response_dict: Final = response.json()
        if response_dict is None:
            raise ValueError("Error in response object format, got None")

        config_class: Final = self.get_config_class(model=model)

        config_class.transform_response_dict_to_openai_response(
            model_response=model_response,
            response_dict=response_dict,
        )

        return model_response

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Enable verbose logging (litellm.verbose = True or set litellm.set_verbose) and inspect 'raw model_response' to see what body actually arrived.
  2. Bypass the proxy/intermediary and call Bedrock directly to confirm where the empty body originates.
  3. Retry the request — empty 200 bodies are usually transient infrastructure faults.
  4. If reproducible with a direct AWS call, report to litellm with the raw response; otherwise fix the intermediary (proxy timeouts, buffering).
Defensive patterns

Strategy: fallback

Try / catch

try:
    resp = litellm.image_generation(model=model, prompt=p)
except ValueError as e:
    if "got None" in str(e):
        log.error("Empty/null body from Bedrock — retrying once")
        return litellm.image_generation(model=model, prompt=p)  # usually transient
    raise

Prevention

When it happens

Trigger: Bedrock returning a 200 with an empty body or 'null' body — seen with some proxy setups, API gateways, or truncated responses — while model/response parsing expects a JSON object.

Common situations: Self-hosted proxies (LiteLLM proxy chains, nginx) stripping bodies, gateway timeouts returning empty 200s, or a provider bug returning null JSON for failed generations.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/6e89e82e5a7a81f9. Report an issue: GitHub.