bug: Chat Completions usage drops cache-write token counts
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 85/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- node.js, typescript
- 領域
- backend
調査の方向性
コンバーターの extractUsage(packages/kosong/src/providers/openai-common.ts)と parseOpenAIUsage(packages/agent-core-v2/src/human/llm/requester/bases/openai/format.ts)はキャッシュ書き込みトークンを落としています。両方の関数を読み、cache_write_tokens を inputCacheCreation に追加し、inputOther から差し引いてください。正規化された出力が期待値の inputCacheCreation: 256 と inputOther: 117 と一致したら完了です。
索引モデルが issue の本文から書いたものです。
説明
What version of Kimi Code is running?
Source checkout at 7ccac2b45b8a3481c76f771bb99c043b562de2c5, including @moonshot-ai/kosong 0.5.6. This is an offline source-function reproduction, not a running CLI session.
Which open platform/subscription were you using?
Moonshot Open Platform Chat Completions response schema. No subscription login or hosted API request was needed for this reproduction.
Which model were you using?
The documented kimi-k3.1-pro usage example.
What platform is your computer?
macOS arm64, Node.js v26.5.0.
What issue are you seeing?
Both Chat Completions usage converters ignore prompt_tokens_details.cache_write_tokens. They return inputCacheCreation: 0 and include those tokens in inputOther instead. The aggregate input count remains correct, but the normalized cache-write breakdown is lost.
The affected conversions are:
What steps can reproduce the bug?
Pass this usage object from the official Chat API example to either converter:
{
"prompt_tokens": 373,
"completion_tokens": 112,
"prompt_tokens_details": {
"cache_write_tokens": 256
}
}
Both currently return the following normalized counters:
{
"inputOther": 373,
"output": 112,
"inputCacheRead": 0,
"inputCacheCreation": 0
}
The v2 converter additionally preserves the original object in raw.
What is the expected behavior?
{
"inputOther": 117,
"output": 112,
"inputCacheRead": 0,
"inputCacheCreation": 256
}
The API documents ordinary input, cache reads and cache writes as mutually exclusive parts of prompt_tokens. Kosong's TokenUsage contract likewise defines inputOther as input that is neither cache-read nor cache-created.
A response with 1,000 input tokens, 600 cached tokens and 256 cache-write tokens should therefore produce 144 ordinary input tokens, 600 cache-read tokens and 256 cache-created tokens. Both converters currently produce 400, 600 and 0.
Additional information
I executed the exact two source functions after stripping TypeScript types. The write-only and read/write cases fail in both implementations; ordinary usage and the legacy top-level cached_tokens cases pass. This was not a package test run, CLI end-to-end test or billing experiment.
This is separate from #2160, which handles partial usage objects without aggregate input counts, and #930, which exposes existing cache counters in the UI. It does not require adding a cache-TTL setting or changing the API's aggregate totals.
The proposed fix is to preserve the reported cache-write count in both existing converters and subtract it from ordinary input, while keeping the existing top-level cache-read precedence and behavior when the new field is absent.
Contribution
- I am willing to submit a PR for this bug fix myself and will wait for a maintainer's
/approvecomment before proceeding with the contribution.
- 主要言語
- TypeScript
- スター
- 7.9k
- フォーク
- 1.3k
- 平均マージ
- 1日 2時間
- マージ済み PR(30日)
- 115
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
MoonshotAI/kimi-code のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
MoonshotAI/kimi-code#4398 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] vis reports legacy tool-triggered swarm sessions as active対応中かも @louisss1016 が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
MoonshotAI/kimi-code#4395 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
MoonshotAI/kimi-code#4392 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
MoonshotAI/kimi-code#4381 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
MoonshotAI/kimi-code#4369 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
MoonshotAI/kimi-code の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
Merit-Systems/x402scan#1312 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Native Web
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
digitalfabrik/integreat-app#4517 ·
メンテナーはふだん 2 日以内に返信
-
TLS guide repeats certs/ in the certificate directory対応中かも @maheshrijal が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
prometheus/docs#3156 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
medusajs/dtc-starter#90 ·
メンテナーはふだん 1 日以内に返信