diff --git a/backend/open_webui/apps/openai/main.py b/backend/open_webui/apps/openai/main.py index 87bcc042c..93155063f 100644 --- a/backend/open_webui/apps/openai/main.py +++ b/backend/open_webui/apps/openai/main.py @@ -411,7 +411,12 @@ async def generate_chat_completion( # Change max_completion_tokens to max_tokens (Backward compatible) if "api.openai.com" not in url and not payload["model"].lower().startswith("o1-"): if "max_completion_tokens" in payload: - payload["max_tokens"] = payload.pop("max_completion_tokens") + # Remove "max_completion_tokens" from the payload + payload["max_tokens"] = payload["max_completion_tokens"] + del payload["max_completion_tokens"] + else: + if "max_tokens" in payload and "max_completion_tokens" in payload: + del payload["max_tokens"] # Convert the modified body back to JSON payload = json.dumps(payload)