feat: credit pricing overhaul — per-model rates, margin, max cap#63
Merged
feat: credit pricing overhaul — per-model rates, margin, max cap#63
Conversation
…ax cap
Restructures llm_pricing.php from flat input/output ints to per-model
real rates ($USD/Mtok) with cache_read / cache_write_5m / cache_write_1h
tiers, context_window, last_verified_at, and tier-based reservation
multipliers (default 1.5 / nano 1.2 / heavy 2.0).
Real prices now reflect Jan 2026 reality:
- Opus 4.7 corrected to $5/$25 (was $15/$75 — 3× overpriced)
- Sonnet 4.6 confirmed $3/$15
- Haiku 4.5 corrected to $1/$5 (was $0.80/$4)
- GPT-5 added at $1.25/$10
- GPT-5 nano added at $0.05/$0.40 (was missing entirely)
- Gemini 2.5 Flash refreshed to $0.30/$2.50 (was $0.075/$0.30)
CostCalculator gains calculatePlatformCredits() returning structured
{platform_credits, raw_cost_usd, billable_cost_usd, margin_applied}
with cache_strategy parameter and per-call margin/max-cap overrides.
estimatePlatformCredits() uses model.tier reservation multiplier.
calculateCost() / estimateCost() back-compat preserved (BudgetEnforcement,
PrismAiGateway, SkillCostCalculator, ContextHealthService unchanged).
EnforceMaxCreditsPerCallAction wires into BudgetEnforcement middleware
to throw InsufficientBudgetException BEFORE the Prism call when team's
estimated cap would be exceeded — protects against runaway Opus calls.
Team gains effectiveMarginMultiplier() + effectiveMaxCreditsPerCall()
with config-default fallback (per-team override lives in cloud).
TeamSettingsPage adds "Billing & Per-Call Limits" section gated on
Schema::hasColumn so community edition gracefully hides cloud-only fields.
Non-LLM cost categories (compute / outbound / storage / tool) scaffolded
in config at usd_per_unit=0 — threaded through but not deducted yet.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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
Base companion to escapeboy/agent-fleet#36 (FleetQ-Cloud). Restructures llm_pricing.php from flat input/output integers to per-model real rates ($USD/Mtok), introduces margin/snapshot/max-cap primitives in CostCalculator, and wires the max-credits-per-call enforcement into BudgetEnforcement middleware.
What changes
Test plan
Cloud parent PR
escapeboy/agent-fleet#36