Skip to content

Pi: amazon-bedrock sessions are dropped from cost history, and 1-hour cache writes are priced as 5-minute writes #4121

Description

@oryband

Problem

With the Pi provider enabled, codexbar cost --provider pi shows no history for Pi sessions that run on Amazon Bedrock. Pi writes "provider": "amazon-bedrock" on each assistant message. PiSessionCostScanner.mappedProvider(fromPiProvider:) accepts only openai-codex and anthropic, so the scanner drops every Bedrock row as an unsupported backend. docs/pi.md documents 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 main at 25bba9b7.

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

extractUsage passes cacheWrite to claudeCostUSD without a 1-hour count, so the scanner prices every cache write at 1.25x input. With PI_CACHE_RETENTION=long, Pi records 1-hour writes in usage.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 both anthropic-messages and bedrock-converse-stream.

This already affects supported anthropic sessions. 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:

The input, output, cache-read and cache-write rates agree, including the 10% premium for regional profiles (us., eu. and others) over global.. The usage.cost.total value that Pi records matched AWS list rates on each of about 7,000 Claude rows that I checked.

Suggested fix

One of these:

  1. Map amazon-bedrock rows by model family (anthropic.claude-* to Claude, openai.gpt-* to Codex). Price them from the models.dev amazon-bedrock catalog with the full model ID, so that a regional prefix keeps its own rate. Read cacheWrite1h for Claude rows.
  2. Use the usage.cost.total value 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.

Activity

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

    P2Normal priority bug or improvement with limited blast radius.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper 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:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:otherThis 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.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions