Fix: gracefully ignore unsupported OpenAI API parameters#1261
Conversation
…ing errors Previously, parameters like logit_bias, function_call, and suffix would cause HTTP 400 errors. Now they are silently ignored with a debug log warning. Also adds ConfigDict(extra="ignore") to request models so that unknown future OpenAI parameters don't cause Pydantic validation errors.
There was a problem hiding this comment.
Code Review
This pull request updates the API to gracefully handle unsupported parameters by ignoring extra fields in Pydantic models and replacing error responses with debug logs for parameters like logit_bias, function_call, and suffix. Feedback includes a suggestion to broaden the type hint for function_call to prevent validation errors when objects are passed and a recommendation to relocate the suffix check for better code consistency.
| model_config = ConfigDict(extra="ignore") | ||
| model: str | ||
| messages: List[ChatCompletionMessageParam] | ||
| function_call: Optional[str] = "none" |
There was a problem hiding this comment.
To fully achieve the goal of "gracefully ignoring" the function_call parameter, the type should be expanded. In the OpenAI API, function_call can be either a string (e.g., "none", "auto") or an object (e.g., {"name": "my_function"}).
Currently, if a client sends an object-style function_call, Pydantic will raise a validation error before the extra="ignore" logic or the explicit check in api_openai.py can handle it. Changing the type to Union[str, Dict[str, Any]] ensures that any valid OpenAI-style function_call is accepted and then ignored as intended.
| function_call: Optional[str] = "none" | |
| function_call: Optional[Union[str, Dict[str, Any]]] = "none" |
| if request.suffix: | ||
| return create_error_response( | ||
| HTTPStatus.BAD_REQUEST, | ||
| "The suffix parameter is not currently supported", | ||
| ) | ||
| logger.debug("Received unsupported parameter 'suffix', ignoring") |
…)" This reverts commit eac63be.
Summary
logit_bias,function_call,suffix) now emit alogger.debug()warning instead of returning HTTP 400 errorsmodel_config = ConfigDict(extra="ignore")toCompletionRequestandChatCompletionRequestso unknown parameters from clients don't cause Pydantic validation errorsTest plan
logit_bias— should succeed with debug logfunction_call— should succeed with debug logsuffix— should succeed with debug log{"foo": "bar"}) — should succeed without validation error