feat(llmcost): alias request and response token types#3953
Conversation
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. 💤 Files selected but had no reviewable changes (1)
⛔ Files ignored due to path filters (5)
⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (5)
📒 Files selected for processing (1)
You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughAdds "request" and "response" as recognized LLM token-type aliases for "input" and "output" across specs, public constants, adapter pricing logic, and tests. No behavioral changes to pricing; only additional accepted token-type names and tests verifying mappings. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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.
🧹 Nitpick comments (1)
openmeter/productcatalog/feature/unitcost.go (1)
125-133: Consider centralizing token-type validity to avoid drift.Small maintainability nit:
Line 126-Line 133hard-codes the valid token set locally, while token handling is also encoded elsewhere (adapter switch). A shared helper keeps future additions safer.♻️ Refactor sketch
- if u.LLM.TokenType != "" { - validTypes := map[LLMTokenType]bool{ - LLMTokenTypeInput: true, LLMTokenTypeOutput: true, - LLMTokenTypeCacheRead: true, LLMTokenTypeReasoning: true, - LLMTokenTypeCacheWrite: true, - LLMTokenTypeRequest: true, LLMTokenTypeResponse: true, - } - if !validTypes[LLMTokenType(u.LLM.TokenType)] { - errs = append(errs, fmt.Errorf("invalid token_type %q: expected one of input, output, cache_read, reasoning, cache_write, request, response", u.LLM.TokenType)) - } - } + if u.LLM.TokenType != "" && !LLMTokenType(u.LLM.TokenType).IsValid() { + errs = append(errs, fmt.Errorf("invalid token_type %q: expected one of %s", u.LLM.TokenType, ValidLLMTokenTypesCSV())) + }// outside this block func (t LLMTokenType) IsValid() bool { /* centralized switch/set */ } func ValidLLMTokenTypesCSV() string { /* stable, shared message source */ }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@openmeter/productcatalog/feature/unitcost.go` around lines 125 - 133, Replace the hard-coded local valid-token set in the validation branch that checks u.LLM.TokenType with a centralized validator method on the LLMTokenType type (e.g., add LLMTokenType.IsValid()) and use a shared helper that returns the canonical CSV/string of allowed values (e.g., ValidLLMTokenTypesCSV()) for the error message; update the check to call LLMTokenType(u.LLM.TokenType).IsValid() and when appending the error to errs use ValidLLMTokenTypesCSV() instead of the inline list so token validity and the error text are defined in one place.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@openmeter/productcatalog/feature/unitcost.go`:
- Around line 125-133: Replace the hard-coded local valid-token set in the
validation branch that checks u.LLM.TokenType with a centralized validator
method on the LLMTokenType type (e.g., add LLMTokenType.IsValid()) and use a
shared helper that returns the canonical CSV/string of allowed values (e.g.,
ValidLLMTokenTypesCSV()) for the error message; update the check to call
LLMTokenType(u.LLM.TokenType).IsValid() and when appending the error to errs use
ValidLLMTokenTypesCSV() instead of the inline list so token validity and the
error text are defined in one place.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e403baf5-2ec6-4c2f-b39c-a4926cd3fa37
📒 Files selected for processing (4)
api/spec/packages/legacy/src/productcatalog/features.tspopenmeter/cost/adapter/compute.goopenmeter/cost/adapter/compute_test.goopenmeter/productcatalog/feature/unitcost.go
Summary by CodeRabbit
Validation
{ "data": [ { "cost": "0.27726", "currency": "USD", "dimensions": { "model": "gpt-4-turbo", "type": "response" }, "from": "2026-03-17T03:02:00Z", "to": "2026-03-17T03:04:00Z", "usage": "9242" }, { "cost": "0.088", "currency": "USD", "dimensions": { "model": "gpt-4o", "type": "response" }, "from": "2026-03-17T03:02:00Z", "to": "2026-03-17T03:04:00Z", "usage": "8800" }, { "cost": "0.08401", "currency": "USD", "dimensions": { "model": "gpt-4-turbo", "type": "request" }, "from": "2026-03-17T03:02:00Z", "to": "2026-03-17T03:05:00Z", "usage": "8401" }, { "cost": "0.0249425", "currency": "USD", "dimensions": { "model": "gpt-4o", "type": "request" }, "from": "2026-03-17T03:02:00Z", "to": "2026-03-17T03:05:00Z", "usage": "9977" } ] }