Skip to content

Fix: gracefully ignore unsupported OpenAI API parameters#1261

Merged
sufubao merged 1 commit intomainfrom
fix/graceful-ignore-unsupported-params
Apr 7, 2026
Merged

Fix: gracefully ignore unsupported OpenAI API parameters#1261
sufubao merged 1 commit intomainfrom
fix/graceful-ignore-unsupported-params

Conversation

@sufubao
Copy link
Copy Markdown
Collaborator

@sufubao sufubao commented Apr 7, 2026

Summary

  • Unsupported OpenAI API parameters (logit_bias, function_call, suffix) now emit a logger.debug() warning instead of returning HTTP 400 errors
  • Added model_config = ConfigDict(extra="ignore") to CompletionRequest and ChatCompletionRequest so unknown parameters from clients don't cause Pydantic validation errors

Test plan

  • Send a chat completion request with logit_bias — should succeed with debug log
  • Send a chat completion request with function_call — should succeed with debug log
  • Send a completion request with suffix — should succeed with debug log
  • Send a request with arbitrary unknown parameters (e.g. {"foo": "bar"}) — should succeed without validation error

…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.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
function_call: Optional[str] = "none"
function_call: Optional[Union[str, Dict[str, Any]]] = "none"

Comment on lines 634 to +635
if request.suffix:
return create_error_response(
HTTPStatus.BAD_REQUEST,
"The suffix parameter is not currently supported",
)
logger.debug("Received unsupported parameter 'suffix', ignoring")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better consistency with chat_completions_impl and to keep all parameter validation/ignoring logic at the entry point of the function, consider moving this check to the top of completions_impl, near the logit_bias check.

@sufubao sufubao merged commit eac63be into main Apr 7, 2026
1 check passed
@sufubao sufubao deleted the fix/graceful-ignore-unsupported-params branch April 7, 2026 09:39
sufubao added a commit that referenced this pull request Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant