Skip to content

feat(pricing): price what was sent, borrow Bedrock prices, count cache toward long context - #227

Merged
fylorn merged 1 commit into
mainfrom
feat/price-what-was-sent
Sep 28, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/price-what-was-sent

Conversation

@fylorn

@fylorn fylorn commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Follows #226 (AWS Bedrock upstreams).

What changes

Priced by the model that was sent. A rule can rewrite the model (set.model), for example claude-sonnet-4-5 → us.anthropic.claude-sonnet-4-5-20250929-v1:0 for a Bedrock upstream. The upstream charges for the model it received, so:

  • Each attempt now records the rewritten model: AttemptView.model (optional; absent when the hop sent what the client asked for, and on WebSocket hops, which never rewrite).
  • The recorder prices a request by the model on the last attempt, falling back to the requested model. The row's model stays what the client asked for, so per-model statistics are unchanged.
  • The unpriced list (unpriced_recent) names the model the price was looked up under, read from the stored routing JSON. That is the name a price override has to use; no schema change.

Bedrock ids get a price. Ids missing from the data set borrow one, always marked estimated (cross_platform):

  1. an inference profile from the model it is named after: apac.anthropic.claude-… → anthropic.claude-… (only the geographies seen in the data set: us, eu, apac, jp, au, us-gov, global)
  2. an Anthropic model on Bedrock from Anthropic's own name: anthropic.claude-opus-4-6-v1 → claude-opus-4-6 (all three version spellings)
  3. the existing direct name → anthropic.<name>-v1:0

Ids the data set lists (most us./eu./global. profiles, with their regional prices) are exact and not estimated. System-defined profile and foundation-model ARNs resolve through their last segment; application inference profile ARNs stay unpriced.

Long-context tiers are read as the data set writes them. The threshold comes from the key name (200K for Claude Sonnet 4/4.5, 272K for GPT-5.4 onwards, 128K for some older Gemini entries), together with the tier's cache prices. The tier is chosen by the request's whole input, cache reads and writes included, as Anthropic counts it. Previously only uncached input was counted, so a warm-cache 500K-token request was priced as a short one, and the 272K tier was not recognised at all.

Filled-in prices mark the cost estimated. When a price the table lacks is used, the cost is Estimated:

  • a 1-hour cache write with no 1-hour price: twice the input price (Anthropic's published multiplier). Before, it silently fell back to the 5-minute price, a 37.5% undercount of that part.
  • a long tier without its own cache prices: the flat cache prices grown by the tier's input ratio.

Price-sheet overrides are still taken exactly as written: an override's long tier keeps the cache prices written for it. PriceFields.input_above_200k / output_above_200k show only a 200K tier; a 272K tier is billed but not displayed there, because showing it as 200K would be wrong.

The config manual now says the 200K threshold counts cache reads and writes (docs regenerated).

Verification

  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, and cargo test --workspace (98 test binaries) all pass locally.
  • New tests: tier parsing against the built-in snapshot (Sonnet 4.5 at 200K with cache prices, GPT-5.5 at 272K, _priority keys ignored); the threshold counting cache; 1-hour and long-tier fill-ins marking estimates only when used; override long tiers taken as written; Bedrock borrowing order and version spellings; exact us. profile prices versus borrowed apac. ones; the recorder pricing by the served hop's rewritten model; the unpriced list naming the sent model; the gateway recording the rewritten model on the attempt, with no-op rewrites recorded as none.

Not handled here

OpenAI's priority and flex service tiers have their own prices in the data set. Pricing them needs the response's service_tier, which the gateway does not read yet.

🤖 Generated with Claude Code

Base automatically changed from feat/bedrock-upstream to main September 28, 2026 16:59
…e toward long context

- Record on each attempt the model a rule rewrote the request to
  (AttemptView.model) and price the request by the model the serving
  hop sent; the unpriced list names that model too, since it is the
  one a price has to be set for.
- Bedrock ids missing from the data set borrow a price, always marked
  estimated: an inference profile from the model it is named after,
  then Anthropic's own name for the model.
- Long-context tiers are read with their threshold from the data set
  (200K for Claude Sonnet 4/4.5, 272K for GPT-5.4 on), including their
  cache prices, and a request's input counts its cache reads and
  writes when choosing the tier.
- A price the table does not list is filled in and the cost marked
  estimated whenever it is used: a 1-hour cache write is twice the
  input price, a long tier's cache prices grow with its input price.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fylorn
fylorn force-pushed the feat/price-what-was-sent branch from fd365d9 to 031c44c Compare September 28, 2026 16:59
@fylorn
fylorn merged commit a0d8450 into main Sep 28, 2026
4 checks passed
@fylorn
fylorn deleted the feat/price-what-was-sent branch September 28, 2026 17:16
fylorn added a commit that referenced this pull request Sep 29, 2026
Minor release for #223, #224, #226, #227, #228, #229, #230 and #231,
and #222 before them.

- Bump the workspace version to 0.55.0
- release-notes/0.55.0.md

Control-plane protocol 28 (was 27): the protocol `bedrock`,
ProviderInput.aws / ProviderView.aws (AwsKeys), ProviderView.region,
ProviderPreview.region and AttemptView.model. The request store schema is
unchanged (22), so the request history is kept.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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