-
Notifications
You must be signed in to change notification settings - Fork 123
Open
Description
Summary
LLM analysis fails for newer OpenAI-compatible models (gpt-5+, o1, o3 series) because PAC sends max_tokens in the request body, but these models only accept max_completion_tokens.
PAC Version
v0.39.3
Error
OpenAI API error: Error code: 400 - {'error': {'message': "Unsupported parameter: 'max_tokens' is not supported with this model. Use 'max_completion_tokens' instead.", 'type': 'invalid_request_error', 'param': 'max_tokens', 'code': 'unsupported_parameter'}}
Root Cause
In pkg/llm/providers/openai/client.go, the openaiRequest struct hardcodes max_tokens:
type openaiRequest struct {
Model string `json:"model"`
Messages []openaiMessage `json:"messages"`
MaxTokens int `json:"max_tokens,omitempty"`
}
Newer OpenAI models (gpt-5, gpt-5-mini, gpt-5-nano, o1, o3 series) reject max_tokens and require max_completion_tokens instead.
Proposed Fix
Add MaxCompletionTokens to the request struct and conditionally send the correct field based on the model:
```go
type openaiRequest struct {
Model string `json:"model"`
Messages []openaiMessage `json:"messages"`
MaxTokens int `json:"max_tokens,omitempty"`
MaxCompletionTokens int `json:"max_completion_tokens,omitempty"`
}
// In Analyze():
apiRequest := &openaiRequest{
Model: c.config.Model,
Messages: []openaiMessage{{Role: "user", Content: fullPrompt}},
}
if isNewGenerationModel(c.config.Model) {
apiRequest.MaxCompletionTokens = request.MaxTokens
} else {
apiRequest.MaxTokens = request.MaxTokens
}
func isNewGenerationModel(model string) bool {
newGenPrefixes := []string{"gpt-5", "o1", "o3"}
for _, prefix := range newGenPrefixes {
if strings.HasPrefix(model, prefix) {
return true
}
}
return false
}
## Additional Context
This also affects custom OpenAI-compatible API gateways that proxy newer models. The omitempty tag on max_tokens does not help because PAC applies a default value of 1000 when max_tokens is not set in the Repository CR.Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels