[PR #6900] [management, proxy] Add prompt-cache token and cost accounting to agent network usage #30011

Closed
opened 2026-08-05 08:09:41 -04:00 by saavagebueno · 0 comments
Owner

Original Pull Request: https://github.com/netbirdio/netbird/pull/6900

State: closed
Merged: Yes


Describe your changes

Bedrock Converse responses report prompt-cache usage in camelCase fields (cacheReadInputTokens/cacheWriteInputTokens) the proxy didn't parse, so cached Converse requests were under-billed. This fixes the parsing and makes cache accounting first-class: the cost meter emits the cache portion of each request's cost (cost.usd_cache), and cached_input_tokens, cache_creation_tokens, and cache_cost_usd are persisted in the agent-network access-log and request-usage tables and exposed in the REST API (entries, sessions, usage buckets), so cache-write-heavy requests are explainable instead of hiding inside total_tokens.

N/A

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — OR I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See CONTRIBUTING.md.

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/886

Summary by CodeRabbit

  • New Features

    • Added prompt-cache token counts and a full cost breakdown (input, cached-input, cache-creation, output) plus cache-attributed totals across access logs, sessions, and usage summaries.
    • Updated Bedrock/Converse parsing and streaming to include cache token fields.
    • Extended cost reporting metadata to include per-component USD values and cost.usd_cache; updated request token limits for e2e chat.
    • Added optional Bedrock model override for e2e workflow runs.
  • Migration

    • Migrates legacy aggregate cost data into the new per-bucket cost format while preserving historical totals.
  • Bug Fixes

    • Improved pricing, cost aggregation, and cost computation accuracy across providers.
**Original Pull Request:** https://github.com/netbirdio/netbird/pull/6900 **State:** closed **Merged:** Yes --- ## Describe your changes Bedrock Converse responses report prompt-cache usage in camelCase fields (`cacheReadInputTokens`/`cacheWriteInputTokens`) the proxy didn't parse, so cached Converse requests were under-billed. This fixes the parsing and makes cache accounting first-class: the cost meter emits the cache portion of each request's cost (`cost.usd_cache`), and `cached_input_tokens`, `cache_creation_tokens`, and `cache_cost_usd` are persisted in the agent-network access-log and request-usage tables and exposed in the REST API (entries, sessions, usage buckets), so cache-write-heavy requests are explainable instead of hiding inside `total_tokens`. ## Issue ticket number and link N/A ## Stack <!-- branch-stack --> ### Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [ ] It is a refactor - [x] Created tests that fail without the change (if possible) - [x] This change does **not** modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — **OR** I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See [CONTRIBUTING.md](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTING.md#discuss-changes-with-the-netbird-team-first). > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [x] I added/updated documentation for this change - [ ] Documentation is **not needed** for this change (explain why) ### Docs PR URL (required if "docs added" is checked) Paste the PR link from https://github.com/netbirdio/docs here: https://github.com/netbirdio/docs/pull/886 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added prompt-cache token counts and a full cost breakdown (input, cached-input, cache-creation, output) plus cache-attributed totals across access logs, sessions, and usage summaries. * Updated Bedrock/Converse parsing and streaming to include cache token fields. * Extended cost reporting metadata to include per-component USD values and `cost.usd_cache`; updated request token limits for e2e chat. * Added optional Bedrock model override for e2e workflow runs. * **Migration** * Migrates legacy aggregate cost data into the new per-bucket cost format while preserving historical totals. * **Bug Fixes** * Improved pricing, cost aggregation, and cost computation accuracy across providers. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
saavagebueno added the pull-request label 2026-08-05 08:09:41 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#30011