Skip to content

Commit d25fae3

Browse files
authored
fix(flags): Pass project API key in remote_config requests (#303)
1 parent 68e78c8 commit d25fae3

File tree

6 files changed

+48
-8
lines changed

6 files changed

+48
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 6.4.1 - 2025-08-06
2+
3+
- fix: Always pass project API key in `remote_config` requests for deterministic project routing
4+
15
# 6.4.0 - 2025-08-05
26

37
- feat: support Vertex AI for Gemini

posthog/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,7 @@ def get_remote_config_payload(self, key: str):
16441644
try:
16451645
return remote_config(
16461646
self.personal_api_key,
1647+
self.api_key,
16471648
self.host,
16481649
key,
16491650
timeout=self.feature_flags_request_timeout_seconds,

posthog/request.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,16 @@ def flags(
132132

133133

134134
def remote_config(
135-
personal_api_key: str, host: Optional[str] = None, key: str = "", timeout: int = 15
135+
personal_api_key: str,
136+
project_api_key: str,
137+
host: Optional[str] = None,
138+
key: str = "",
139+
timeout: int = 15,
136140
) -> Any:
137141
"""Get remote config flag value from remote_config API endpoint"""
138142
return get(
139143
personal_api_key,
140-
f"/api/projects/@current/feature_flags/{key}/remote_config/",
144+
f"/api/projects/@current/feature_flags/{key}/remote_config?token={project_api_key}",
141145
host,
142146
timeout,
143147
)

posthog/test/test_client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import unittest
33
from datetime import datetime
44
from uuid import uuid4
5-
from posthog.contexts import get_context_session_id, set_context_session, new_context
65

76
import mock
87
import six
98
from parameterized import parameterized
109

1110
from posthog.client import Client
11+
from posthog.contexts import get_context_session_id, new_context, set_context_session
1212
from posthog.request import APIError
1313
from posthog.test.test_utils import FAKE_TEST_API_KEY
1414
from posthog.types import FeatureFlag, LegacyFlagMetadata
@@ -2057,7 +2057,7 @@ def test_set_context_session_with_page_explicit_properties(self):
20572057

20582058
def test_set_context_session_override_in_capture(self):
20592059
"""Test that explicit session ID overrides context session ID in capture"""
2060-
from posthog.contexts import set_context_session, new_context
2060+
from posthog.contexts import new_context, set_context_session
20612061

20622062
with mock.patch("posthog.client.batch_post") as mock_post:
20632063
client = Client(FAKE_TEST_API_KEY, on_error=self.set_fail, sync_mode=True)
@@ -2158,6 +2158,7 @@ def test_get_remote_config_payload_works_without_poller(self, patch_remote_confi
21582158
self.assertEqual(result, {"test": "payload"})
21592159
patch_remote_config.assert_called_once_with(
21602160
"test-personal-key",
2161+
FAKE_TEST_API_KEY,
21612162
client.host,
21622163
"test-flag",
21632164
timeout=client.feature_flags_request_timeout_seconds,
@@ -2282,9 +2283,7 @@ def test_get_feature_flag_result_with_empty_string_payload(self, patch_batch_pos
22822283
}
22832284
]
22842285
},
2285-
"payloads": {
2286-
"empty-variant": "" # Empty string payload
2287-
},
2286+
"payloads": {"empty-variant": ""}, # Empty string payload
22882287
},
22892288
}
22902289
]

posthog/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = "6.4.0"
1+
VERSION = "6.4.1"
22

33
if __name__ == "__main__":
44
print(VERSION, end="") # noqa: T201

remote_config_example.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Simple test script for PostHog remote config endpoint.
4+
"""
5+
6+
import posthog
7+
8+
# Initialize PostHog client
9+
posthog.api_key = "phc_..."
10+
posthog.personal_api_key = "phs_..." # or "phx_..."
11+
posthog.host = "http://localhost:8000" # or "https://us.posthog.com"
12+
posthog.debug = True
13+
14+
15+
def test_remote_config():
16+
"""Test remote config payload retrieval."""
17+
print("Testing remote config endpoint...")
18+
19+
# Test feature flag key - replace with an actual flag key from your project
20+
flag_key = "unencrypted-remote-config-setting"
21+
22+
try:
23+
# Get remote config payload
24+
payload = posthog.get_remote_config_payload(flag_key)
25+
print(f"✅ Success! Remote config payload for '{flag_key}': {payload}")
26+
27+
except Exception as e:
28+
print(f"❌ Error getting remote config: {e}")
29+
30+
31+
if __name__ == "__main__":
32+
test_remote_config()

0 commit comments

Comments
 (0)