Repository navigation
Conversation
This was referenced Oct 13, 2026
Collaborator
Author
Collaborator
Author
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Adds organization-scoped AI model prices as an overlay on the site-wide price catalog, so the same model can be priced differently per organization, either for every provider of a type or for one configured provider. Pricing one configured provider is the only way to price
openai-compatgateways such as LiteLLM routing to Bedrock.Token usage is priced by the most specific match: the organization's price for the configured provider, then its price for the provider type, then a site-wide custom price, then the price book. The requested model is still preferred over the model the provider reports. Each token usage record now stores which kind of price matched and its keys (
price_kind,price_organization_id,price_provider_id,price_provider). These are stored only, not exposed in the API.New experimental, AI Gateway licensed routes are
GET,POSTandDELETEon/api/experimental/organizations/{organization}/ai/model-prices, authorized againstResourceAiModelPrice.InOrg(org), so only owners and org admins can use them. The site-wide routes are unchanged.Interceptions don't carry an organization yet, so the lookup passes none and only site-wide prices apply at runtime for now. Org matching is covered by database tests with explicit org IDs. The migration (
000621) only adds tables, an enum and nullable columns, and needs no backfill.Closes AIGOV-612. Replaces #30396.
Known issue:
GetUnpricedAIModelsSincenow counts a model as priced when any organization has a provider-ID price for it. Org prices aren't applied at runtime yet, so such a model can drop out of the unpriced-models report while its usage still records a NULL cost.Design and decisions (from AIGOV-612)
Kinds of price, in lookup order, most specific first:
ai_org_provider_model_prices, primary key(organization_id, provider_id, model). The provider type comes fromai_providers.ai_org_model_prices, primary key(organization_id, provider, model), withCHECK (provider <> 'openai-compat').ai_model_prices, unchanged.ai_model_prices, unchanged.Decisions
openai-compatprices stay rejected, because each gateway can route to a different upstream. Allowing them later would be additive.organizationsandai_providersuseON DELETE CASCADE. Prices for soft-deleted providers are never matched and are hidden by the API.UNION ALLquery of primary-key lookups, ordered first by whether the row is for the requested model, then by kind. Theai_model_price_kindenum is declared most specific first.POSTreturning204, which thecoderd_ai_model_priceTerraform resource depends on.providerorprovider_id; aprovider_idmust be a live provider, and aprovidergiven alongside it must match its type. Invalid entries, duplicate keys and blanketopenai-compatprices return400, and nothing is written.GETon the org route returns every price that applies to the org. By default it lists effective prices, so an org type price hides the matching site-wide prices.source=alllists every row. Each row shows itsscope.DELETEtakesprovider_idorprovider, plusmodel, in the query string, because model names can contain slashes. There is no surrogate ID for now.Out of scope: the UI (AIGOV-699), Terraform support for org prices (AIGOV-710), and passing the organization from interceptions into the lookup, which depends on org context work.
This PR was generated by Coder Agents on behalf of @SasSwart.