mirror of
https://github.com/coder/coder.git
synced 2026-08-31 01:03:45 +08:00
2d9b6eda8f
## Description AI Gateway computes the cost of an interception from `ai_model_prices`, which is seeded on every server start from a price book embedded in the binary. A model the price book does not cover records a NULL cost, so its spend is invisible to cost reporting and is not enforced against budgets. The only fix was to wait for a Coder release that added the model. This adds an experimental CLI, backed by an experimental HTTP endpoint, for pricing those models. Models the price book already covers are rejected, because the seeder re-applies the book on every start and would overwrite an operator price. Support for custom pricing will be handled in https://linear.app/codercom/issue/AIGOV-589/extend-experimental-cli-command-to-set-custom-ai-model-prices. ## Commands ``` coder exp ai-model-prices list [--provider] [--model] coder exp ai-model-prices update [file|-] [--provider] [--model] [--input-price] [--output-price] [--cache-read-price] [--cache-write-price] [--yes] ``` ## Changes - Add `GET` and `POST /api/experimental/ai/model-prices`, gated behind the AI Bridge entitlement and the existing `ai_model_price` RBAC resource. - Add a `GetAIModelPrices` query with optional `provider` and `model` filters applied in SQL. - Validate the whole request before writing anything, so one bad entry cannot leave the table half updated, and report every problem at once. - Reject prices for models the embedded price book already covers, through a new `prices.IsDefaultPriced`. - Add the `coder exp ai-model-prices` command with `list` and `update`. `update` accepts a JSON document or the single-model flags and prints a plan, asking to confirm unless the document is piped in or `--yes` is passed. - Consolidate the supported provider list into `coderd/aibridge/prices/providers` so the price generator and the server share one definition. - Add `codersdk` types and client methods for both endpoints, and bound the request body at 1 MiB. - Document the command in the AI Gateway cost controls page. Closes https://linear.app/codercom/issue/AIGOV-567/experimental-cli-command-to-set-prices-for-unpriced-ai-models > [!NOTE] > Initially generated by Claude Opus 5, modified and reviewed by @ssncferreira
44 lines
951 B
Go
44 lines
951 B
Go
package cli
|
|
|
|
import (
|
|
agplcli "github.com/coder/coder/v2/cli"
|
|
"github.com/coder/serpent"
|
|
)
|
|
|
|
type RootCmd struct {
|
|
agplcli.RootCmd
|
|
}
|
|
|
|
func (r *RootCmd) enterpriseOnly() []*serpent.Command {
|
|
return []*serpent.Command{
|
|
// These commands exist in AGPL, but we use a different implementation
|
|
// in enterprise:
|
|
r.Server(nil),
|
|
r.provisionerDaemons(),
|
|
agplcli.ExperimentalCommand(append(r.AGPLExperimental(), r.enterpriseExperimental()...)),
|
|
|
|
// New commands that don't exist in AGPL:
|
|
r.aiGateway(),
|
|
r.agentFirewall(),
|
|
r.boundaryAlias(),
|
|
r.workspaceProxy(),
|
|
r.features(),
|
|
r.licenses(),
|
|
r.groups(),
|
|
r.prebuilds(),
|
|
r.provisionerd(),
|
|
r.externalWorkspaces(),
|
|
}
|
|
}
|
|
|
|
func (r *RootCmd) enterpriseExperimental() []*serpent.Command {
|
|
return []*serpent.Command{
|
|
r.aiModelPricesCommand(),
|
|
}
|
|
}
|
|
|
|
func (r *RootCmd) EnterpriseSubcommands() []*serpent.Command {
|
|
all := append(r.CoreSubcommands(), r.enterpriseOnly()...)
|
|
return all
|
|
}
|