Skip to content

feat(cost): add api - #3923

Merged
hekike merged 2 commits into
mainfrom
feat/cost-api
Mar 5, 2026
Merged

hekike merged 2 commits into
mainfrom
feat/cost-api

Conversation

@hekike

@hekike hekike commented Mar 4, 2026 •

Copy link
Copy Markdown
Contributor
  • Add feature cost properties
  • Add feature cost analytics api

Summary by CodeRabbit

  • New Features
    • Per-feature cost configuration: supports fixed (manual) pricing and LLM-based per-token pricing with resolved per-token rates.
    • New cost query endpoint: fetch time-windowed usage metrics, aggregated and per-row cost results, currency, and related metadata for a feature.

@hekike
hekike requested a review from a team as a code owner March 4, 2026 23:05
@hekike hekike added the release-note/ignore Ignore this change when generating release notes label Mar 4, 2026
@coderabbitai

coderabbitai Bot commented Mar 4, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Cost models & query types
api/spec/src/productcatalog/features.tsp
Adds FeatureUnitCost union (manual, llm), FeatureManualUnitCost, FeatureLLMUnitCost, FeatureLLMUnitCostPricing, FeatureCostQueryRow, FeatureCostQueryResult, and exposes FeatureCreateInputs.unitCost.
API route
api/spec/src/productcatalog/routes.tsp
Adds queryFeatureCost GET operation on /{featureId}/cost returning FeatureCostQueryResult (or errors).
Router handler stub
openmeter/server/router/product_catalog.go
Adds Router.QueryFeatureCost HTTP handler method that delegates to an unimplemented backend handler (stubbed, no business logic yet).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

release-note/misc

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'feat(cost): add api' is vague and doesn't clearly convey what specific API or cost feature is being added. Consider a more descriptive title like 'feat(cost): add feature cost query API' to better explain the main change—adding a new endpoint for querying feature costs with LLM-based and manual pricing support.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/cost-api

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between dc7ec59 and f540a0c.

⛔ Files ignored due to path filters (11)
  • api/client/go/client.gen.go is excluded by !api/client/**
  • api/client/javascript/src/client/schemas.ts is excluded by !api/client/**
  • api/client/javascript/src/zod/index.ts is excluded by !api/client/**
  • api/client/python/openmeter/_generated/aio/operations/_operations.py is excluded by !**/_generated/**, !api/client/**
  • api/client/python/openmeter/_generated/models/__init__.py is excluded by !**/_generated/**, !api/client/**
  • api/client/python/openmeter/_generated/models/_enums.py is excluded by !**/_generated/**, !api/client/**
  • api/client/python/openmeter/_generated/models/_models.py is excluded by !**/_generated/**, !api/client/**
  • api/client/python/openmeter/_generated/operations/_operations.py is excluded by !**/_generated/**, !api/client/**
  • api/client/python/openmeter/_types.py is excluded by !api/client/**
  • api/openapi.cloud.yaml is excluded by !**/openapi.cloud.yaml
  • api/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (3)
  • api/api.gen.go
  • api/spec/src/productcatalog/features.tsp
  • api/spec/src/productcatalog/routes.tsp

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
openmeter/server/router/product_catalog.go (1)

33-34: Small typo in comment: feaure → feature

Tiny 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

📥 Commits

Reviewing files that changed from the base of the PR and between f540a0c and dc03cf3.

📒 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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing visibility

@hekike
hekike merged commit 92db110 into main Mar 5, 2026
26 checks passed
@hekike
hekike deleted the feat/cost-api branch March 5, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/ignore Ignore this change when generating release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants