fix: add thinking parameter for OpenAI-compatible APIs with supportsReasoningBinary #11032
+155
−0
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.
Related GitHub Issue
Closes: #11001
Description
This PR attempts to address Issue #11001 where OpenAI-compatible APIs (like volcengine's Ark API) return an error when using reasoning effort: "Invalid combination of reasoning_effort and thinking type: medium + disabled"
Root Cause: Some OpenAI-compatible APIs require both the
reasoning_effortparameter (e.g., "medium") AND athinkingparameter set to{ type: "enabled" }. The OpenAI handler was sendingreasoning_effortbut not thethinkingparameter, creating an invalid state.Implementation Details:
Added
thinking: { type: "enabled" }parameter insrc/api/providers/openai.tswhen:reasoningobject is present), ANDsupportsReasoningBinaryflag is trueApplied the fix to three locations:
createMessagemethod (streaming path)handleO3FamilyMessagemethod (streaming path)handleO3FamilyMessagemethod (non-streaming path)This follows the same pattern already implemented in
base-openai-compatible-provider.tsUsage: Users can enable this by setting
supportsReasoningBinary: truein their custom model info configuration.Test Procedure
Added 5 new test cases to verify the thinking parameter behavior:
should include thinking parameter when supportsReasoningBinary is true and reasoning effort is enabledshould not include thinking parameter when supportsReasoningBinary is false even with reasoning effort enabledshould include thinking parameter for O3 model when supportsReasoningBinary is trueshould not include thinking parameter for O3 model when supportsReasoningBinary is falseshould include thinking parameter for O3 model in non-streaming mode when supportsReasoningBinary is trueAll 53 tests pass:
cd src && npx vitest run api/providers/__tests__/openai.spec.tsPre-Submission Checklist
Documentation Updates
supportsReasoningBinaryin custom model info.Additional Notes
Feedback and guidance are welcome!
Important
Adds
thinkingparameter to OpenAI-compatible APIs whenreasoning_effortis used andsupportsReasoningBinaryis true, with tests verifying behavior.thinking: { type: "enabled" }parameter inopenai.tswhenreasoning_effortis used andsupportsReasoningBinaryis true.createMessageandhandleO3FamilyMessagemethods for both streaming and non-streaming paths.openai.spec.tsto verifythinkingparameter behavior under different conditions.supportsReasoningBinarytrue/false and streaming/non-streaming modes.This description was created by
for 19bd598. You can customize this summary. It will automatically update as commits are pushed.