Repository navigation
feat(cost): add api - #3923
feat(cost): add api#3923
Conversation
📝 WalkthroughWalkthroughThis change adds per-feature unit cost models (manual and LLM-based), token-level pricing structures, cost query result models, and a new GET endpoint to query accumulated feature costs by featureId. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@api/spec/src/productcatalog/features.tsp`:
- Around line 75-82: The spec added unitCost to FeatureCreateInputs but the
backend struct and mapper don't include it; update the CreateFeatureInputs
struct (openmeter/productcatalog/feature/connector.go) to add a unitCost field
of type FeatureUnitCost (or equivalent internal type) and then propagate that
field in the MapFeatureCreateInputsRequest function
(openmeter/productcatalog/driver/parser.go) so incoming unitCost from the API is
assigned to the new struct field; ensure any type conversions or nullability are
handled the same way as other fields in CreateFeatureInputs.
- Around line 112-159: The schema currently documents but does not enforce
mutual exclusivity for provider/providerProperty, model/modelProperty, and
tokenType/tokenTypeProperty; replace each optional pair with a TypeSpec union
using `@oneOf`: define two models per pair (e.g., ProviderByProperty {
providerProperty: string; provider?: never } and ProviderByValue { provider:
string; providerProperty?: never }), then declare `@oneOf` union ProviderConfig =
ProviderByProperty | ProviderByValue and use ProviderConfig in place of the
separate provider/providerProperty fields; repeat the same pattern for model
(ModelByProperty/ModelByValue -> ModelConfig) and tokenType
(TokenTypeByProperty/TokenTypeByValue -> TokenTypeConfig) so the generated
OpenAPI emits oneOf and enforces XOR semantics.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 24bff588-9d75-41e4-858f-f4dd8e56b905
⛔ Files ignored due to path filters (11)
api/client/go/client.gen.gois excluded by!api/client/**api/client/javascript/src/client/schemas.tsis excluded by!api/client/**api/client/javascript/src/zod/index.tsis excluded by!api/client/**api/client/python/openmeter/_generated/aio/operations/_operations.pyis excluded by!**/_generated/**,!api/client/**api/client/python/openmeter/_generated/models/__init__.pyis excluded by!**/_generated/**,!api/client/**api/client/python/openmeter/_generated/models/_enums.pyis excluded by!**/_generated/**,!api/client/**api/client/python/openmeter/_generated/models/_models.pyis excluded by!**/_generated/**,!api/client/**api/client/python/openmeter/_generated/operations/_operations.pyis excluded by!**/_generated/**,!api/client/**api/client/python/openmeter/_types.pyis excluded by!api/client/**api/openapi.cloud.yamlis excluded by!**/openapi.cloud.yamlapi/openapi.yamlis excluded by!**/openapi.yaml
📒 Files selected for processing (3)
api/api.gen.goapi/spec/src/productcatalog/features.tspapi/spec/src/productcatalog/routes.tsp
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
openmeter/server/router/product_catalog.go (1)
33-34: Small typo in comment:feaure→featureTiny fix, but worth cleaning for readability. As per coding guidelines
**/*.go: “In general when reviewing the Golang code make readability and maintainability a priority, even potentially suggest restructuring the code to improve them.”🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/server/router/product_catalog.go` around lines 33 - 34, Fix the typo in the comment that reads "Query feaure cost" to "Query feature cost" in openmeter/server/router/product_catalog.go; update the comment above the handler for the GET /api/v1/features/{featureId}/cost route (the comment text containing "Query feaure cost") to improve readability and adhere to code style guidelines.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@openmeter/server/router/product_catalog.go`:
- Around line 35-38: The QueryFeatureCost method on type Router currently
forwards every request to unimplemented.QueryFeatureCost causing a 501; replace
this stub by wiring the endpoint to the real backend handler or gating the
route: locate the product catalog or cost service (e.g., a.ProductCatalog,
a.Service or similar) and call its QueryFeatureCost/GetFeatureCost method with
featureId and params, marshal the result to JSON and write a proper 200 response
(or return errors with appropriate status codes), or if the feature isn't ready,
remove/gate the route so it doesn't call unimplemented.QueryFeatureCost; ensure
to remove the unimplemented.QueryFeatureCost call and handle errors from the
backend call inside Router.QueryFeatureCost.
---
Nitpick comments:
In `@openmeter/server/router/product_catalog.go`:
- Around line 33-34: Fix the typo in the comment that reads "Query feaure cost"
to "Query feature cost" in openmeter/server/router/product_catalog.go; update
the comment above the handler for the GET /api/v1/features/{featureId}/cost
route (the comment text containing "Query feaure cost") to improve readability
and adhere to code style guidelines.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: c14f62a2-71cf-47f5-99af-6025ecde3426
📒 Files selected for processing (1)
openmeter/server/router/product_catalog.go
| * Use "manual" for a fixed per-unit cost, or "llm" to look up cost | ||
| * from the LLM cost database based on meter group-by properties. | ||
| */ | ||
| @summary("Unit cost") |
Summary by CodeRabbit