mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 08:05:12 +00:00
A composite route that rewrites the request model left the client's thinking untouched, so a route from claude-sonnet-5 to claude-opus-5-5 forwarded thinking.type=enabled with budget_tokens and validateClaude55Request answered 400 before the request reached the upstream. The route middleware now rewrites the model through RewriteCompositeRequestModel, which replaces a thinking mode that validateClaude55Request rejects for the new model with the nearest mode it accepts: enabled becomes adaptive without budget_tokens, and disabled becomes between_tools on Sonnet 5.5. The mapping is shared with the Bedrock Sonnet 5.5 sanitizer, whose behavior is unchanged. Modes the target still rejects stay with validateClaude55Request, and a request whose model the route does not rewrite keeps its thinking as sent.
28 lines
884 B
Go
28 lines
884 B
Go
package service
|
|
|
|
import (
|
|
"github.com/Wei-Shaw/sub2api/internal/pkg/claude"
|
|
"github.com/tidwall/gjson"
|
|
"github.com/tidwall/sjson"
|
|
)
|
|
|
|
// adaptThinkingToClaude55 replaces a thinking mode that a Claude 5.5 model
|
|
// rejects with the nearest mode it accepts: enabled becomes adaptive without
|
|
// budget_tokens, and on Sonnet 5.5 disabled becomes between_tools. Other modes
|
|
// are left for validateClaude55Request to judge.
|
|
func adaptThinkingToClaude55(body []byte, model string) []byte {
|
|
if !isClaude55SignedThinkingModel(model) {
|
|
return body
|
|
}
|
|
switch gjson.GetBytes(body, "thinking.type").String() {
|
|
case "enabled":
|
|
body, _ = sjson.SetBytes(body, "thinking.type", "adaptive")
|
|
body, _ = sjson.DeleteBytes(body, "thinking.budget_tokens")
|
|
case "disabled":
|
|
if claude.IsSonnet55(model) {
|
|
body, _ = sjson.SetBytes(body, "thinking.type", "between_tools")
|
|
}
|
|
}
|
|
return body
|
|
}
|