fix(ai/prompts): give HTTP 401 a real error message - #893
Merged
turnipdabeets merged 2 commits intoAug 24, 2026
Merged
Conversation
Prompt fetches that fail with 401 fell through to a generic "HTTP 401" error that gave no hint the personal API key was missing, expired, or the wrong type. Add a 401 branch, alongside the existing 403 branch, that names the likely causes, including the common personal-key-versus-secret-key mixup. Generated-By: PostHog Desktop Task-Id: cece44a6-1807-431b-8a3e-7f00e0d75eac
Contributor
Author
🦔 ReviewHog reviewed this pull requestFound 0 must fix, 1 should fix, 0 consider. Published 1 finding (view the review). Resolved comments: 1 fixed |
Contributor
posthog-python Compliance ReportDate: 2026-08-24 19:50:23 UTC ✅ All Tests Passed!111/111 tests passed Capture_V1 Tests✅ 94/94 tests passed View Details
Feature_Flags Tests✅ 17/17 tests passed View Details
|
Contributor
Author
|
ReviewHog Alpha 🦔 If you find any issues helpful - please reply "valid", "invalid", etc., for evaluation purposes 🙏 |
The 401 auth-failure message told users to "pass a personal_api_key and not a secret key", conflating the key type (personal API key vs project secret key) with the parameter name. A correctly-configured client user (`Posthog(..., secret_key='phx_...')`) would read this as "switch to personal_api_key=", which resolves to the same value and re-triggers the 401 plus a DeprecationWarning. Reword so the message names the key type (personal API key, starts with 'phx_'; a project secret key is not accepted) separately from the parameter to use per entry point: personal_api_key when constructing Prompts directly, secret_key when configuring the PostHog client. Generated-By: PostHog Desktop Task-Id: add0fc6a-5a9d-4035-882a-aa60824939bf
turnipdabeets
approved these changes
Aug 24, 2026
turnipdabeets
deleted the
posthog-self-driving/fixaiprompts-give-http-401-a-real-error-20922a
branch
August 24, 2026 19:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 Motivation and Context
HTTP 401from a prompt fetch with no hint why the key was rejected — missing, expired, or the wrong type. The caller falls back to a bundled prompt, so onboarding still works but quietly serves a stale prompt instead of theproductionlabel, and nobody watching error tracking can tell why._fetch_prompt_from_apihandled only 404 and 403 explicitly; every other status, 401 included, fell through to a genericHTTP {status_code}string.Applies to every SDK user hitting an auth failure, not just the onboarding path.
💚 How did you test it?
test_handle_401_response, which asserts the new message names the prompt and mentions the personal API key.pytest posthog/test/ai/test_prompts.py(401 and 403 cases pass).ruff formatandruff checkon both changed files.📝 Checklist
If releasing new changes
sampo addto generate a changeset file🤖 Agent context
Autonomy: Fully autonomous
posthog/ai/prompts.py, plus one test. No adjacent refactoring.Created with PostHog Desktop from this inbox report.