Skip to content

feat(server-ai): stamp modelKey and modelVersion on AI usage events (AIC-2858)#1794

Merged
atornsii merged 3 commits into
mainfrom
atornsii/AIC-2858/add-support-for-model-key-version
Jul 22, 2026
Merged

feat(server-ai): stamp modelKey and modelVersion on AI usage events (AIC-2858)#1794
atornsii merged 3 commits into
mainfrom
atornsii/AIC-2858/add-support-for-model-key-version

Conversation

@atornsii

@atornsii atornsii commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

  • AIC-2858 — Make Changes to Node.js
  • Parent: AIC-2849 — Add modelKey and modelVersion as fields to be read by SDK
  • Depends on backend payload work: AIC-2876
  • Mirrors Go: AIC-2850 / Python: PR #208

Describe the solution you've provided

Read modelKey and modelVersion from the AI Config variation payload (variation.model) and stamp them on all LDAIConfigTracker metric event payloads, alongside existing modelName/providerName fields.

  • Add optional modelKey/modelVersion to LDModelConfig
  • Pass the new fields into LDAIConfigTrackerImpl from LDAIClientImpl._evaluate
  • Include modelVersion (always) and modelKey (when present) in getTrackData()
  • Default modelVersion to 1 when absent; exclude both fields from the resumption token
  • Additive/backward compatible — older payloads without the new fields continue to work

Describe alternatives you've considered

None — this mirrors the established pattern from the Go and Python SDK implementations.

Additional context

Tech spec: Models Primitive Improvements

Test plan

  • yarn workspace @launchdarkly/server-sdk-ai test (241 passed)
  • yarn workspace @launchdarkly/server-sdk-ai lint
  • yarn workspaces foreach -pR --topological-dev --from '@launchdarkly/server-sdk-ai' run build
  • Verify against a staging environment once AIC-2876 payload is available
Open in Web Open in Cursor 

…AIC-2858)

Read modelKey and modelVersion from the AI Config variation payload and
stamp them on emitted metric events alongside existing modelName and
providerName fields. Default modelVersion to 1 when absent and exclude
both fields from the resumption token. Additive and backward compatible.

Co-authored-by: Anthony Torns II <atornsii@users.noreply.github.com>
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@launchdarkly/js-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 26365 bytes
Compressed size limit: 29000
Uncompressed size: 129044 bytes

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk-common size report
This is the brotli compressed size of the ESM build.
Compressed size: 38887 bytes
Compressed size limit: 39000
Uncompressed size: 212703 bytes

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@launchdarkly/js-client-sdk size report
This is the brotli compressed size of the ESM build.
Compressed size: 32006 bytes
Compressed size limit: 34000
Uncompressed size: 114336 bytes

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@launchdarkly/browser size report
This is the brotli compressed size of the ESM build.
Compressed size: 179727 bytes
Compressed size limit: 200000
Uncompressed size: 831515 bytes

@jsonbailey

Copy link
Copy Markdown
Contributor

Holding based on our conversation today and we will follow up on slack before reviewing.

@atornsii
atornsii marked this pull request as ready for review July 9, 2026 20:32
@atornsii
atornsii requested a review from a team as a code owner July 9, 2026 20:32
joker23
joker23 previously approved these changes Jul 10, 2026
@atornsii
atornsii marked this pull request as draft July 15, 2026 21:36
Gonfalon moved these two fields from the payload's model object to
_ldMeta (launchdarkly/gonfalon#67230) to avoid modelVersion reading as
the underlying LLM's own version. Field names are unchanged; only the
JSON location moves.

_toBaseConfig now merges modelKey/modelVersion from _ldMeta onto the
exposed model object (previously a direct passthrough of flagValue.model,
which no longer carries them), only setting them when actually present
so config.model's shape is unchanged when they're absent. The tracker's
own default-to-1 fallback for stamped events is untouched.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@atornsii
atornsii marked this pull request as ready for review July 16, 2026 16:55

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8ad1db9. Configure here.

Comment thread packages/sdk/server-ai/src/LDAIClientImpl.ts
Comment thread packages/sdk/server-ai/src/api/config/LDAIConfigUtils.ts Outdated
@joker23
joker23 self-requested a review July 16, 2026 17:22
@joker23
joker23 dismissed their stale review July 16, 2026 17:22

dismissing because approval is old

modelKey/modelVersion should only be visible via the tracker's
stamped event data, mirroring how variationKey/version are treated.
LDAIClientImpl already sourced them from _ldMeta directly for the
tracker factory, so only the model reconstruction in _toBaseConfig
needed to stop merging them onto the public model object.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@atornsii
atornsii merged commit a91a1e7 into main Jul 22, 2026
56 of 60 checks passed
@atornsii
atornsii deleted the atornsii/AIC-2858/add-support-for-model-key-version branch July 22, 2026 22:47
@github-actions github-actions Bot mentioned this pull request Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants