mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-24 16:05:44 +08:00
fix(bedrock): filter unsupported top-level fields and fix beta token cleanup
- Remove `provider` and `metadata` fields from Bedrock request body. Bedrock returns 400 ValidationException for unknown top-level fields. - When filtered beta tokens list is empty, delete any pre-existing `anthropic_beta` field in body to prevent client-injected tokens from leaking to Bedrock unfiltered. - Add `context-management-2025-06-27` and `fine-grained-tool-streaming-2025-05-14` to bedrockSupportedBetaTokens whitelist per AWS documentation.
This commit is contained in:
@@ -215,8 +215,14 @@ func PrepareBedrockRequestBodyWithTokens(body []byte, modelID string, betaTokens
|
||||
return nil, fmt.Errorf("inject anthropic_beta: %w", err)
|
||||
}
|
||||
logger.LegacyPrintf("service.gateway", "[Bedrock] Injected beta tokens: %v (model=%s ccCompat=%v)", betaTokens, modelID, ccCompat)
|
||||
} else {
|
||||
body, _ = sjson.DeleteBytes(body, "anthropic_beta")
|
||||
}
|
||||
|
||||
// 移除 Bedrock 不支持的 Anthropic 直连 API 专有顶层字段
|
||||
body, _ = sjson.DeleteBytes(body, "provider")
|
||||
body, _ = sjson.DeleteBytes(body, "metadata")
|
||||
|
||||
// 移除 model 字段(Bedrock 通过 URL 指定模型)
|
||||
body, err = sjson.DeleteBytes(body, "model")
|
||||
if err != nil {
|
||||
@@ -465,11 +471,12 @@ func parseAnthropicBetaHeader(header string) []string {
|
||||
// 参考: AWS Bedrock 官方文档 + litellm anthropic_beta_headers_config.json
|
||||
// 更新策略: 当 AWS Bedrock 新增支持的 beta token 时需同步更新此白名单
|
||||
var bedrockSupportedBetaTokens = map[string]bool{
|
||||
"computer-use-2025-01-24": true,
|
||||
"computer-use-2025-11-24": true,
|
||||
"context-1m-2025-08-07": true,
|
||||
// "context-management-2025-06-27": false, // 无官方文档支持
|
||||
"compact-2026-01-12": true, // 官方支持,仅 InvokeModel API(Opus 4.6+)
|
||||
"computer-use-2025-01-24": true,
|
||||
"computer-use-2025-11-24": true,
|
||||
"context-1m-2025-08-07": true,
|
||||
"context-management-2025-06-27": true, // compaction + clear_thinking,AWS 文档已支持
|
||||
"compact-2026-01-12": true, // 官方支持,仅 InvokeModel API(Opus 4.6+)
|
||||
"fine-grained-tool-streaming-2025-05-14": true, // AWS Tool Use 文档已支持
|
||||
// "interleaved-thinking-2025-05-14": false, // 无官方文档支持
|
||||
"tool-search-tool-2025-10-19": true,
|
||||
"tool-examples-2025-10-29": true,
|
||||
|
||||
Reference in New Issue
Block a user