Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/optimization/src/ldai_optimizer/ld_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ def __repr__(self) -> str:
return f"LDApiClient(base_url={self._base_url!r})"

def _auth_headers(self) -> Dict[str, str]:
return {"Authorization": self._api_key}
return {
"Authorization": self._api_key,
"LD-API-Version": "20240415",
}

def _request(
self,
Expand Down
8 changes: 8 additions & 0 deletions packages/optimization/tests/test_ld_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ def test_authorization_header_always_sent(self):
req: urllib.request.Request = mock_open.call_args[0][0]
assert req.get_header("Authorization") == "my-api-key"

def test_default_api_version_header_is_v4(self):
client = LDApiClient("test-key")
with patch("urllib.request.urlopen", return_value=_mock_urlopen({})) as mock_open:
client._request("GET", "/path")
req: urllib.request.Request = mock_open.call_args[0][0]
# urllib capitalizes header names; the wire value is still LD-API-Version.
assert req.get_header("Ld-api-version") == "20240415"

def test_raises_ld_api_error_on_http_error(self):
client = LDApiClient("test-key")
http_error = urllib.error.HTTPError(
Expand Down
Loading