22import hashlib
33import json
44import logging
5+ import re
56from typing import Optional
67from urllib .parse import urlparse
78
@@ -739,8 +740,16 @@ def get_azure_allowed_params(api_version: str) -> set[str]:
739740 return allowed_params
740741
741742
742- def is_openai_reasoning_model (model : str ) -> bool :
743- return model .lower ().startswith (('o1' , 'o3' , 'o4' , 'gpt-5' ))
743+ def is_openai_new_model (model : str ) -> bool :
744+ model_lower = model .lower ()
745+ # o-series models (o1, o3, o4, o5, ...)
746+ if re .match (r'^o\d+' , model_lower ):
747+ return True
748+ # gpt-N where N >= 5 (gpt-5, gpt-5.2, gpt-6, ...)
749+ m = re .match (r'^gpt-(\d+)' , model_lower )
750+ if m and int (m .group (1 )) >= 5 :
751+ return True
752+ return False
744753
745754
746755def convert_to_azure_payload (url , payload : dict , api_version : str ):
@@ -750,7 +759,7 @@ def convert_to_azure_payload(url, payload: dict, api_version: str):
750759 allowed_params = get_azure_allowed_params (api_version )
751760
752761 # Special handling for o-series models
753- if is_openai_reasoning_model (model ):
762+ if is_openai_new_model (model ):
754763 # Convert max_tokens to max_completion_tokens for o-series models
755764 if 'max_tokens' in payload :
756765 payload ['max_completion_tokens' ] = payload ['max_tokens' ]
@@ -1040,7 +1049,7 @@ async def generate_chat_completion(
10401049 key = request .app .state .config .OPENAI_API_KEYS [idx ]
10411050
10421051 # Check if model is a reasoning model that needs special handling
1043- if is_openai_reasoning_model (payload ['model' ]):
1052+ if is_openai_new_model (payload ['model' ]):
10441053 payload = openai_reasoning_model_handler (payload )
10451054 elif 'api.openai.com' not in url :
10461055 # Remove "max_completion_tokens" from the payload for backward compatibility
0 commit comments