Repository navigation
fix(core): bill uncached input tokens in model pricing - #1500
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
| Layer / File(s) | Summary |
|---|---|
Merge split usage fields crates/core/src/observability/mod.rs, crates/core/tests/unit/observability/mod_tests.rs |
When usage includes uncached_input_tokens, merge_usage takes prompt and cache fields from that same usage. Tests cover both input orders. |
Price uncached input and select tiers crates/core/src/codec/model_pricing.rs, crates/core/tests/unit/codec/response_tests.rs, crates/core/tests/unit/codec/parity_tests.rs, crates/core/tests/unit/observability/exporter_parity_tests.rs, docs/configure-plugins/model-pricing.mdx, docs/integrate-into-frameworks/provider-response-codecs.mdx |
Cost estimation uses uncached input when reported and checks its consistency with prompt and cache counts. Cache reads and writes count toward rate-tier selection. Gemini tool-use input tokens are included in billing. Tests and documentation cover these behaviors and provider usage mappings. |
Reconstruct optimization baseline usage crates/core/src/api/optimization.rs, crates/core/tests/unit/optimization_tests.rs |
Baseline derivation uses saved prompt and cache tokens with the observed and API-specific input splits. Tests cover inconsistent or undetermined splits, missing prompt counts, and overflow. |
Priority:
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Bug fix
Merge Risk: 
Minimal · up to 532c3
-
No actionable pricing or usage-accounting issue remains identified; the change is ready for normal merge checks.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Description check
-
Explanation
The pull request description includes all required sections, completed contribution and duplication checks, detailed implementation scope, reviewer guidance, and a valid Relates to entry indicating that no issue is linked.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 2.13% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 47 functions across 8 files. (2 skipped: 2 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
- bill `uncached_input_tokens` at the input rate when usage reports it - leave usage unpriced when its input counts don't match - count cache reads and writes when picking a rate tier - keep uncached input in optimization baseline usage - take merged input counts from the source with `uncached_input_tokens` - test: split usage pricing, tier selection, baseline uncached input, merged usage Signed-off-by: Greyson Lalonde <[email protected]>
532c353 to
c312f75
Compare
Overview
Providers report cached input in different ways. This can cause a cost estimate to count tokens twice or miss some tokens.
This change makes cached-input pricing consistent. Relay bills each token group once. It does not estimate a cost when the reported counts conflict.
Details
For example, a request can have 1,000 uncached input tokens and 200 cached input tokens. Relay bills each group at its own rate and uses 1,200 tokens to select the pricing tier.
Where should the reviewer start?
Start with the cached-input pricing behavior. Check that Relay bills each token group once and uses the full input count to select a pricing tier. Then check that conflicting counts do not produce an estimate.
Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)
Summary by CodeRabbit