Skip to content
Open
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
5 changes: 5 additions & 0 deletions .sampo/changesets/prompts-project-secret-key-wording.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 7 additions & 6 deletions posthog/ai/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)


Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions posthog/test/ai/test_prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down