fix: token limits & Temperature Parameter Errors for Reasoning Models #1937
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix Token Limits & Temperature Parameter Errors for Reasoning Models
🐛 Problem
Reasoning models (GPT-5, o1, o3 series) were failing due to two critical parameter compatibility issues:
max_tokensis too large:100000. This model supports at most 16384 completion tokens.temperaturedoes not support0with reasoning models. Only the default (1) value is supported.🔍 Root Cause
OpenAI's reasoning models have different API parameter requirements than traditional models:
maxCompletionTokensinstead ofmaxTokenstemperature: 1(no custom values)topP,presencePenalty, etc.) are not supported✅ Solution
1. Model Detection System
2. Provider-Specific Token Limits
3. Parameter Compatibility Logic
Token Parameters:
Temperature Parameters:
Parameter Filtering (Streaming):
📁 Files Changed
app/lib/.server/llm/constants.ts→ Added reasoning model detection & provider limitsapp/lib/.server/llm/stream-text.ts→ Fixed streaming parameter compatibilityapp/routes/api.llmcall.ts→ Fixed direct API call parametersapp/lib/modules/llm/types.ts→ AddedmaxCompletionTokensfieldapp/lib/modules/llm/providers/*→ Updated model definitions with completion token limits🧪 Testing
Verified with multiple reasoning models:
gpt-5→ Working with correct parametersgpt-5-chat-latest→ Successful completiono1-preview→ Parameter compatibility confirmedGPT-4,Claude) → Unchanged behavior maintained🎯 Impact
🔧 Debug Logging
Added debug logging for troubleshooting:
✅ This fix ensures seamless integration with OpenAI's latest reasoning models while maintaining backward compatibility with all existing model providers.