Skip to content

feat(api): credits API specification#3938

Merged
tothandras merged 1 commit into
mainfrom
feat/credits-api
Mar 24, 2026
Merged

feat(api): credits API specification#3938
tothandras merged 1 commit into
mainfrom
feat/credits-api

Conversation

@tothandras
Copy link
Copy Markdown
Contributor

@tothandras tothandras commented Mar 12, 2026

Summary by CodeRabbit

  • New Features

    • Full customer credits API: create, list, retrieve, void grants; update external settlement; list credit transactions.
    • Customer credit balances: view pending vs available credits per currency with retrieval timestamp.
    • Credit transaction ledger: view funding, consumption, expiration, voids, adjustments, and actors.
    • New paginated endpoints and query filters for grants, balances, and transactions.
  • Refactor

    • Money replaced by structured CurrencyAmount (amount + currency) for clearer billing representation.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

Adds a customer credits domain and API: new TypeSpec models/enums for credit grants, ledgers, balances, operations and endpoint interfaces wired into konnect/openmeter; shared schema updates (currency, resource references); and v3 server route stubs delegating to unimplemented handlers.

Changes

Cohort / File(s) Summary
Currency System
api/spec/packages/aip/src/currencies/currency.tsp
Added using TypeSpec.OpenAPI; and exported union CurrencyCode with OpenAPI metadata and Go type extension.
Credit Domain Models
api/spec/packages/aip/src/customers/credits/balance.tsp, api/spec/packages/aip/src/customers/credits/grant.tsp, api/spec/packages/aip/src/customers/credits/ledger.tsp
Added CreditBalances/CreditBalance; CreditGrant with enums (funding, availability, settlement, status), tax config, purchase/invoice/filters/priority/timestamps; and CreditTransaction, actor model and related enums.
Credit API Operations
api/spec/packages/aip/src/customers/credits/operations.tsp
Defined request filter models and operation interfaces for create/get/list credit grants, voiding, external settlement updates, getting balances, and listing transactions (includes pagination and deepObject filters).
Module Composition
api/spec/packages/aip/src/customers/credits/index.tsp, api/spec/packages/aip/src/customers/index.tsp
Added credits index and imported credits module into customers index.
Endpoint Routing
api/spec/packages/aip/src/konnect.tsp, api/spec/packages/aip/src/openmeter.tsp
Wired new customer credit endpoints (/openmeter/customers/{customerId}/credits/...): grants collection, per-grant routes with /void and /settlement/external, balance, and transactions, mapped to Customers operations.
Shared Utilities
api/spec/packages/aip/src/shared/properties.tsp, api/spec/packages/aip/src/shared/resource.tsp
Replaced Money alias with CurrencyAmount model; added Shared.ResourceImmutable and generic Shared.ResourceReference<T> (id: ULID).
Route Handlers
api/v3/server/routes.go
Added seven server route handler stubs (GetCustomerCreditBalance, ListCreditGrants, CreateCreditGrant, GetCreditGrant, VoidCreditGrant, UpdateCreditGrantExternalSettlement, ListCreditTransactions) delegating to unimplemented.* handlers.

Sequence Diagram(s)

sequenceDiagram
  participant Client as Client
  participant API as API Gateway
  participant Server as Server Handler
  participant DB as Billing DB

  Client->>API: HTTP POST /openmeter/customers/{id}/credits/grants (create)
  API->>Server: Route to CreateCreditGrant handler
  Server->>DB: Persist CreditGrant record
  DB-->>Server: Confirm saved
  Server-->>API: 201 Created (CreditGrant)
  API-->>Client: 201 Created (response)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

area/api, area/billing

Suggested reviewers

  • turip
  • GAlexIHU
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely describes the main addition: a new credits API specification with multiple endpoints and models for managing billing credits.
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
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/credits-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.

Comment thread api/spec/src/v3/customers/credits/credit.tsp Outdated
Comment thread api/spec/src/v3/customers/credits/credit.tsp Outdated
Comment thread api/spec/src/v3/customers/credits/credit.tsp Outdated
Comment thread api/spec/src/v3/customers/credits/credit.tsp Outdated
Comment thread api/spec/src/v3/customers/credits/credit.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/credit.tsp Outdated
Comment thread api/spec/src/v3/customers/credits/credit.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp
Comment thread api/spec/src/v3/customers/credits/credit.tsp Outdated
Comment thread api/spec/src/v3/customers/credits/credit.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp Outdated
Comment thread api/spec/src/v3/customers/credits/credit.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/credit.tsp Outdated
Comment thread api/spec/src/v3/customers/credits/credit.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp
Comment thread api/spec/src/v3/customers/credits/credit.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp
Comment thread api/spec/packages/aip/src/customers/credits/balance.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/balance.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/balance.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/balance.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp
Comment thread api/spec/packages/aip/src/customers/credits/operations.tsp
Comment thread api/spec/packages/aip/src/customers/credits/balance.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/ledger.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/operations.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/operations.tsp
Comment thread api/spec/packages/aip/src/customers/credits/operations.tsp
Comment thread api/spec/packages/aip/src/customers/credits/operations.tsp
Comment thread api/spec/packages/aip/src/customers/credits/balance.tsp
Comment thread api/spec/packages/aip/src/customers/credits/ledger.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/ledger.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp
Comment thread api/spec/packages/aip/src/customers/credits/ledger.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/ledger.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/operations.tsp
Comment thread api/spec/packages/aip/src/customers/credits/operations.tsp Outdated
@tothandras tothandras added the release-note/feature Release note: Exciting New Features label Mar 22, 2026
@tothandras tothandras changed the title feat(api): credits v3 [WIP] feat(api): credits API specification Mar 22, 2026
@tothandras tothandras marked this pull request as ready for review March 22, 2026 01:28
@tothandras tothandras requested a review from a team as a code owner March 22, 2026 01:28
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (6)
api/spec/packages/aip/src/currencies/currency.tsp (1)

31-39: Single-member union with commented-out variant.

The CurrencyCode union currently only contains Shared.CurrencyCode with CurrencyCodeCustom commented out. This works fine, but it might be worth adding a brief comment explaining whether this is intentional for now (future extensibility) or if it's a TODO. The @extension("x-go-type", "string") is a nice touch for clean Go codegen.

💡 Optional: Add a clarifying comment
 `@friendlyName`("BillingCurrencyCode")
 `@extension`("x-go-type", "string")
 union CurrencyCode {
   Shared.CurrencyCode,
-  // CurrencyCodeCustom,
+  // TODO: CurrencyCodeCustom will be added once custom currency support is complete
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/spec/packages/aip/src/currencies/currency.tsp` around lines 31 - 39, The
CurrencyCode union currently only contains Shared.CurrencyCode while
CurrencyCodeCustom is commented out; add a short clarifying comment or TODO in
the CurrencyCode union explaining that the single-member state is intentional
(for future extensibility) or re-enable/implement CurrencyCodeCustom if it was
accidentally left commented; reference the CurrencyCode union, the commented
CurrencyCodeCustom variant, and Shared.CurrencyCode (and keep the
`@extension`("x-go-type", "string") annotation) so reviewers know where to apply
the comment or change.
api/spec/packages/aip/src/customers/credits/operations.tsp (2)

184-205: Transaction listing looks solid.

Good design choices here:

  • Pagination support via Common.PagePaginationQuery
  • Deep-object filter for type, currency, and date range
  • Clear doc about reverse chronological ordering

One small thing: the from/to filters reference "created at" timestamps in the docs, but CreditTransaction has both created_at (inherited) and booked_at. Might be worth clarifying which timestamp the filter applies to.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/spec/packages/aip/src/customers/credits/operations.tsp` around lines 184
- 205, The filter docs reference "created at" but the API type CreditTransaction
exposes both created_at and booked_at, causing ambiguity for
ListCreditTransactionsParamsFilter consumers; update the doc on
CustomerCreditTransactionOperations.list (and/or
ListCreditTransactionsParamsFilter) to explicitly state whether the from/to date
range applies to CreditTransaction.created_at or CreditTransaction.booked_at,
and, if needed, rename or add a clarifying field (e.g.,
from_created_at/from_booked_at) in ListCreditTransactionsParamsFilter to avoid
ambiguity so callers know which timestamp the filter targets.

32-35: Same currency type inconsistency here.

Line 35 uses Shared.CurrencyCode while other filter models in this file (lines 135, 171) use Currencies.CurrencyCode. Might want to unify these for consistency across the credits API.

♻️ Align with other usages
   /**
    * Filter credit grants by currency.
    */
-  currency?: Shared.CurrencyCode;
+  currency?: Currencies.CurrencyCode;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/spec/packages/aip/src/customers/credits/operations.tsp` around lines 32 -
35, The currency filter property "currency?: Shared.CurrencyCode" is
inconsistent with other filters that use Currencies.CurrencyCode; change the
type to "currency?: Currencies.CurrencyCode" and update any imports or namespace
references so the Currencies namespace is available in this module (aligning the
credit filter model with the other models that use Currencies.CurrencyCode).
api/spec/packages/aip/src/customers/credits/ledger.tsp (1)

83-84: Consider narrowing what's inherited from Shared.Resource.

The CreditTransaction currently inherits name, description, and labels from Shared.Resource (you're only omitting updated_at and deleted_at). For an immutable ledger entry, having editable-looking fields like name and description seems off — users might expect they can set/update them, but that contradicts the immutability semantics.

You might want to either:

  1. Omit those fields too: OmitProperties<Shared.Resource, "updated_at" | "deleted_at" | "name" | "description" | "labels">
  2. Or cherry-pick just id and created_at from Resource instead
♻️ Suggested approach
 model CreditTransaction {
-  ...OmitProperties<Shared.Resource, "updated_at" | "deleted_at">;
+  ...OmitProperties<Shared.Resource, "updated_at" | "deleted_at" | "name" | "description" | "labels">;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/spec/packages/aip/src/customers/credits/ledger.tsp` around lines 83 - 84,
The CreditTransaction model currently inherits editable fields like name,
description, and labels from Shared.Resource via OmitProperties<Shared.Resource,
"updated_at" | "deleted_at"> which contradicts ledger immutability; update the
model definition (CreditTransaction) to either omit those additional mutable
fields (e.g., add "name" | "description" | "labels" to the OmitProperties list)
or replace the inheritance with a narrower pick of only immutable Resource
fields (e.g., only id and created_at) so the ledger entry exposes only immutable
properties.
api/spec/packages/aip/src/customers/credits/grant.tsp (2)

157-167: Consider enforcing the > 0 constraint if possible.

The doc mentions "The value must be greater than 0" but there's no @minValue or similar constraint decorator. Since Shared.Numeric is string-based, standard numeric decorators may not apply — just flagging it so validation happens server-side if TypeSpec can't enforce it.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/spec/packages/aip/src/customers/credits/grant.tsp` around lines 157 -
167, The doc says per_unit_cost_basis must be > 0 but there's no enforcement;
add validation for per_unit_cost_basis (the Shared.Numeric field) by either
applying a TypeSpec constraint decorator (e.g., add `@minValue`(0, exclusive=true)
to per_unit_cost_basis if supported) or, if TypeSpec decorators can't validate
string-based Shared.Numeric, validate it server-side where grant credits are
handled (parse per_unit_cost_basis to a number, ensure > 0, and return a clear
validation error). Ensure you update the code paths that consume
per_unit_cost_basis so invalid values are rejected before processing.

132-154: Inconsistent currency type references.

There's a small inconsistency here:

  • Line 136: currency: Currencies.CurrencyCode
  • Line 154: currency: Shared.CurrencyCode

If these resolve to the same type, consider using the same qualified name for consistency. If they're different types, double-check that Shared.CurrencyCode is the intended type for the purchase currency.

♻️ Make it consistent
     /**
      * Currency of the purchase amount.
      */
     `@visibility`(Lifecycle.Read, Lifecycle.Create)
-    currency: Shared.CurrencyCode;
+    currency: Currencies.CurrencyCode;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/spec/packages/aip/src/customers/credits/grant.tsp` around lines 132 -
154, The currency type is inconsistent between the top-level credit `currency:
Currencies.CurrencyCode` and the nested `purchase.currency:
Shared.CurrencyCode`; update the schema so both use the same qualified type
(pick either `Currencies.CurrencyCode` or `Shared.CurrencyCode`) or, if they are
intentionally different types, validate and rename the nested field to the
correct type; change the `currency` declaration inside the `purchase` object to
match the chosen type and run type checks to ensure no other references need
aligning.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@api/spec/packages/aip/src/currencies/currency.tsp`:
- Around line 31-39: The CurrencyCode union currently only contains
Shared.CurrencyCode while CurrencyCodeCustom is commented out; add a short
clarifying comment or TODO in the CurrencyCode union explaining that the
single-member state is intentional (for future extensibility) or
re-enable/implement CurrencyCodeCustom if it was accidentally left commented;
reference the CurrencyCode union, the commented CurrencyCodeCustom variant, and
Shared.CurrencyCode (and keep the `@extension`("x-go-type", "string") annotation)
so reviewers know where to apply the comment or change.

In `@api/spec/packages/aip/src/customers/credits/grant.tsp`:
- Around line 157-167: The doc says per_unit_cost_basis must be > 0 but there's
no enforcement; add validation for per_unit_cost_basis (the Shared.Numeric
field) by either applying a TypeSpec constraint decorator (e.g., add
`@minValue`(0, exclusive=true) to per_unit_cost_basis if supported) or, if
TypeSpec decorators can't validate string-based Shared.Numeric, validate it
server-side where grant credits are handled (parse per_unit_cost_basis to a
number, ensure > 0, and return a clear validation error). Ensure you update the
code paths that consume per_unit_cost_basis so invalid values are rejected
before processing.
- Around line 132-154: The currency type is inconsistent between the top-level
credit `currency: Currencies.CurrencyCode` and the nested `purchase.currency:
Shared.CurrencyCode`; update the schema so both use the same qualified type
(pick either `Currencies.CurrencyCode` or `Shared.CurrencyCode`) or, if they are
intentionally different types, validate and rename the nested field to the
correct type; change the `currency` declaration inside the `purchase` object to
match the chosen type and run type checks to ensure no other references need
aligning.

In `@api/spec/packages/aip/src/customers/credits/ledger.tsp`:
- Around line 83-84: The CreditTransaction model currently inherits editable
fields like name, description, and labels from Shared.Resource via
OmitProperties<Shared.Resource, "updated_at" | "deleted_at"> which contradicts
ledger immutability; update the model definition (CreditTransaction) to either
omit those additional mutable fields (e.g., add "name" | "description" |
"labels" to the OmitProperties list) or replace the inheritance with a narrower
pick of only immutable Resource fields (e.g., only id and created_at) so the
ledger entry exposes only immutable properties.

In `@api/spec/packages/aip/src/customers/credits/operations.tsp`:
- Around line 184-205: The filter docs reference "created at" but the API type
CreditTransaction exposes both created_at and booked_at, causing ambiguity for
ListCreditTransactionsParamsFilter consumers; update the doc on
CustomerCreditTransactionOperations.list (and/or
ListCreditTransactionsParamsFilter) to explicitly state whether the from/to date
range applies to CreditTransaction.created_at or CreditTransaction.booked_at,
and, if needed, rename or add a clarifying field (e.g.,
from_created_at/from_booked_at) in ListCreditTransactionsParamsFilter to avoid
ambiguity so callers know which timestamp the filter targets.
- Around line 32-35: The currency filter property "currency?:
Shared.CurrencyCode" is inconsistent with other filters that use
Currencies.CurrencyCode; change the type to "currency?: Currencies.CurrencyCode"
and update any imports or namespace references so the Currencies namespace is
available in this module (aligning the credit filter model with the other models
that use Currencies.CurrencyCode).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 75ae9333-560e-4a4b-92a9-9e52f4d738e7

📥 Commits

Reviewing files that changed from the base of the PR and between ef40371 and f745d80.

⛔ Files ignored due to path filters (1)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (13)
  • api/spec/packages/aip/src/currencies/currency.tsp
  • api/spec/packages/aip/src/customers/credits/balance.tsp
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/spec/packages/aip/src/customers/credits/index.tsp
  • api/spec/packages/aip/src/customers/credits/ledger.tsp
  • api/spec/packages/aip/src/customers/credits/operations.tsp
  • api/spec/packages/aip/src/customers/index.tsp
  • api/spec/packages/aip/src/konnect.tsp
  • api/spec/packages/aip/src/openmeter.tsp
  • api/spec/packages/aip/src/shared/properties.tsp
  • api/spec/packages/aip/src/shared/resource.tsp
  • api/v3/api.gen.go
  • api/v3/server/routes.go

Comment thread api/spec/packages/aip/src/customers/credits/operations.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/ledger.tsp Outdated
Comment thread api/spec/packages/aip/src/customers/credits/grant.tsp
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
api/spec/packages/aip/src/customers/credits/operations.tsp (2)

35-35: Inconsistent currency type references.

Line 35 uses Shared.CurrencyCode while lines 135 and 171 use Currencies.CurrencyCode. It'd be nice to keep these consistent across filter models for easier maintenance and a unified API surface.

♻️ Suggested fix
`@friendlyName`("GetCreditBalanceParamsFilter")
model GetCreditBalanceParamsFilter {
  /**
   * Filter credit balance by currency.
   */
-  currency?: Currencies.CurrencyCode;
+  currency?: Shared.CurrencyCode;

  /**
   * Filter by specific feature.
   */
  feature?: Shared.ResourceKey;
}

And similarly for ListCreditTransactionsParamsFilter:

-  currency?: Currencies.CurrencyCode;
+  currency?: Shared.CurrencyCode;

Also applies to: 135-135, 171-171

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/spec/packages/aip/src/customers/credits/operations.tsp` at line 35, The
currency type is referenced inconsistently across filter models (uses
Shared.CurrencyCode at currency?: Shared.CurrencyCode and
Currencies.CurrencyCode at other locations like in ListCreditsParamsFilter and
ListCreditTransactionsParamsFilter); standardize these by picking one canonical
alias (either Shared.CurrencyCode or Currencies.CurrencyCode) and update all
currency?: ... occurrences to use that single type name (update the type on the
property declarations in the ListCreditsParamsFilter,
ListCreditTransactionsParamsFilter and any other filter interfaces found in this
file so they all reference the same CurrencyCode symbol).

199-201: Placeholder noted.

This empty interface is clearly marked as TODO for future credit adjustment operations.

Would you like me to open an issue to track this work item?

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/spec/packages/aip/src/customers/credits/operations.tsp` around lines 199
- 201, The interface CustomerCreditAdjustmentOperations is an empty TODO
placeholder; replace this vague placeholder by either (A) implementing the
intended operations (add methods like createAdjustment, getAdjustment,
listAdjustments, voidAdjustment with appropriate signatures) inside
CustomerCreditAdjustmentOperations, or (B) if implementation is not ready, keep
the interface but add a clear JSDoc TODO that states the expected methods and
links to a tracking issue/ID (e.g., "TODO: implement credit adjustment
operations — issue `#1234`") so consumers know it's intentionally incomplete;
update the exported symbol CustomerCreditAdjustmentOperations accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@api/spec/packages/aip/src/customers/credits/operations.tsp`:
- Line 35: The currency type is referenced inconsistently across filter models
(uses Shared.CurrencyCode at currency?: Shared.CurrencyCode and
Currencies.CurrencyCode at other locations like in ListCreditsParamsFilter and
ListCreditTransactionsParamsFilter); standardize these by picking one canonical
alias (either Shared.CurrencyCode or Currencies.CurrencyCode) and update all
currency?: ... occurrences to use that single type name (update the type on the
property declarations in the ListCreditsParamsFilter,
ListCreditTransactionsParamsFilter and any other filter interfaces found in this
file so they all reference the same CurrencyCode symbol).
- Around line 199-201: The interface CustomerCreditAdjustmentOperations is an
empty TODO placeholder; replace this vague placeholder by either (A)
implementing the intended operations (add methods like createAdjustment,
getAdjustment, listAdjustments, voidAdjustment with appropriate signatures)
inside CustomerCreditAdjustmentOperations, or (B) if implementation is not
ready, keep the interface but add a clear JSDoc TODO that states the expected
methods and links to a tracking issue/ID (e.g., "TODO: implement credit
adjustment operations — issue `#1234`") so consumers know it's intentionally
incomplete; update the exported symbol CustomerCreditAdjustmentOperations
accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 99cf3527-b7e8-40d1-8345-a9aa6f8269da

📥 Commits

Reviewing files that changed from the base of the PR and between f745d80 and c71160a.

⛔ Files ignored due to path filters (1)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (13)
  • api/spec/packages/aip/src/currencies/currency.tsp
  • api/spec/packages/aip/src/customers/credits/balance.tsp
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/spec/packages/aip/src/customers/credits/index.tsp
  • api/spec/packages/aip/src/customers/credits/ledger.tsp
  • api/spec/packages/aip/src/customers/credits/operations.tsp
  • api/spec/packages/aip/src/customers/index.tsp
  • api/spec/packages/aip/src/konnect.tsp
  • api/spec/packages/aip/src/openmeter.tsp
  • api/spec/packages/aip/src/shared/properties.tsp
  • api/spec/packages/aip/src/shared/resource.tsp
  • api/v3/api.gen.go
  • api/v3/server/routes.go
✅ Files skipped from review due to trivial changes (4)
  • api/spec/packages/aip/src/customers/index.tsp
  • api/spec/packages/aip/src/customers/credits/index.tsp
  • api/spec/packages/aip/src/customers/credits/balance.tsp
  • api/spec/packages/aip/src/customers/credits/ledger.tsp
🚧 Files skipped from review as they are similar to previous changes (4)
  • api/spec/packages/aip/src/shared/properties.tsp
  • api/spec/packages/aip/src/currencies/currency.tsp
  • api/spec/packages/aip/src/shared/resource.tsp
  • api/spec/packages/aip/src/customers/credits/grant.tsp

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
api/spec/packages/aip/src/customers/credits/ledger.tsp (2)

86-90: Consider adding a doc note clarifying booked_at vs inherited created_at.

Since CreditTransaction extends ResourceImmutable (which includes created_at), both timestamps will be present. The distinction makes sense for ledger systems—created_at is record creation time, booked_at is the effective financial date—but a brief doc note could help API consumers understand when these might differ.

📝 Suggested doc enhancement
   /**
-   * The date and time the transaction was booked.
+   * The date and time the transaction was booked (effective date).
+   * This may differ from `created_at` when transactions are backdated or posted asynchronously.
    */
   `@visibility`(Lifecycle.Read)
   booked_at: Shared.DateTime;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/spec/packages/aip/src/customers/credits/ledger.tsp` around lines 86 - 90,
Add a short doc comment to clarify the difference between booked_at and the
inherited created_at on CreditTransaction: state that CreditTransaction (which
extends ResourceImmutable and therefore includes created_at) will include
created_at as the record insertion timestamp and booked_at as the
financial/effective booking timestamp (and note they may differ, e.g.,
retroactive bookings or delayed processing). Update the comment above the
booked_at field (and optionally add a one-line note near the CreditTransaction
type) referencing booked_at, created_at, CreditTransaction and ResourceImmutable
so API consumers understand the intended semantics.

32-33: TODO items to track for follow-up.

There are a few TODO comments in this file (lines 32, 58, 73) indicating open design questions. These are reasonable to defer, just flagging them for visibility.

Would you like me to open tracking issues for these TODOs, or are they already captured elsewhere?

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@api/spec/packages/aip/src/customers/credits/ledger.tsp` around lines 32 - 33,
There are lingering TODO comments (e.g., "TODO: add other types and do they have
additional metadata?") that mark unresolved design questions; create proper
tracked issues for each TODO (the one shown and the other two), link those issue
IDs back into the TODO comments or replace the inline TODO with a short note
referencing the issue, and if any are already captured elsewhere, update the
comment to reference the existing issue ID instead of leaving an open TODO so
reviewers can quickly find the decision history.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@api/spec/packages/aip/src/customers/credits/ledger.tsp`:
- Around line 86-90: Add a short doc comment to clarify the difference between
booked_at and the inherited created_at on CreditTransaction: state that
CreditTransaction (which extends ResourceImmutable and therefore includes
created_at) will include created_at as the record insertion timestamp and
booked_at as the financial/effective booking timestamp (and note they may
differ, e.g., retroactive bookings or delayed processing). Update the comment
above the booked_at field (and optionally add a one-line note near the
CreditTransaction type) referencing booked_at, created_at, CreditTransaction and
ResourceImmutable so API consumers understand the intended semantics.
- Around line 32-33: There are lingering TODO comments (e.g., "TODO: add other
types and do they have additional metadata?") that mark unresolved design
questions; create proper tracked issues for each TODO (the one shown and the
other two), link those issue IDs back into the TODO comments or replace the
inline TODO with a short note referencing the issue, and if any are already
captured elsewhere, update the comment to reference the existing issue ID
instead of leaving an open TODO so reviewers can quickly find the decision
history.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a35cfe75-8b08-4953-8135-ab53e6f56d94

📥 Commits

Reviewing files that changed from the base of the PR and between c71160a and 2133bac.

⛔ Files ignored due to path filters (1)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (13)
  • api/spec/packages/aip/src/currencies/currency.tsp
  • api/spec/packages/aip/src/customers/credits/balance.tsp
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/spec/packages/aip/src/customers/credits/index.tsp
  • api/spec/packages/aip/src/customers/credits/ledger.tsp
  • api/spec/packages/aip/src/customers/credits/operations.tsp
  • api/spec/packages/aip/src/customers/index.tsp
  • api/spec/packages/aip/src/konnect.tsp
  • api/spec/packages/aip/src/openmeter.tsp
  • api/spec/packages/aip/src/shared/properties.tsp
  • api/spec/packages/aip/src/shared/resource.tsp
  • api/v3/api.gen.go
  • api/v3/server/routes.go
✅ Files skipped from review due to trivial changes (3)
  • api/spec/packages/aip/src/customers/credits/index.tsp
  • api/spec/packages/aip/src/customers/index.tsp
  • api/spec/packages/aip/src/customers/credits/balance.tsp
🚧 Files skipped from review as they are similar to previous changes (5)
  • api/spec/packages/aip/src/shared/properties.tsp
  • api/spec/packages/aip/src/shared/resource.tsp
  • api/spec/packages/aip/src/openmeter.tsp
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/spec/packages/aip/src/customers/credits/operations.tsp

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/packages/aip/src/shared/resource.tsp`:
- Around line 77-83: The two generic models ResourceReference<T> and
ResourceWithKeyReference<T> share the same `@friendlyName`("{name}Reference", T)
which can cause codegen collisions; update the `@friendlyName` on one (or both) to
a distinct identifier (for example change ResourceWithKeyReference<T> to
`@friendlyName`("{name}WithKeyReference", T) or similar) so each model has a
unique friendly name while keeping the type parameter placeholder; locate the
decorators on ResourceReference and ResourceWithKeyReference and modify the
string templates accordingly to reflect their semantic difference (required id
vs optional id).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 821f4194-6a9f-421d-b2b6-0c9b2e48eea5

📥 Commits

Reviewing files that changed from the base of the PR and between 2133bac and f3d309f.

⛔ Files ignored due to path filters (1)
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (13)
  • api/spec/packages/aip/src/currencies/currency.tsp
  • api/spec/packages/aip/src/customers/credits/balance.tsp
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/spec/packages/aip/src/customers/credits/index.tsp
  • api/spec/packages/aip/src/customers/credits/ledger.tsp
  • api/spec/packages/aip/src/customers/credits/operations.tsp
  • api/spec/packages/aip/src/customers/index.tsp
  • api/spec/packages/aip/src/konnect.tsp
  • api/spec/packages/aip/src/openmeter.tsp
  • api/spec/packages/aip/src/shared/properties.tsp
  • api/spec/packages/aip/src/shared/resource.tsp
  • api/v3/api.gen.go
  • api/v3/server/routes.go
✅ Files skipped from review due to trivial changes (5)
  • api/spec/packages/aip/src/customers/credits/index.tsp
  • api/spec/packages/aip/src/customers/index.tsp
  • api/spec/packages/aip/src/customers/credits/ledger.tsp
  • api/spec/packages/aip/src/customers/credits/balance.tsp
  • api/spec/packages/aip/src/customers/credits/grant.tsp
🚧 Files skipped from review as they are similar to previous changes (5)
  • api/spec/packages/aip/src/shared/properties.tsp
  • api/spec/packages/aip/src/currencies/currency.tsp
  • api/spec/packages/aip/src/konnect.tsp
  • api/spec/packages/aip/src/openmeter.tsp
  • api/spec/packages/aip/src/customers/credits/operations.tsp

Comment thread api/spec/packages/aip/src/shared/resource.tsp
@tothandras tothandras merged commit 0fb6b3e into main Mar 24, 2026
25 checks passed
@tothandras tothandras deleted the feat/credits-api branch March 24, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/feature Release note: Exciting New Features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants