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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 6.4.1 - 2025-08-06

- fix: Always pass project API key in `remote_config` requests for deterministic project routing

# 6.4.0 - 2025-08-05

- feat: support Vertex AI for Gemini
Expand Down
1 change: 1 addition & 0 deletions posthog/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1644,6 +1644,7 @@ def get_remote_config_payload(self, key: str):
try:
return remote_config(
self.personal_api_key,
self.api_key,
self.host,
key,
timeout=self.feature_flags_request_timeout_seconds,
Expand Down
8 changes: 6 additions & 2 deletions posthog/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,16 @@ def flags(


def remote_config(
personal_api_key: str, host: Optional[str] = None, key: str = "", timeout: int = 15
personal_api_key: str,
project_api_key: str,
host: Optional[str] = None,
key: str = "",
timeout: int = 15,
) -> Any:
"""Get remote config flag value from remote_config API endpoint"""
return get(
personal_api_key,
f"/api/projects/@current/feature_flags/{key}/remote_config/",
f"/api/projects/@current/feature_flags/{key}/remote_config?token={project_api_key}",
host,
timeout,
)
Expand Down
9 changes: 4 additions & 5 deletions posthog/test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
import unittest
from datetime import datetime
from uuid import uuid4
from posthog.contexts import get_context_session_id, set_context_session, new_context

import mock
import six
from parameterized import parameterized

from posthog.client import Client
from posthog.contexts import get_context_session_id, new_context, set_context_session
from posthog.request import APIError
from posthog.test.test_utils import FAKE_TEST_API_KEY
from posthog.types import FeatureFlag, LegacyFlagMetadata
Expand Down Expand Up @@ -2057,7 +2057,7 @@ def test_set_context_session_with_page_explicit_properties(self):

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

with mock.patch("posthog.client.batch_post") as mock_post:
client = Client(FAKE_TEST_API_KEY, on_error=self.set_fail, sync_mode=True)
Expand Down Expand Up @@ -2158,6 +2158,7 @@ def test_get_remote_config_payload_works_without_poller(self, patch_remote_confi
self.assertEqual(result, {"test": "payload"})
patch_remote_config.assert_called_once_with(
"test-personal-key",
FAKE_TEST_API_KEY,
client.host,
"test-flag",
timeout=client.feature_flags_request_timeout_seconds,
Expand Down Expand Up @@ -2282,9 +2283,7 @@ def test_get_feature_flag_result_with_empty_string_payload(self, patch_batch_pos
}
]
},
"payloads": {
"empty-variant": "" # Empty string payload
},
"payloads": {"empty-variant": ""}, # Empty string payload
},
}
]
Expand Down
2 changes: 1 addition & 1 deletion posthog/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "6.4.0"
VERSION = "6.4.1"

if __name__ == "__main__":
print(VERSION, end="") # noqa: T201
32 changes: 32 additions & 0 deletions remote_config_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3
"""
Simple test script for PostHog remote config endpoint.
"""

import posthog

# Initialize PostHog client
posthog.api_key = "phc_..."
posthog.personal_api_key = "phs_..." # or "phx_..."
posthog.host = "http://localhost:8000" # or "https://us.posthog.com"
posthog.debug = True


def test_remote_config():
"""Test remote config payload retrieval."""
print("Testing remote config endpoint...")

# Test feature flag key - replace with an actual flag key from your project
flag_key = "unencrypted-remote-config-setting"

try:
# Get remote config payload
payload = posthog.get_remote_config_payload(flag_key)
print(f"✅ Success! Remote config payload for '{flag_key}': {payload}")

except Exception as e:
print(f"❌ Error getting remote config: {e}")


if __name__ == "__main__":
test_remote_config()