Skip to content

Commit 36627c7

Browse files
authored
fix(optimization): pin LD-API-Version on agent-optimization API calls (AIC-3484) (#216)
## Summary - Agent-optimization requests now send `LD-API-Version: 20240415` by default. - AI Config calls in the same client still send `beta`, which overrides that default. - After 2026-12-31, a call with no version header is rejected when the customer's token defaults below API v4. These requests use that token. ## Test plan - [x] `uv run pytest` in `packages/optimization` - [x] Confirm a request with no extra headers records `Ld-api-version: 20240415`, and `get_ai_config_variation` still sends `beta`.
2 parents f7bfe59 + fa7b6c3 commit 36627c7

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎packages/optimization/src/ldai_optimizer/ld_api_client.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,10 @@ def __repr__(self) -> str:
198198
return f"LDApiClient(base_url={self._base_url!r})"
199199

200200
def _auth_headers(self) -> Dict[str, str]:
201-
return {"Authorization": self._api_key}
201+
return {
202+
"Authorization": self._api_key,
203+
"LD-API-Version": "20240415",
204+
}
202205

203206
def _request(
204207
self,

‎packages/optimization/tests/test_ld_api_client.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ def test_authorization_header_always_sent(self):
168168
req: urllib.request.Request = mock_open.call_args[0][0]
169169
assert req.get_header("Authorization") == "my-api-key"
170170

171+
def test_default_api_version_header_is_v4(self):
172+
client = LDApiClient("test-key")
173+
with patch("urllib.request.urlopen", return_value=_mock_urlopen({})) as mock_open:
174+
client._request("GET", "/path")
175+
req: urllib.request.Request = mock_open.call_args[0][0]
176+
# urllib capitalizes header names; the wire value is still LD-API-Version.
177+
assert req.get_header("Ld-api-version") == "20240415"
178+
171179
def test_raises_ld_api_error_on_http_error(self):
172180
client = LDApiClient("test-key")
173181
http_error = urllib.error.HTTPError(

0 commit comments

Comments
 (0)