MoonshotAI / MoonshotAI/kimi-code

[Bug] `metadata` field causes false 262144 token limit error on k3 (286K request)

Open
#3,530 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.5k
Forks
1.2k
Avg merge
11h 53m
Merged PRs (30d)
350

Description

Title: 服务端 bug:请求体带 metadata 字段时 k3 256K token 校验被误触发

现象

https://api.kimi.com/coding/v1/messages?beta=true 发送一份 286657 tokens
的请求(model=k3, 81 tools, 405 messages, stream=false):

  • 请求体 metadata 字段 → 返回 400:
    Invalid request: Your request exceeded model token limit: 262144 (requested: 286657)
  • 同一请求仅删除 metadata 字段 → 返回 200,
    usage.cache_read_input_tokens = 293471,model=k3,正常推理。

预期行为

metadata 是 Anthropic Messages API 规范里的可选业务元数据字段,
语义上只用于业务侧标识,不应参与 token 上限校验。k3 的实际上限是 1M,
286657 tokens 远低于 1M,无论是否带 metadata 都应该通过。

实证

我做了 12 发单变量受控实验,每次只改一个字段,其他完全一致:

变体 status requested_tokens
baseline(带 metadata) 400 286657
改 model 名(4 种:k3[1m]/kimi-for-coding/kimi-for-coding-highspeed/kimi-k3) 400 286657
删 anthropic-beta header(3 种) 400 286657
改/删 thinking(2 种) 400 286657
删 context_management + output_config 400 282363
只删 metadata 200

反向验证 3 发一致:no_metadata PASS × 2 + baseline fail × 1。

完整请求/响应样本在本地存档,如需要可提供(脱敏后):

  • variants/baseline/ — 带 metadata 的完整请求与 400 响应
  • variants/no_metadata/ — 同请求删 metadata 后的 200 响应

猜测(供定位)

可能的原因:

  1. metadata 被当作 cache key 一部分,误判『需重新加载完整 context』
  2. 路由逻辑里带 metadata 走某条有 256K 硬限的分支
  3. metadata.user_id 触发了账号级限流/档位校验

环境

  • Claude Code CLI 2.1.260 (npm 全局)
  • Kimi For Coding Allegretto 档
  • 端点:api.kimi.com/coding/v1/messages?beta=true

Contributor guide

Open the contributing guide

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.

Research direction

Start by reproducing the controlled comparison against https://api.kimi.com/coding/v1/messages?beta=true using the archived baseline and no_metadata request variants. Compare server behavior with and without metadata, then identify the relevant server-side validation or routing entry point; done means a 286657-token k3 request succeeds consistently when metadata is present.

Written by the indexing model from the issue text.

Assessment

Domain
api, backend
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.