Skip to content

Identify CLI via X-Api-Client header for backend usage tracking#35

Merged
lukaskroepfl merged 1 commit into
mainfrom
feat/cli-api-client-header
Jul 8, 2026
Merged

Identify CLI via X-Api-Client header for backend usage tracking#35
lukaskroepfl merged 1 commit into
mainfrom
feat/cli-api-client-header

Conversation

@lukaskroepfl

Copy link
Copy Markdown
Member

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 by X-Api-Client = bitmovin-cli. No backend change needed.

What

  • src/lib/client.ts: pass X-Api-Client: bitmovin-cli and X-Api-Client-Version: <CLI version> to the SDK constructor on both auth paths (API key and OAuth Bearer). The SDK's HeaderHandler merges constructor headers over its defaults, so no fetch wrapping is needed. The version is read from package.json via createRequire, so it stays correct on every release.
  • Regression tests in test/lib/client.test.ts and test/lib/client-bearer.test.ts.

Verification

Ran the SDK with a capturing fetch using the exact config getClient builds; both auth paths emit the new headers on the wire:

{"X-Api-Key":"test-key","X-Api-Client":"bitmovin-cli","X-Api-Client-Version":"0.4.0",...}
{"X-Api-Key":"","X-Api-Client":"bitmovin-cli","X-Api-Client-Version":"0.4.0",...,"Authorization":"Bearer tok"}

All 193 tests pass.

🤖 Generated with Claude Code

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 webzherd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@lukaskroepfl lukaskroepfl merged commit e0ac7d1 into main Jul 8, 2026
3 checks passed
@lukaskroepfl lukaskroepfl deleted the feat/cli-api-client-header branch July 8, 2026 11:38
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.

2 participants