Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

bug: Chat Completions usage drops cache-write token counts

Abierto Apto para principiantes
#4,368 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
85/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
node.js, typescript
Área
backend

Línea de trabajo

Los convertidores extractUsage (packages/kosong/src/providers/openai-common.ts) y parseOpenAIUsage (packages/agent-core-v2/src/human/llm/requester/bases/openai/format.ts) descartan los tokens de cache-write. Lee ambas funciones, añade cache_write_tokens a inputCacheCreation y réstalo de inputOther. Listo cuando la salida normalizada coincida con el inputCacheCreation: 256 y inputOther: 117 esperados.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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 /approve comment before proceeding with the contribution.
Lenguaje dominante
TypeScript
Estrellas
7.9k
Forks
1.3k
Merge medio
1 d 13 h
PR fusionados (30 d)
97

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de MoonshotAI/kimi-code

Todos los issues de MoonshotAI/kimi-code

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.