BerriAI/litellm · error · ValueError
Invalid log_format: . Must be one of: 'json_array'…
Error message
Invalid log_format: {log_format}. Must be one of: 'json_array', 'ndjson', 'single' What it means
GenericAPILogger.__init__ raises ValueError when log_format is provided but not exactly 'json_array', 'ndjson', or 'single'. The format controls how multiple log events are batched into the HTTP request body: one JSON array, newline-delimited JSON, or a single event per request. It defaults to 'json_array' when omitted.
Solutions
- Use exactly one of: 'json_array', 'ndjson', 'single' (lowercase, underscore).
- Omit log_format entirely if the default 'json_array' batching is acceptable.
- Validate the value against the allowed set in your config loader before starting the proxy.
- If your receiver needs JSON objects per line, that is 'ndjson'.
Example fix
# before GenericAPILogger(endpoint=..., log_format='json') # ValueError # after GenericAPILogger(endpoint=..., log_format='ndjson')
Defensive patterns
Strategy: type-guard
Validate before calling
VALID_FORMATS = {'json_array', 'ndjson', 'single'}
if log_format is not None and log_format not in VALID_FORMATS:
raise SystemExit(f'log_format must be one of {sorted(VALID_FORMATS)}, got {log_format!r}') Type guard
def is_valid_log_format(fmt: str | None) -> bool:
return fmt is None or fmt in {'json_array', 'ndjson', 'single'} Try / catch
try:
GenericAPILogger(endpoint=endpoint, log_format=fmt)
except ValueError as e:
if 'log_format' in str(e):
fmt = 'json_array' # fall back to default and warn
logger.warning('Invalid log_format; using json_array')
raise Prevention
- Validate log_format against the literal set before constructing the logger.
- Remember the safe default is 'json_array' — omit the arg rather than guessing names.
When it happens
Trigger: Passing log_format='json' (the common wrong guess), 'JSON_ARRAY', 'nd-json', or 'newline' to GenericAPILogger; loading the value from a config key that defaults to something else; version drift where a previously accepted alias was removed.
Common situations: Copy-pasting config from a different logging integration; assuming case-insensitivity; wanting per-event delivery and guessing the value name instead of checking docs.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- endpoint not set for GenericAPILogger…
- All values in argilla_transformation_object must be a key…
- Both project_id and topic_id must be provided
- GCS Bucket logging is a premium feature. Please upgrade to…
- GCS_BUCKET_NAME is not set in the environment, but GCS…
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/d771a951d06622fb.
Report an issue: GitHub.
Appendix: 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 77b7c6c40c)