Skip to content

feat(weave): add cache token pricing columns to llm_token_prices#6484

Closed
andrewtruong wants to merge 6 commits intomasterfrom
andrew/l3-cache-price-columns
Closed

feat(weave): add cache token pricing columns to llm_token_prices#6484
andrewtruong wants to merge 6 commits intomasterfrom
andrew/l3-cache-price-columns

Conversation

@andrewtruong
Copy link
Copy Markdown
Collaborator

Summary

  • Add ClickHouse migration 026_add_cache_token_costs with cache_read_input_token_cost and cache_write_input_token_cost columns (Float64, DEFAULT 0)
  • Add same columns to SQLite llm_token_prices CREATE TABLE
  • Update LLM_TOKEN_PRICES_COLUMNS in token_costs.py and build_model_prices_query to SELECT the new columns
  • Add cache_read_input_token_cost and cache_write_input_token_cost to CostCreateInput (default 0.0) and CostQueryOutput
  • Update SQLite _ensure_default_costs, _apply_costs_to_calls, and cost_create to read/write/compute with cache pricing

Context

This is Layer 3 of the cached token tracking feature. It adds the storage columns for variable cache pricing, enabling downstream cost data fetching (L4) from LiteLLM and cache-aware cost calculation (L5).

Test plan

  • ClickHouse migration applies cleanly (up and down)
  • SQLite tests pass with new schema
  • cost_create accepts cache pricing fields
  • cost_query returns cache pricing fields
  • _apply_costs_to_calls computes cache token costs when pricing data exists
  • Existing cost tests pass unchanged (new columns default to 0)

🤖 Generated with Claude Code

andrewtruong and others added 2 commits March 28, 2026 10:24
Add cache_read_input_tokens and cache_write_input_tokens to
LLMUsageSchema, LLMCostSchema, and LLMAggregatedUsage so the data model
can represent cached token counts and their costs.

Update usage_utils.py to extract, normalize (cache_creation_input_tokens
→ cache_write_input_tokens), merge, and aggregate the new fields through
the call hierarchy.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add cache_read_input_token_cost and cache_write_input_token_cost columns
to the llm_token_prices table in both ClickHouse (migration 026) and
SQLite.  Update LLM_TOKEN_PRICES_COLUMNS, CostCreateInput,
CostQueryOutput, and the SQLite cost application logic to read, write,
and compute costs using the new columns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@wandbot-3000
Copy link
Copy Markdown

wandbot-3000 Bot commented Mar 28, 2026

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 28, 2026

Codecov Report

❌ Patch coverage is 43.75000% with 18 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
weave/trace_server/usage_utils.py 0.00% 14 Missing ⚠️
weave/trace_server/sqlite_trace_server.py 0.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

andrewtruong and others added 4 commits March 28, 2026 11:22
026 is now taken by object_version_first_seen from master.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

This PR has been inactive for 14 days. It will be closed in 7 days unless there is new activity.

@github-actions github-actions Bot added the Stale label Apr 12, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant