Skip to content

fix(pricing): current Anthropic rates, [1m] and version-safe resolution, 1h cache writes (UM-1591) - #1696

Merged
jaywedgeworth22 merged 2 commits into
mainfrom
claude/UM-1591-pricing-fix
Oct 18, 2026
Merged

jaywedgeworth22 merged 2 commits into
mainfrom
claude/UM-1591-pricing-fix

Conversation

@jaywedgeworth22

@jaywedgeworth22 jaywedgeworth22 commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Fixes UM-1591

Summary

Updates Anthropic API-equivalent pricing and token-cost derivation so that current model rates and 1-hour cache writes are priced correctly. The change corrects previously over- or under-estimated costs caused by fuzzy model matching, [1m] context markers, missing 1-hour cache rates, and long-prompt tiers.

Key changes

  • Current Anthropic rates

    • Removes hardcoded Opus/Sonnet runtime overrides and resolves Anthropic rates from the bundled catalog.
    • Adds pinned tests for Anthropic, OpenAI GPT-5.5/5.6/6, xAI Grok 4.5–4.7, and MiniMax M3 rates so catalog drift fails CI.
    • Adds MiniMax M3 PAYG pricing (including its long-context tier) and marks the plan-only MiniMax M3.1 Flash Preview as explicitly unpriced.
  • Version-safe model resolution

    • Strips trailing [1m]/[...] markers and normalizes dotted Claude versions (claude-opus-5.5 → claude-opus-5-5).
    • Prevents prefix fallback from matching a shorter version key: claude-opus-5-5 no longer resolves to claude-opus-5, and unknown versions such as claude-opus-5-9 are reported as unpriced instead of borrowing another model’s rates.
    • Preserves date/alias suffix matching such as -20251001, -latest, and -20260401.
  • 1-hour cache writes

    • Adds a canonical cacheCreation1h token bucket with aliases (cacheWrite1h, cacheWriteOneHour, etc.).
    • Honors metadata.cacheTtl / metadata.ttl values indicating a 1-hour TTL.
    • Prices 1-hour writes at the published 1-hour rate; when no 1-hour rate exists, falls back to the 5-minute rate and flags the derivation incomplete.
    • Uses canonical token types across cost checking, ingest derivation, LLM burn, agents overview, and external usage aggregation so 1-hour writes are not silently treated as 5-minute writes.
  • Long-prompt tiers

    • Adds a configurable long-context threshold (default 200k; Haiku 5.5 uses 100k).
    • Adds the Claude Haiku 5.5 over-100k-token tier at 5× standard rates.
    • For grouped rows without per-request prompt sizes, keeps the point estimate at standard rates and reports the long-tier cost only as an upper bound.
  • Cost check reporting

    • Adds pricingStatus (priced / unpriced / no-tokens), derivedCostUpperBoundUsd, and hasLongPromptTier.
    • Separates 5-minute and 1-hour cache-write totals.
    • Treats untyped cache writes as a lower bound between the 5-minute and 1-hour rates, and includes 1-hour writes in unpriced/incomplete counting.

Tests

Adds and updates tests covering:

  • Pinned provider rate tables.
  • [1m] and dotted-version normalization.
  • Unknown-version unpriced behavior.
  • 1-hour cache-write pricing and TTL aliases.
  • Haiku 5.5 long-prompt tier behavior.
  • Cost-check lower/upper bound reporting.
  • Ingest cost derivation for 1-hour writes and [1m] models.

Review note

An automated review reported one medium finding: “Business logic gap detected based on PR requirements.” No specific file, line, or failing scenario was provided with the finding, so it could not be tied to a concrete code path in the supplied changes.

…on, 1h cache writes (UM-1591)

Refresh the LiteLLM snapshot (now carries claude-opus-5-5, sonnet-5-5, haiku-5-5 and fable-5-1 at the published Anthropic rates) and drop the hand-written Anthropic overrides.  Rates are pinned in a new test against the Anthropic pricing page read 2026-10-17.

Resolution: strip the [1m] marker (no premium on Claude 4.6+), fold dotted Claude versions, and stop the prefix fallback from matching a shorter version key (claude-opus-5-5[1m] was priced as Opus 5, +69%; claude-fable-5-1 as Fable 5, +40%).  Unknown versions now report unpriced.

Pricing: add a cacheCreation1h bucket (aliases cacheWrite1h, cacheWriteOneHour, metadata cacheTtl=1h) and a long-prompt tier with its own threshold (Haiku 5.5 over 100k tokens pays 5x).  MiniMax M3 priced, M3.1 Flash Preview left unpriced (plan-only).  Cost check now reports pricingStatus, a 5m..1h band for untyped cache writes, and applies the Haiku tier from per-row prompt size.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Oct 18, 2026

Copy link
Copy Markdown

UM-1591

@jaywedgeworth22
jaywedgeworth22 enabled auto-merge (squash) October 18, 2026 01:20
Comment thread src/lib/claude-cost-check.ts Outdated
… rows (UM-1591)

An exporter flush can combine many requests, so averaging prompt tokens per row could price short requests at the 5x tier.  The point estimate now always uses the standard tier, and the long tier only widens derivedCostUpperBoundUsd.  The tier is applied only by callers that know per-request prompt size (deriveTokenCostUsd with longContext).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jaywedgeworth22
jaywedgeworth22 merged commit d8a3f96 into main Oct 18, 2026
10 checks passed
@jaywedgeworth22
jaywedgeworth22 deleted the claude/UM-1591-pricing-fix branch October 18, 2026 01:30
@kody-ai

kody-ai Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ✅

Access your configuration settings here.

​

@kody-ai

kody-ai Bot commented Oct 18, 2026

Copy link
Copy Markdown

kody code-review Business Logic medium

Business Rules Validation

Task: 5773430482 — Provision Canonical iOS Records to Unblock Widget Fix Delivery
Task Link: https://github.com/Simple-With-Us/Usage-Monitor/issues/1634
Status: Issues Found
Confidence: high

Findings

MUST_FIX: PR scope does not match the task scope

Requirement: "Provision Canonical iOS Records" with active bundle IDs "Usage Monitor app: com.simplewithus.usage.client.ios", "Widget extension: com.simplewithus.usage.client.ios.widget", "Local Monitor app: com.simplewithus.usage.local.ios"; App Group group.com.simplewithus.usage; scripts/ios-fleet/apps.json keeps ASC records pending; ship script refuses to upload until host-app records are registered; legacy records 6799230435 / 6799230729 must not be used.
Missing in code: No evidence in this PR diff of any change related to iOS bundle identifiers, Apple Developer Portal App IDs, App Store Connect records, App Group entitlements, scripts/ios-fleet/apps.json, Push Notifications capability, or the hosted ship-script gating.
Evidence (Code): The PR diff is confined to src/lib/pricing/*, src/lib/claude-cost-check.ts, src/lib/llm-burn.ts, src/lib/external-usage-events.ts, src/lib/agents-overview.ts, and their test files. All touched symbols — canonicalTokenType, isOneHourCacheTtl, normalizeModelName, resolvePricingKey, deriveTokenCostUsd, CLAUDE_HAIKU_5_5_LONG_PROMPT_PATCH, CATALOG_PATCHES, MINIMAX_M3 — are in the Anthropic/LiteLLM model-pricing domain. The PR description also fixes UM-1591 (model pricing), not the iOS provisioning task.
Suggested action: Either update this PR to deliver the iOS bundle/App Group/ASC provisioning artifacts required by the task (and update the rollout doc + scripts/ios-fleet/apps.json), or relink the PR to a UM-1591 tracking ticket and reopen/assign task 5773430482 to whichever PR actually provisions the canonical iOS records.

MUST_FIX: No evidence in this PR diff of implementing any of the three acceptance-criteria bundle IDs

Requirement: AC #1 "Usage Monitor app: com.simplewithus.usage.client.ios"; AC #2 "Widget extension: com.simplewithus.usage.client.ios.widget"; AC #3 "Local Monitor app: com.simplewithus.usage.local.ios".
Missing in code: No evidence in this PR diff of any of the three bundle IDs. The diff contains no iOS provisioning files, no Info.plist, no entitlements, no apps.json, no Xcode project changes, and no Developer Portal App ID definitions.
Evidence (Code): This PR diff does not show changes in the iOS provisioning area required by the task.
Suggested action: Add (or link to a separate PR that adds) the canonical bundle IDs to the iOS project and to scripts/ios-fleet/apps.json, configure the Widget extension as a separate Developer Portal App ID with App Groups enabled, and ensure the Client app's Push Notifications capability is enabled.

MUST_FIX: No evidence in this PR diff of honoring the legacy-record blacklist

Requirement: "Do not use the legacy records 6799230435 / 6799230729; they belong to retired bundle IDs."
Missing in code: No evidence in this PR diff of any reference to the legacy Apple IDs 6799230435 or 6799230729, nor to the scripts/ios-fleet/apps.json record-pending state, nor to the hosted ship-script refusal logic.
Evidence (Code): The diff does not touch scripts/ios-fleet/ or any ship-script files.
Suggested action: Verify that scripts/ios-fleet/apps.json (or equivalent fleet manifest) and the hosted ship script enforce the retired-records blacklist and block uploads until the new host-app ASC records are registered; this PR does not show that change.

SUGGESTION: Push Notifications capability not visible in this PR diff

Requirement: "The Client app also needs Push Notifications."
Missing in code: No evidence in this PR diff of enabling the Push Notifications capability (APNs entitlement, aps-environment, or Info.plist key) for com.simplewithus.usage.client.ios.
Evidence (Code): This PR diff does not show changes in the iOS provisioning area required by the task.
Suggested action: Add the APNs entitlement to the Client app's entitlements file and document the APNs key registration step for the owner.

INFO: Rollout doc link not enforced by any code change in this PR diff

Requirement: "Implementation and exact portal steps: docs/rollouts/2026-10-09-ios-bundle-identifiers.md."
Observation: This PR diff does not modify the rollout document or any tooling that references it. The canonical implementation steps therefore live only in the doc, with no in-repo enforcement.
Suggested action: Confirm the rollout doc still reflects the current owner-approved bundle IDs and App Group; link it from scripts/ios-fleet/apps.json and the ship script so the upload block cites it.

Requirements Verified


Analysis performed by Kodus AI Business Rules Validator


💡 This validation runs automatically only on the first review of a pull request. To run it again, comment @kody -v business-logic.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant