F-sdk-cost-estimate: Pre-request cost estimation#10
Merged
Conversation
…timation Add a simplified convenience wrapper around estimateEventCost() that: - Accepts minimal params (provider, model, token counts) - Returns structured CostEstimate breakdown (input/output/tool costs) - Supports API-fetched pricing via refreshPricing() with 24h cache - Falls back to BUNDLED_PRICES when offline Includes toolCostUsd field for complete breakdown when webSearchCount > 0. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
Author
Sentinel Code Review — APPROVEDAll checks passed. Security, quality, and documentation verified. Implementation CompletenessAll 5 deliverables verified:
Security
Quality
Regression CheckPatterns #1-#11: no matches. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
estimateCost()synchronous convenience wrapper for pre-request cost estimationrefreshPricing()async function for fetching live prices from AISpendGuard API with 24h cacheCostEstimateandCostEstimateInputtypes with structured breakdown (input/output/tool costs)Task
Task file:
aispendguard-tasks/active/features/F-sdk-cost-estimate.mdChanges
src/types.ts— AddedCostEstimateandCostEstimateInputtype definitionssrc/pricing.ts— AddedestimateCost(),refreshPricing(), API price cache with 24h TTLsrc/index.ts— Exported new functions and typestests/pricing.test.mjs— 6 new tests: structured breakdown, unknown model, batch mode, cached tokens, custom pricing, web search feesREADME.md— Added cost estimation example and API entriesImplementation Coverage
CostEstimateandCostEstimateInputadded tosrc/types.tsestimateCost()andrefreshPricing()added tosrc/pricing.tssrc/index.tstests/pricing.test.mjsSentinel Notes Addressed
toolCostUsdfield toCostEstimatefor complete breakdownjson.models ?? []for defensive parsing inrefreshPricing()estimateCostto existing destructuring on L6 of test fileTesting
npm run buildpassesnpm testpasses (64 pass, 0 fail, 1 skip)Documentation