@@ -14,6 +14,11 @@ import (
1414 "github.com/tidwall/gjson"
1515)
1616
17+ const (
18+ defaultResponsesMaxOutputTokens = 65536
19+ gpt55ResponsesMaxOutputTokens = 128000
20+ )
21+
1722// ValidationRule represents a validation rule function
1823type ValidationRule func (value gjson.Result , path string ) * ValidationError
1924
@@ -419,13 +424,30 @@ func ChatCompletionValidationRules() map[string][]ValidationRule {
419424 }
420425}
421426
427+ // ResponsesMaxOutputTokensForModel returns the downstream validation cap for
428+ // max_output_tokens. Most Codex models still use the legacy 64k output cap,
429+ // while gpt-5.5 clients may legitimately request up to 128k.
430+ func ResponsesMaxOutputTokensForModel (model string ) int {
431+ switch strings .ToLower (strings .TrimSpace (model )) {
432+ case "gpt-5.5" :
433+ return gpt55ResponsesMaxOutputTokens
434+ default :
435+ return defaultResponsesMaxOutputTokens
436+ }
437+ }
438+
422439// ResponsesAPIValidationRules returns validation rules for responses API request
423440// Note: input can be either a string or an array of items (validated separately)
424441func ResponsesAPIValidationRules () map [string ][]ValidationRule {
442+ return ResponsesAPIValidationRulesForModel ("" )
443+ }
444+
445+ func ResponsesAPIValidationRulesForModel (model string ) map [string ][]ValidationRule {
446+ maxOutputTokens := ResponsesMaxOutputTokensForModel (model )
425447 return map [string ][]ValidationRule {
426448 "model" : {Required (), TypeString (), MaxLength (64 )},
427449 // input validation is handled separately to support both string and array formats
428- "max_output_tokens" : {TypeNumber (), MinValue (1 ), MaxValue (65536 )},
450+ "max_output_tokens" : {TypeNumber (), MinValue (1 ), MaxValue (float64 ( maxOutputTokens ) )},
429451 "temperature" : {TypeNumber (), Range (0 , 2 )},
430452 "top_p" : {TypeNumber (), Range (0 , 1 )},
431453 "stream" : {TypeBoolean ()},
@@ -451,7 +473,7 @@ func ValidateChatCompletionsRequest(body []byte, supportedModels []string) *Vali
451473
452474// ValidateResponsesAPIRequest validates a responses API request with model validation
453475func ValidateResponsesAPIRequest (body []byte , supportedModels []string ) * ValidationResult {
454- rules := ResponsesAPIValidationRules ( )
476+ rules := ResponsesAPIValidationRulesForModel ( gjson . GetBytes ( body , "model" ). String () )
455477 rules ["model" ] = append (rules ["model" ], ModelValidator (supportedModels ))
456478 validator := NewValidator (body )
457479 return validator .ValidateRequest (rules )
0 commit comments