-
Notifications
You must be signed in to change notification settings - Fork 2k
Pi: amazon-bedrock sessions are dropped from cost history, and 1-hour cache writes are priced as 5-minute writes #4121
Copy link
Copy link
Closed
Labels
P2Normal priority bug or improvement with limited blast radius.Normal priority bug or improvement with limited blast radius.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.This issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Description
Activity
Metadata
Metadata
Assignees
Labels
P2Normal priority bug or improvement with limited blast radius.Normal priority bug or improvement with limited blast radius.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis issue has meaningful maintainer-visible impact outside the owned taxonomy.This issue has meaningful maintainer-visible impact outside the owned taxonomy.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.
Problem
With the Pi provider enabled,
codexbar cost --provider pishows no history for Pi sessions that run on Amazon Bedrock. Pi writes"provider": "amazon-bedrock"on each assistant message.PiSessionCostScanner.mappedProvider(fromPiProvider:)accepts onlyopenai-codexandanthropic, so the scanner drops every Bedrock row as an unsupported backend.docs/pi.mddocuments this limit. Bedrock is a common way to run Pi inside a company AWS account.I saw this on 0.66.0. The mapping is the same on 0.69.0 and on
mainat25bba9b7.Example assistant row from a Pi session file (content removed):
{"type":"message","message":{"role":"assistant","provider":"amazon-bedrock","api":"bedrock-converse-stream","model":"global.anthropic.claude-opus-5-5","usage":{"input":4,"output":360,"cacheRead":55528,"cacheWrite":161,"cacheWrite1h":161,"totalTokens":56053,"cost":{"input":0.000016,"output":0.0072,"cacheRead":0.0111056,"cacheWrite":0.001288,"total":0.0196096}}}}Model IDs that Pi records on Bedrock:
global.anthropic.claude-*,us.anthropic.claude-*,global.openai.gpt-5.6-*,global.openai.gpt-6-*,global.xai.grok-4.6.Second problem: 1-hour cache writes
extractUsagepassescacheWritetoclaudeCostUSDwithout a 1-hour count, so the scanner prices every cache write at 1.25x input. WithPI_CACHE_RETENTION=long, Pi records 1-hour writes inusage.cacheWrite1h. Anthropic and Bedrock charge those at 2x input. The code comment says that Pi JSONL does not record cache retention, but current Pi records it for bothanthropic-messagesandbedrock-converse-stream.This already affects supported
anthropicsessions. On one month of my Opus 5.5 usage with long retention, the scanner formula came out about 20% below the recorded cost.Pricing check
I compared the rates for the models above in three places:
amazon-bedrockcatalog.usage.costvalues that Pi records.The input, output, cache-read and cache-write rates agree, including the 10% premium for regional profiles (
us.,eu.and others) overglobal.. Theusage.cost.totalvalue that Pi records matched AWS list rates on each of about 7,000 Claude rows that I checked.Suggested fix
One of these:
amazon-bedrockrows by model family (anthropic.claude-*to Claude,openai.gpt-*to Codex). Price them from the models.devamazon-bedrockcatalog with the full model ID, so that a regional prefix keeps its own rate. ReadcacheWrite1hfor Claude rows.usage.cost.totalvalue that Pi records when it is present, as feat(core): expand pi session attribution and reported cost handling #2575 proposed.I can test a build against real Bedrock sessions.