Repository navigation
Apply time-bound provider promotions to AI-credit accounting - #11771
Conversation
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Pinned promotion metadata allows withdrawn offers to keep discounting later request and WebSocket usage, potentially leaving usage free until the offer’s original expiry.
2 open issues
What changed in this PR
Adds time-bound Copilot promotions to AWF’s AI-credit accounting while preserving canonical rates and excluding operator and fallback pricing.
Changes:
- Validates promotion percentages and timestamps, including scheduled starts and exclusive expiry.
- Applies exact discounts to eligible provider-priced components after tier selection.
- Exposes advertised and applied promotion details in logs, usage records, and reflection.
| File | Description |
|---|---|
docs/api-proxy-sidecar.md |
Documents promotion accounting and audit metadata. |
containers/api-proxy/token-tracker-shared.js |
Persists structured promotion metadata in usage records. |
containers/api-proxy/token-budget-log.test.js |
Tests promotion metadata propagation and zero-credit logging. |
containers/api-proxy/token-budget-log.js |
Emits promotion details in logs and budget fields. |
containers/api-proxy/runtime-model-catalog.test.js |
Tests validation, timing boundaries, refreshes, and canonical rates. |
containers/api-proxy/runtime-model-catalog.js |
Validates promotions and exposes activity status and generated banners. |
containers/api-proxy/guards/pricing-resolution.test.js |
Updates discount accounting and budget expectations. |
containers/api-proxy/guards/ai-credits-guard.test.js |
Covers component discounts, pricing exclusions, expiry, and budgets. |
containers/api-proxy/guards/ai-credits-guard.js |
Applies exact discounts and records pricing provenance. |
Review effort: Max (adaptive)
|
|
||
| function getRuntimePricingFact(provider, model, catalog = runtimeCatalog) { | ||
| function getRuntimePromotion(provider, model, catalog = runtimeCatalog, options = {}) { | ||
| const promotion = normalizePromotion(findRuntimeModel(provider, model, catalog)?.promotion); |
| pricingObservedAt: pricingResolution.observedAt, | ||
| pricingApiVersion: pricingResolution.apiVersion, | ||
| pricingDiscountPercent: pricingResolution.discountPercent, | ||
| pricingDiscountPercent: promotion?.discountPercent, |
|
@copilot address review feedback |
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
| ...(promotion.startsAt !== undefined ? { starts_at: promotion.startsAt } : {}), | ||
| active: promotion.active, | ||
| applied: false, | ||
| banner: `${record.displayName || record.id}: ${promotion.discountPercent}% promotion ` + |
|
✅ Copilot review passed with no inline comments. @lpcox Add the |
Documentation PreviewDocumentation has been built for this PR. To view locally:
Built from commit fe12e56 |
|
@copilot merge main and resolve conflicts |
…und-model-promotions Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Merged |


Runtime promotions were visible in model metadata but absent from AI-credit charges, causing budgets to consume credits at list prices.
A 50% promotion halves eligible charges until—but not including—the expiry timestamp; a 100% promotion records zero credits.