Claude Code返回错误“Extra inputs are not permitted”
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
Research direction
Start at gateway_request.go around line 629 and inspect removeThinkingDependentContextStrategies and the surrounding request preprocessing. Reproduce the Claude Code request with extra context_management fields, then run the relevant Go tests or add coverage for the forwarding path. Done means only the supported edits field is forwarded and the upstream error no longer occurs.
Written by the indexing model from the issue text.
Description
claude上游返回这个消息:
{
"error": {
"message": "context_management: Extra inputs are not permitted",
"type": "invalid_request_error"
},
"request_id": "req_011CaQfPxNfmqWaj8EQVM4WB",
"type": "error"
}
代码里对 context_management 只处理了 edits 数组的内容(过滤特定 type),但没有对整个 context_management 对象做字段白名单。
Claude API 的 context_management 只允许 edits 这一个字段,如果上游客户端传了其他字段(比如 enabled: true、type: xxx 等顶层 key),就会触发这个错误。
问题根源:客户端发了类似这样的请求体:
{
"context_management": {
"enabled": true, // ← Claude 不认识这个字段
"edits": [...]
}
}
修复方案:在转发给 Claude 之前,对 context_management 做白名单清理,只保留 edits。
在 gateway_request.go:629 附近的 removeThinkingDependentContextStrategies 函数,或者在更上层的请求预处理中加一个过滤:
// 只保留 Claude 支持的字段
func sanitizeContextManagement(body []byte) []byte {
cm := gjson.GetBytes(body, "context_management")
if !cm.Exists() {
return body
}
edits := gjson.GetBytes(body, "context_management.edits")
// 删掉整个 context_management,再只写回 edits
body, _ = sjson.DeleteBytes(body, "context_management")
if edits.Exists() {
body, _ = sjson.SetRawBytes(body, "context_management.edits", []byte(edits.Raw))
}
return body
}
- Dominant language
- Go
- Stars
- 42.1k
- Forks
- 9k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 343
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Wei-Shaw/sub2api
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
All issues in Wei-Shaw/sub2api
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
kind/cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
kubernetes-sigs/kueue#15947 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sympozium-ai/sympozium#627 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100