From abe88c41a5dbe04c597945260ca78e4dc308769b Mon Sep 17 00:00:00 2001 From: Juraj Majerik Date: Thu, 26 Nov 2026 13:35:38 +0530 Subject: [PATCH] fix(prompts): say a project secret key works for prompt fetches Co-Authored-By: Claude Fable 5.1 --- .../prompts-project-secret-key-wording.md | 5 +++++ posthog/ai/prompts.py | 13 +++++++------ posthog/test/ai/test_prompts.py | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 .sampo/changesets/prompts-project-secret-key-wording.md diff --git a/.sampo/changesets/prompts-project-secret-key-wording.md b/.sampo/changesets/prompts-project-secret-key-wording.md new file mode 100644 index 000000000..b41fdc868 --- /dev/null +++ b/.sampo/changesets/prompts-project-secret-key-wording.md @@ -0,0 +1,5 @@ +--- +pypi/posthog: patch +--- + +The prompt fetch error messages now say that a project secret API key (`phs_`) with the `llm_prompt:read` scope works as well as a personal API key. The server has accepted both since November 2026. diff --git a/posthog/ai/prompts.py b/posthog/ai/prompts.py index 4da454703..fd8579b63 100644 --- a/posthog/ai/prompts.py +++ b/posthog/ai/prompts.py @@ -210,17 +210,17 @@ def _authentication_error(reference: str) -> Exception: return Exception( f"[PostHog Prompts] Authentication failed for {reference}. " "The key may be missing, expired, or the wrong type. Prompt fetches " - "require a personal API key (starts with 'phx_'); a project secret " - "key is not accepted. Pass this key as personal_api_key when you " - "construct Prompts directly, or as secret_key when you configure the " - "PostHog client." + "need a personal API key (starts with 'phx_') or a project secret " + "API key (starts with 'phs_') with the llm_prompt:read scope. Pass " + "it as personal_api_key when you construct Prompts directly, or as " + "secret_key when you configure the PostHog client." ) def _access_denied_error(reference: str) -> Exception: return Exception( f"[PostHog Prompts] Access denied for {reference}. " - "Check that your personal_api_key has the correct permissions and the LLM prompts feature is enabled." + "Check that your personal_api_key has the llm_prompt:read scope and the LLM prompts feature is enabled." ) @@ -287,7 +287,8 @@ def __init__( Args: posthog: PostHog client instance (optional if personal_api_key provided) - personal_api_key: Direct personal API key (optional if posthog provided) + personal_api_key: Personal API key (phx_) or project secret API key (phs_) + with the llm_prompt:read scope (optional if posthog provided) project_api_key: Direct project API key (optional if posthog provided) host: PostHog host (defaults to app endpoint) default_cache_ttl_seconds: Default cache TTL (defaults to 300) diff --git a/posthog/test/ai/test_prompts.py b/posthog/test/ai/test_prompts.py index 7072bc90c..cc9bfb468 100644 --- a/posthog/test/ai/test_prompts.py +++ b/posthog/test/ai/test_prompts.py @@ -595,6 +595,7 @@ def test_handle_401_response(self, mock_get_session): message = str(context.exception) self.assertIn('Authentication failed for prompt "restricted-prompt"', message) self.assertIn("personal API key", message) + self.assertIn("project secret API key", message) def test_throw_when_no_personal_api_key_configured(self): """Should throw when no personal_api_key is configured."""