bug: One-hour Anthropic cache writes are priced at the 5-minute rate, so spend is 37.5% too low

Abierto
#1,883 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
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go

Línea de trabajo

Read core/parse/inference/anthropic.go around lines 241-276 and the pricing definitions in core/cost/pricing, starting with the Anthropic usage parsing and bundled rates. Add coverage for a mixed 5-minute and 1-hour cache split, then run the relevant Go tests. Done means the 5-minute share retains its current rate and the 1-hour share is priced at 2x the base input rate.

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

Descripción

bug

Problem

Cortex prices every Anthropic cache write at the 5-minute rate. A 1-hour cache write costs 2x the base input price, but Cortex records 1.25x. So the spend for 1-hour cache writes is 37.5% too low.

Example

claude-sonnet-4-5, cache_creation_input_tokens: 100000, all of them ephemeral_1h_input_tokens:

  • Cortex records 100000 × $3.75/MTok = $0.375.
  • Anthropic bills 100000 × $6.00/MTok = $0.60.

No unpriced or incomplete marker appears.

Source

Anthropic's prompt-caching docs (https://platform.claude.com/docs/en/build-with-claude/prompt-caching):

  • "Cache write tokens with a 5-minute TTL are 1.25 times the base input tokens price."
  • "Cache write tokens with a 1-hour TTL are 2 times the base input tokens price."
  • The usage object gives the split in usage.cache_creation.{ephemeral_5m_input_tokens, ephemeral_1h_input_tokens}. cache_creation_input_tokens is their sum.

Cause (main at 676557d35)

  • core/parse/inference/anthropic.go:241-276 reads only cache_creation_input_tokens.
  • core/cost/pricing has one TierCacheWrite. core/cost/pricing/bundled.go:164-166 sets it to 1.25x input.
  • No non-test Go file reads ephemeral_1h_input_tokens.

Fix

Parse the cache_creation object. Price the 1-hour share at 2x input: either add a tier, or add (1h tokens × 0.75 × input rate) to the cache-write cost. Keep the 5-minute share as it is. Add a test with a mixed split.

Impact if not fixed

Any agent that sends cache_control: {"type": "ephemeral", "ttl": "1h"} sees too little spend. Not measured: how much of real Claude Code traffic uses the 1-hour TTL. The captured fixtures in the repo show ephemeral_1h_input_tokens: 0.

Lenguaje dominante
Go
Estrellas
26
Forks
46
Merge medio
9 h 55 min
PR fusionados (30 d)
257

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 rossoctl/cortex

Todos los issues de rossoctl/cortex

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.