Skip to content

CLI cost estimate uses outdated per-family prices (Opus overstated 3–3.75×) #72

Description

@axisrow

PRICE_PER_MTOK (src/cli/analyzeSession.ts:50) is keyed by model family only (priceFamily() → parseModelString().family); the model version is ignored. Current models are priced very differently from the table, so est. cost / --breakdown are wrong for most recent sessions. Tests pin numbers derived from the same table, so they cannot catch it.

Расхождения (USD / MTok: input / output / cache read)

family в таблице реально
opus 15 / 75 / 1.5 верно только для Opus ≤4.1. Opus 4.6–5: 5 / 25; Opus 5.5: 4 / 20 / 0.20
sonnet 3 / 15 / 0.3 верно для 4.x. Sonnet 5 / 5.5: 2 / 10 / 0.20
haiku 1 / 5 / 0.1 верно для 4.5. Haiku 5.5: 0.10 / 0.50 (промпт ≤100K; выше — 0.50 / 2.50)
fable — Fable 5 / 5.1: 10 / 50, cache read 0.25 — сейчас unpriced → costPartial

Дополнительно:

  • Cache read неявно = 0.1× input, но у Opus 5.5 это 0.05×, у Fable 5.1 — 0.025×. Нужна явная колонка, а не множитель.
  • Cache write считается только по 5-минутной ставке (1.25× input). 1-часовая запись стоит 2×, а UsageMetadata (src/main/types/jsonl.ts:82) не читает usage.cache_creation.ephemeral_5m_input_tokens / ephemeral_1h_input_tokens — разбивка теряется при парсинге.
  • Тесты (test/main/cli/analyzeSession.test.ts, ~352–484, напр. toBeCloseTo(0.00087) для sonnet) сверяют результат с той же таблицей.

Что сделать

  1. Таблица цен по (family, major, minor) с явными колонками: input, output, cache read, cache write 5m, cache write 1h + комментарий с датой сверки и ссылкой на прайс Anthropic.
  2. Версию брать из parseModelString (src/shared/utils/modelParser.ts уже отдаёт major/minor); fallback для не-Claude моделей (glm) сохранить.
  3. Добавить cache_creation.{ephemeral_5m_input_tokens, ephemeral_1h_input_tokens} в UsageMetadata и парсер; при отсутствии разбивки — считать весь cache_creation_input_tokens как 5m.
  4. Учесть ступенчатую цену Haiku 5.5 (>100K промпта) или явно задокументировать упрощение.
  5. Тесты: эталонные значения выписаны вручную из официального прайса, а не вычислены из таблицы.

Acceptance

  • Тест на каждую строку таблицы с ценой из официального прайса
  • Тест на 1h cache write (2× input) и на раунд со смешанной 5m/1h разбивкой
  • est. cost для Opus 4.8 / Opus 5.5 / Sonnet 5.5 / Haiku 5.5 / Fable 5.1 соответствует прайсу
  • pnpm typecheck && pnpm test зелёные

Activity

  1. axisrow commented on Oct 11, 2026

    @axisrow
    OwnerAuthor

    ⚠️ Данные от Claude Code при повторной перепроверке. Доверия к выводам нет — проверьте дважды.

    Замер на реальной сессии (Claude Code 2.1.296, claude-opus-5-5, замороженная копия файла):

    токены
    input 144
    cache read 14 626 640
    cache write 276 224 — из них 1h: 276 224 (100 %), 5m: 0
    output 64 181
    • CLI: est. cost: $31.93 (формула текущей таблицы opus: 15 / 75 / 1.5 / 18.75).
    • По прайсу Opus 5.5 (4 / 20 / cache read 0.20 / 1h write 8): ≈ $6.42. Завышение 5,0×; основная часть — чтение кэша ($21,94 против $2,93).
    • Все записи в кэш в этой сессии — 1-часовые, так что поддержка cache_creation.ephemeral_1h_input_tokens — не редкий случай, а основной.

    Проверить: jq -s '[.[] | select(.type=="assistant") | .message.usage.cache_creation // empty] | group_by(keys) | map({keys: .[0] | keys, n: length})' <file.jsonl> и пересчитать стоимость по прайсу для своей модели.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions