Identify CLI via X-Api-Client header for backend usage tracking#35
Merged
Conversation
The JS SDK sends X-Api-Client: bitmovin-api-sdk-javascript on every request, making CLI traffic indistinguishable from generic SDK usage. Override it with bitmovin-cli plus the CLI version (read from package.json) on both the API-key and OAuth client paths. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
webzherd
approved these changes
Jul 8, 2026
webzherd
left a comment
Contributor
There was a problem hiding this comment.
LGTM — verified the core assumptions locally: the SDK's HeaderHandler merges constructor headers over its defaults (RestClient.js), the createRequire path to package.json resolves correctly from both src/ and dist/, and getClient is the only SDK construction site so both auth paths cover all API traffic. Built the branch and ran the full suite in a clean worktree: 193/193 passing.
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.
Why
CLI requests currently arrive at the backend as
X-Api-Client: bitmovin-api-sdk-javascript(the JS SDK default), so CLI usage is indistinguishable from any other JS SDK integration. Overriding the client identification lets us measure CLI adoption in the existing per-client usage metrics — just filter/group byX-Api-Client = bitmovin-cli. No backend change needed.What
src/lib/client.ts: passX-Api-Client: bitmovin-cliandX-Api-Client-Version: <CLI version>to the SDK constructor on both auth paths (API key and OAuth Bearer). The SDK'sHeaderHandlermerges constructor headers over its defaults, so no fetch wrapping is needed. The version is read frompackage.jsonviacreateRequire, so it stays correct on every release.test/lib/client.test.tsandtest/lib/client-bearer.test.ts.Verification
Ran the SDK with a capturing fetch using the exact config
getClientbuilds; both auth paths emit the new headers on the wire:All 193 tests pass.
🤖 Generated with Claude Code