Repository navigation
[AISAGE-707] feat(admin): configure custom model pricing in the gateway admin panel - #7499
chrarnoldus wants to merge 8 commits into
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryThe incremental fixes now bill configured custom pricing through Assumptions: Files Reviewed (16 files)
Previous Review Summaries (7 snapshots, latest commit d31d3b6)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit d31d3b6)Status: 2 Issues Found | Recommendation: Address before merge Executive SummaryConfigured custom pricing is threaded through every lookup correctly, but blank (null) cache prices make gateway admission price input at twice the billed rate, and FIM, edit, embeddings and SystemOne still bill upstream cost while advertising the configured price. Assumptions: Overview
Issue Details (click to expand)WARNING
Files Reviewed (39 files)
Fix these issues in Kilo Cloud Previous review (commit ae13784)Status: 1 Issue Found | Recommendation: Address before merge Executive SummaryThe three follow-up fixes (fallback-only briefing bound, replica config read, in-flight save guards) check out, but configured pricing is still applied only to chat/transcription billing, so FIM, edit, embeddings and SystemOne paths can advertise configured prices they never bill. Assumptions: Overview
Issue Details (click to expand)WARNING
Files Reviewed (5 files)
Fix these issues in Kilo Cloud Previous review (commit 1cb9c7c)Status: 4 Issues Found | Recommendation: Address before merge Executive SummaryThe rebased admin custom-pricing feature is wired consistently through the catalog, endpoint API, spend admission, and chat billing, but configured pricing is not applied to FIM/edit/embeddings/SystemOne billing, the agent-briefing bound ignores fallback-only entries, and the new shared reader uses the primary database on pre-upstream gateway paths. Assumptions: Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (36 files)
Previous review (commit 8a92e9b)Status: No Issues Found | Recommendation: Merge Executive SummaryThe follow-up commit resolves all three earlier findings: the admin tab now refuses to render the editable form until the stored pricing loads, change detection compares fields in a fixed order, and the spend ceiling includes custom pricing for both the requested model ID and the alias target. Remaining incremental changes are tests and a two-argument call site update; no new issues found. Files Reviewed (6 files)
Note: Previous review (commit a1d5526)Status: 3 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (33 files)
Generated files ( Previous review (commit 8cb2f45)Status: No Issues Found | Recommendation: Merge Executive SummaryThe only changes attributable to this PR since the previous review are a regenerated Kilo MCP catalog entry ( Files Reviewed (2 files)
Previous review (commit fa77c2c)Status: 1 Issues Found | Recommendation: Address before merge Executive SummaryConfigured custom pricing is correctly validated and wired through billing, endpoints, and the org page, but the public model catalog applies it without honoring Overview
Issue Details (click to expand)WARNING
Files Reviewed (26 files)
Notes: Reviewed by deepseek-flash-latest · Input: 122K · Output: 34.7K · Cached: 3M Review guidance: REVIEW.md from base branch |
8a92e9b to
1cb9c7c
Compare
ae13784 to
d31d3b6
Compare
d31d3b6 to
7297587
Compare
1f9215c to
1a5c4b0
Compare
…ing and System One billing
Summary
ai_gateway_config.custom_pricingjsonb column (generated migration0305_custom_pricing).CustomPricingConfigSchemavalidates it: lowercase gateway model IDs, finite non-negative prices, an integer discount from 1 to 100, no duplicate models, at most 200 models. New admin tRPC router:admin.gatewayCustomPricing(get/set).getCustomPricing(modelId, configuredCustomPricing)returns the configured entry for a model if there is one. Otherwise it returns the built-incustomPricingByModelIdentry (currently Gemini 3.8 Flash and Gemini 4 Argon), which this PR does not change.getConfiguredCustomPricing(), a DB read cached for 60s, the same pattern as the Vercel model ID overrides. If the stored config is invalid, the last valid value is kept.applyUsagePricing, called byprocessTokenDataandrewriteUsage). FIM, edit, embedding and System One billing now go throughapplyUsagePricingtoo, so configured pricing applies to every billing path.applyCustomPricingToModel)applyCustomPricingToPricing)service_tierstripping (removeUnsupportedRequestServiceTier)pickerRequestPriceinenforceRequestCostLimit) and the agent briefing price bound (briefingPriceRates). For a~alias, the safeguard prices both the requested alias ID, which billing uses, and the target, so pricing configured for either raises the ceiling.models.customPricingreturns the configured map. The organization Providers & Models page passes it togetOfferingPricing.getConfiguredCustomPricing()reads throughreadDb, like the other gateway config getters.services/kilo-mcp/catalog.jsonincludes the newmodels.customPricingquery.Verification
pnpm --filter @kilocode/web-shared typecheck,pnpm --filter @kilocode/db typecheck,pnpm --filter ai-gateway typecheckand theapps/webtsgotypecheck all passed.main, theapps/webJest suites underpackages/web-shared/src/lib/ai-gateway/,src/lib/agent-briefing,src/components/organizations/providers-and-models,src/app/admin/gateway,src/routers/adminandsrc/routers/models-routerpassed against a local Postgres. The exception isextend-claw-trial-router.test.ts, whose one-year ceiling assertion is off by an hour around the DST change; it does not touch custom pricing.service_tierstrippingpackages/dbschema.test,migration-journalandschema-typestests passed.oxlintandoxfmton changed files are clean.Visual Changes
Adds a new "Custom Pricing" tab under Admin > Gateway. It is a form and a table, not a JSON editor. Each model gets prompt, completion and optional cache prices per 1M tokens, an optional discount shown in the model name, and a fallback-only flag. Built-in pricing is listed below with an "Overridden" badge when a configured entry replaces it.
No stored pricing
Saved pricing: a discounted model and a fallback-only model
Unsaved edit: the prompt price changed to $2.1, with Discard changes available
Reviewer Notes
main. The migration was regenerated on top ofmain's latest migration (0304), and it only adds thecustom_pricingcolumn.mainmoved billed-cost calculation intoapplyUsagePricing, which also rewrites the cost in responses. Configured pricing is passed to it explicitly;ResponseUsageContextcarries it for the response rewriters.mainreplacedtextRequestPriceCeilingwith picker-price admission (pickerRequestPrice) andbriefingPriceRates. The rebase passes configured pricing into both instead.