Claude Code返回错误“Extra inputs are not permitted”

Open Beginner friendly
#1,968 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
go
Domain
api

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Wei-Shaw/sub2api

All issues in Wei-Shaw/sub2api

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.