Skip to content

feat: capture provider cost details with three-tier dispatch#443

Closed
harrisony wants to merge 0 commit into
mcowger:mainfrom
harrisony:main
Closed

feat: capture provider cost details with three-tier dispatch#443
harrisony wants to merge 0 commit into
mcowger:mainfrom
harrisony:main

Conversation

@harrisony
Copy link
Copy Markdown
Contributor

@harrisony harrisony commented May 20, 2026

Summary

  • fix: add upstream_inference_cost fallback for total cost so BYOK requests (where usage.cost=0) report the real spend
  • refactor: stop aliasing upstream_inference_prompt_costinput_cost; keep upstream fields separate since upstream_inference_prompt_cost = input_cost + cached_input_cost (aliasing silently zeroed out costCached)
  • feat: add three-tier cost dispatch in applyUsageCostDetails — superset (per-bucket gateway fields) → normal (upstream prompt/completions split with cache ratio) → minimal (proportional fallback)
  • test: expand coverage with edge cases — zero-cost non-BYOK, OpenRouter markup (cost >> upstream sum), zero prompt tokens, heavy-cache-hit ratio split, end-to-end BYOK and non-BYOK flows

Test plan

  • All 1378 backend tests pass (bun run test:force-all)
  • Biome lint clean (bunx biome lint .)
  • Each commit independently passes lint + tests (verified via git rebase --exec)

🤖 Generated with Claude Code

@harrisony harrisony marked this pull request as draft May 22, 2026 06:38
@harrisony harrisony closed this May 22, 2026
mcowger added a commit that referenced this pull request May 24, 2026
## Summary

- **fix**: add `upstream_inference_cost` fallback for total cost so BYOK
requests (where `usage.cost=0`) report the real spend
- **refactor**: stop aliasing `upstream_inference_prompt_cost` →
`input_cost`; keep upstream fields separate since
`upstream_inference_prompt_cost = input_cost + cached_input_cost`
(aliasing silently zeroed out `costCached`)
- **feat**: add three-tier cost dispatch in `applyUsageCostDetails` —
superset (per-bucket gateway fields) → normal (upstream
prompt/completions split with cache ratio) → minimal (proportional
fallback)
- **test**: expand coverage with edge cases — zero-cost non-BYOK,
OpenRouter markup (cost >> upstream sum), zero prompt tokens,
heavy-cache-hit ratio split, end-to-end BYOK and non-BYOK flows

## Test plan

- [x] All 1378 backend tests pass (`bun run test:force-all`)
- [x] Biome lint clean (`bunx biome lint .`)
- [x] Each commit independently passes lint + tests (verified via `git
rebase --exec`)

> **Note:** I mixed up the branches in #443, and also mixed up #520.
That PR couldn't be reopened due to a force-push. This replaces that PR.

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Matt Cowger <mcowger@users.noreply.github.com>
Co-authored-by: Matt Cowger <matt@cowger.us>
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