diff --git a/packages/optimization/src/ldai_optimizer/ld_api_client.py b/packages/optimization/src/ldai_optimizer/ld_api_client.py index 6dbd580a..447bb32a 100644 --- a/packages/optimization/src/ldai_optimizer/ld_api_client.py +++ b/packages/optimization/src/ldai_optimizer/ld_api_client.py @@ -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, diff --git a/packages/optimization/tests/test_ld_api_client.py b/packages/optimization/tests/test_ld_api_client.py index e2c11cb8..88c6104d 100644 --- a/packages/optimization/tests/test_ld_api_client.py +++ b/packages/optimization/tests/test_ld_api_client.py @@ -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(