@@ -89,18 +89,29 @@ func isOSeriesModel(model string) bool {
8989 return len (m ) >= 2 && m [0 ] == 'o' && m [1 ] >= '0' && m [1 ] <= '9'
9090}
9191
92- // adaptForOSeries rewrites a ChatRequest body for OpenAI o-series models,
93- // mapping max_tokens -> max_completion_tokens and dropping temperature while
94- // preserving all unknown top-level JSON fields.
95- func adaptForOSeries (req * core.ChatRequest ) (any , error ) {
92+ func isGPT5Model (model string ) bool {
93+ m := strings .ToLower (strings .TrimSpace (model ))
94+ return m == "gpt-5" || strings .HasPrefix (m , "gpt-5-" )
95+ }
96+
97+ // isReasoningChatModel reports whether the model follows OpenAI's reasoning
98+ // chat parameter rules for max_completion_tokens and temperature handling.
99+ func isReasoningChatModel (model string ) bool {
100+ return isOSeriesModel (model ) || isGPT5Model (model )
101+ }
102+
103+ // adaptForReasoningChat rewrites a ChatRequest body for OpenAI reasoning chat
104+ // models, mapping max_tokens -> max_completion_tokens and dropping temperature
105+ // while preserving all unknown top-level JSON fields.
106+ func adaptForReasoningChat (req * core.ChatRequest ) (any , error ) {
96107 body , err := json .Marshal (req )
97108 if err != nil {
98- return nil , core .NewInvalidRequestError ("failed to marshal o-series request: " + err .Error (), err )
109+ return nil , core .NewInvalidRequestError ("failed to marshal reasoning request: " + err .Error (), err )
99110 }
100111
101112 var raw map [string ]json.RawMessage
102113 if err := json .Unmarshal (body , & raw ); err != nil {
103- return nil , core .NewInvalidRequestError ("failed to decode o-series request payload: " + err .Error (), err )
114+ return nil , core .NewInvalidRequestError ("failed to decode reasoning request payload: " + err .Error (), err )
104115 }
105116 if maxTokens , ok := raw ["max_tokens" ]; ok {
106117 raw ["max_completion_tokens" ] = maxTokens
@@ -113,8 +124,8 @@ func adaptForOSeries(req *core.ChatRequest) (any, error) {
113124// chatRequestBody returns the appropriate request body for the model.
114125// Reasoning models get parameter adaptation; others pass through as-is.
115126func chatRequestBody (req * core.ChatRequest ) (any , error ) {
116- if isOSeriesModel (req .Model ) {
117- return adaptForOSeries (req )
127+ if isReasoningChatModel (req .Model ) {
128+ return adaptForReasoningChat (req )
118129 }
119130 return req , nil
120131}
0 commit comments