Repository navigation
Conversation
Kaiten now makes usage reports idempotent with a client key and keeps their history. - contracts/openapi.yaml is synced from the Kaiten release that adds them, and both generated clients are regenerated. - @kaitencloud/client: ReportUsageInput.transactionId. reportUsage marks a keyed report idempotent, so the transport retries it on network errors and 5xx under the same key; a report without a key is still sent once. A malformed key throws a TypeError before any request; the reused-key 409 throws TransactionIdReusedError (a KaitenError), never retried. - usage.reportDetailed / reportUsageDetailed also return replayed (Idempotent-Replayed) and metadataDropped (Kaiten-Metadata-Dropped); the transport gains runWithResponse to read them. - An API without transactionId refuses the field: the report is resent without it and the client stops sending keys for its lifetime, warning once. - usage.history / listUsageReports walks an instance's entitlement usage reports by afterSeq, with from, to, transactionId and a limit. - @kaitencloud/server: isTransactionIdReused, and the README shows the history operations and how to stream an export. Signed-off-by: Tom Ribuot <tom.ribuot@kaiten.sh>
This was referenced Oct 6, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR change?
The JS SDKs' side of two Kaiten features: idempotent usage reports (
transactionId) and the usage history. Server side: kaitencloud/kaiten#16; Go: kaitencloud/sdk-go#1.@kaitencloud/clientReportUsageInput.transactionId.reportUsagemarks a keyed report idempotent, so the transport retries it on network errors and 5xx, every attempt under the same key. A report without a key is still sent once: a failed request may have been counted.TransactionIdReusedError, aKaitenErrorwith the original report inerrors[0].value, never retried. A malformed key throws aTypeErrorbefore any request.usage.reportDetailed/reportUsageDetailedalso returnreplayed(Idempotent-Replayed) andmetadataDropped(Kaiten-Metadata-Dropped). The transport gainsrunWithResponseto read them;runis unchanged.transactionIdrefuses the field (the body is closed). The report is resent without it, and the client stops sending keys (and retrying reports) for its lifetime, warning once.usage.history/listUsageReports. An instance's entitlement usage reports, oldest first, following theafterSeqpages, withfrom,to,transactionIdand alimit.@kaitencloud/servertransactionIdto the usage report body, plusInstances.listUsageReports,exportUsageReportsandexportOrganizationUsageReports.isTransactionIdReusedsits besideisThresholdExceeded. The README shows the history operations and how to stream an export (parseAs: "stream").Why?
A usage report that timed out could not be retried safely, because it might count twice. A key makes the retry safe. The history lets a host show and keep what was counted.
Testing
vp checkand the affected packages' tests pass.vp run -r build && vp check && vp run -r test: client 179, server 35, examples/node 5. Bundle size and version invariants pass.New tests:
TransactionIdReusedErrorwith no retry. Malformed keys are refused with no request.body.transactionIdgives a resend without the key, later reports keyless, and one warning. A newer API'sInvalidTransactionIdis not mistaken for it.afterSeqwalk, the limit, andOutsideRetentionsurfacing with its code.isTransactionIdReusedis distinct from the threshold predicate, the history query, and a streamed CSV export.check:openapi-driftfails until the Kaiten release carrying these operations publishes@kaitencloud/openapi: the snapshot here is synced from that release's spec, ahead of the published one.Compatibility / migration impact
Additive.
reportUsagekeeps its signature and return type.KaitenUsageModulegainsreportDetailedandhistory, which matters only to code implementing that interface itself.KaitenClientLikeis unchanged. Keys need a Kaiten release withtransactionId; against an older one the client falls back as described above.Checklist
CONTRIBUTING.md.Signed-off-byline.material included in this PR.
information.
licenses and attributions.
are contributed under Apache-2.0.