BerriAI/litellm · error · ValueError

Invalid log_format: {log_format}. Must be one of: 'json_arra

Error message

Invalid log_format: {log_format}. Must be one of: 'json_array', 'ndjson', 'single'

What it means

Raised by GenericAPILogger.__init__ when the log_format argument (or the log_format loaded from a generic_api_compatible_callbacks.json config via callback_name) is not None and not one of the three supported formats: 'json_array', 'ndjson', 'single'. The value is validated at construction time, so the logger fails fast before any request is logged. If log_format is None the default 'json_array' is used.

Source

Thrown at litellm/integrations/generic_api/generic_api_callback.py:176

                "endpoint not set for GenericAPILogger, GENERIC_LOGGER_ENDPOINT not found in environment variables"
            )

        self.headers: dict[str, str] = self._get_headers(headers)
        self.endpoint: str = endpoint
        self.event_types: list[API_EVENT_TYPES] | None = event_types
        self.callback_name: str | None = callback_name
        self.max_retries = max(0, int(max_retries or 0))
        retry_delay_value: Final = 0.0 if retry_delay is None else retry_delay
        self.retry_delay = max(0.0, float(retry_delay_value))
        self.timeout = timeout

        # Validate and store log_format
        if log_format is not None and log_format not in [
            "json_array",
            "ndjson",
            "single",
        ]:
            raise ValueError(f"Invalid log_format: {log_format}. Must be one of: 'json_array', 'ndjson', 'single'")
        self.log_format: LOG_FORMAT_TYPES = log_format or "json_array"

        verbose_logger.debug(
            "in init GenericAPILogger, callback_name: %s, endpoint %s, headers %s, event_types: %s, log_format: %s",
            self.callback_name,
            self.endpoint,
            self.headers,
            self.event_types,
            self.log_format,
        )

        #########################################################
        # Init variables for batch flushing logs
        #########################################################
        self.flush_lock = asyncio.Lock()
        super().__init__(**kwargs, flush_lock=self.flush_lock)
        asyncio.create_task(self.periodic_flush())
        self.log_queue: list[dict | StandardLoggingPayload] = []

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Set log_format to exactly one of 'json_array', 'ndjson', or 'single' (case-sensitive), or omit it / pass None to get the 'json_array' default.
  2. If using callback_name, open the callback config JSON (generic_api_compatible_callbacks.json) and fix the 'log_format' entry for that callback; the explicit argument must be None for the config value to take effect.
  3. Add a startup assertion like assert log_format in (None, 'json_array', 'ndjson', 'single') before constructing the logger so misconfiguration is caught with a clearer message.

Example fix

# before
logger = GenericAPILogger(endpoint="https://logs.example.com", log_format="ndjson ")  # trailing space -> ValueError

# after
logger = GenericAPILogger(endpoint="https://logs.example.com", log_format="ndjson")
Defensive patterns

Strategy: validation

Validate before calling

from litellm.integrations.generic_api.generic_api_callback import GenericAPILogger

VALID_LOG_FORMATS = {"json_array", "ndjson", "single"}

def make_logger(endpoint: str, log_format: str | None = None) -> GenericAPILogger:
    if log_format is not None and log_format not in VALID_LOG_FORMATS:
        raise ValueError(
            f"log_format must be one of {sorted(VALID_LOG_FORMATS)} or None, got {log_format!r}"
        )
    return GenericAPILogger(endpoint=endpoint, log_format=log_format)

Type guard

def is_valid_log_format(value: object) -> bool:
    return value is None or (isinstance(value, str) and value in {"json_array", "ndjson", "single"})

Prevention

When it happens

Trigger: Constructing GenericAPILogger(callback_name=..., log_format='JSON') with wrong casing, passing log_format='json' or 'yaml', or defining a custom callback in generic_api_compatible_callbacks.json whose 'log_format' key contains a typo like 'ndjosn'. Also passing an empty string '' (which is not None, so it enters validation and fails).

Common situations: Users adding a generic API logging callback to litellm.callbacks and guessing the format name; teams loading callback config from their own JSON registry where a teammate edited the format value; copy-pasting config from examples written for a different library version that used different format names.

Related errors


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