{"record":{"id":"d771a951d06622fb","repo":"BerriAI/litellm","slug":"invalid-log-format-log-format-must-be-one-of","errorCode":null,"errorMessage":"Invalid log_format: {log_format}. Must be one of: 'json_array', 'ndjson', 'single'","messagePattern":"Invalid log_format: (.+?)\\. Must be one of: 'json_array', 'ndjson', 'single'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/integrations/generic_api/generic_api_callback.py","lineNumber":176,"sourceCode":"                \"endpoint not set for GenericAPILogger, GENERIC_LOGGER_ENDPOINT not found in environment variables\"\n            )\n\n        self.headers: dict[str, str] = self._get_headers(headers)\n        self.endpoint: str = endpoint\n        self.event_types: list[API_EVENT_TYPES] | None = event_types\n        self.callback_name: str | None = callback_name\n        self.max_retries = max(0, int(max_retries or 0))\n        retry_delay_value: Final = 0.0 if retry_delay is None else retry_delay\n        self.retry_delay = max(0.0, float(retry_delay_value))\n        self.timeout = timeout\n\n        # Validate and store log_format\n        if log_format is not None and log_format not in [\n            \"json_array\",\n            \"ndjson\",\n            \"single\",\n        ]:\n            raise ValueError(f\"Invalid log_format: {log_format}. Must be one of: 'json_array', 'ndjson', 'single'\")\n        self.log_format: LOG_FORMAT_TYPES = log_format or \"json_array\"\n\n        verbose_logger.debug(\n            \"in init GenericAPILogger, callback_name: %s, endpoint %s, headers %s, event_types: %s, log_format: %s\",\n            self.callback_name,\n            self.endpoint,\n            self.headers,\n            self.event_types,\n            self.log_format,\n        )\n\n        #########################################################\n        # Init variables for batch flushing logs\n        #########################################################\n        self.flush_lock = asyncio.Lock()\n        super().__init__(**kwargs, flush_lock=self.flush_lock)\n        asyncio.create_task(self.periodic_flush())\n        self.log_queue: list[dict | StandardLoggingPayload] = []","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/integrations/generic_api/generic_api_callback.py#L158-L194","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copy-pasting config from a different logging integration; assuming case-insensitivity; wanting per-event delivery and guessing the value name instead of checking docs.","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'."],"exampleFix":"# before\nGenericAPILogger(endpoint=..., log_format='json')  # ValueError\n\n# after\nGenericAPILogger(endpoint=..., log_format='ndjson')","handlingStrategy":"type-guard","validationCode":"VALID_FORMATS = {'json_array', 'ndjson', 'single'}\nif log_format is not None and log_format not in VALID_FORMATS:\n    raise SystemExit(f'log_format must be one of {sorted(VALID_FORMATS)}, got {log_format!r}')","typeGuard":"def is_valid_log_format(fmt: str | None) -> bool:\n    return fmt is None or fmt in {'json_array', 'ndjson', 'single'}","tryCatchPattern":"try:\n    GenericAPILogger(endpoint=endpoint, log_format=fmt)\nexcept ValueError as e:\n    if 'log_format' in str(e):\n        fmt = 'json_array'  # fall back to default and warn\n        logger.warning('Invalid log_format; using json_array')\n    raise","preventionTips":["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."],"tags":["generic-api","logging-callback","enum-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}