Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(hog): rename HOG_API_KEY to HOG_PERSONAL_API_KEY (#127795)

Rafael Audibert12e02b823c76
diff --git a/hog/MIGRATING.md b/hog/MIGRATING.md
index 048e44ecddb7..828c8596941e 100644
--- a/hog/MIGRATING.md
+++ b/hog/MIGRATING.md
@@ -19,7 +19,7 @@ hog reads only `HOG_` variables. Rename these:
| posthog-cli | hog |
| ---------------------------------------------- | ------------------------ |
-| `POSTHOG_CLI_API_KEY`, `POSTHOG_CLI_TOKEN` | `HOG_API_KEY` |
+| `POSTHOG_CLI_API_KEY`, `POSTHOG_CLI_TOKEN` | `HOG_PERSONAL_API_KEY` |
| `POSTHOG_CLI_PROJECT_ID`, `POSTHOG_CLI_ENV_ID` | `HOG_PROJECT_ID` |
| `POSTHOG_CLI_HOST` | `HOG_HOST` |
| `POSTHOG_CLI_DOTENV_FILE` | `HOG_DOTENV_FILE` |
diff --git a/hog/README.md b/hog/README.md
index 8573ea8a6bea..7fe430764770 100644
--- a/hog/README.md
+++ b/hog/README.md
@@ -181,7 +181,7 @@ hog uploads the same bytes and content hashes as posthog-cli, so either CLI can
`hog` reads credentials in the same order as `posthog-cli`, with `HOG_` variable names:
-1. `HOG_API_KEY` and `HOG_PROJECT_ID` in the environment, plus an optional `HOG_HOST`
+1. `HOG_PERSONAL_API_KEY` and `HOG_PROJECT_ID` in the environment, plus an optional `HOG_HOST`. The key is a personal API key: it acts as you, with your access.
2. The same variables in the file `--dotenv-file` or `HOG_DOTENV_FILE` names. A missing file prints a warning and hog moves on to the next source.
3. `~/.posthog/credentials.json`, which `hog auth login` and `posthog-cli login` write (`HOG_HOME` moves the folder). `hog auth login` makes it readable only by you.
diff --git a/hog/src/commands/auth/auth.test.ts b/hog/src/commands/auth/auth.test.ts
index 8485c9989904..1ef27a138299 100644
--- a/hog/src/commands/auth/auth.test.ts
+++ b/hog/src/commands/auth/auth.test.ts
@@ -252,10 +252,10 @@ describe('hog auth login', () => {
[
'a key in the environment',
{ [CREDENTIALS_FILE]: STORED },
- { HOG_API_KEY: 'phx_env' },
+ { HOG_PERSONAL_API_KEY: 'phx_env' },
'logged_out',
'https://eu.posthog.com/settings/user-api-keys',
- ['HOG_API_KEY'],
+ ['HOG_PERSONAL_API_KEY'],
],
])('logout with %s removes what hog stored', async (_name, files, env, status, revokeUrl, stillSet) => {
const result = await runHog(['auth', 'logout'], { env: { CLAUDECODE: '1', ...env }, files })
diff --git a/hog/src/commands/auth/login.ts b/hog/src/commands/auth/login.ts
index 34bcf1b4c3bf..f0eb31866356 100644
--- a/hog/src/commands/auth/login.ts
+++ b/hog/src/commands/auth/login.ts
@@ -100,7 +100,7 @@ export default defineCommand({
notes: [
'At a terminal, hog asks where your PostHog account is hosted and opens the browser to approve the login.',
'Agents and scripts get a link and a code to hand to a person, then finish with `hog auth login --wait`.',
- 'In CI, skip login and set HOG_API_KEY, HOG_PROJECT_ID and HOG_HOST.',
+ 'In CI, skip login and set HOG_PERSONAL_API_KEY, HOG_PROJECT_ID and HOG_HOST.',
].join('\n'),
examples: ['hog auth login', 'hog auth login --region eu', 'hog auth login --wait'],
@@ -124,7 +124,7 @@ export default defineCommand({
throw new HogError(
'login_needs_a_person',
'hog auth login needs a person to approve it in a browser, so it does not run in CI.',
- 'Set HOG_API_KEY, HOG_PROJECT_ID and HOG_HOST instead.'
+ 'Set HOG_PERSONAL_API_KEY, HOG_PROJECT_ID and HOG_HOST instead.'
)
}
diff --git a/hog/src/commands/auth/logout.ts b/hog/src/commands/auth/logout.ts
index c88e661d203b..5cc32d2ef8ed 100644
--- a/hog/src/commands/auth/logout.ts
+++ b/hog/src/commands/auth/logout.ts
@@ -1,5 +1,5 @@
import { defineCommand } from '@/core/command'
-import { API_KEY_ENV_VAR, posthogFile } from '@/posthog/credentials'
+import { PERSONAL_API_KEY_ENV_VAR, posthogFile } from '@/posthog/credentials'
import { clearPendingLogin } from '@/posthog/login'
interface LogoutResult {
@@ -33,7 +33,7 @@ export default defineCommand({
status: stored ? 'logged_out' : 'not_logged_in',
credentialsPath,
revokeUrl: host ? new URL('settings/user-api-keys', `${host.replace(/\/+$/, '')}/`).toString() : null,
- stillSet: runtime.env[API_KEY_ENV_VAR] ? [API_KEY_ENV_VAR] : [],
+ stillSet: runtime.env[PERSONAL_API_KEY_ENV_VAR] ? [PERSONAL_API_KEY_ENV_VAR] : [],
}
},
diff --git a/hog/src/commands/auth/status.ts b/hog/src/commands/auth/status.ts
index e450ededc5d3..58cfbda38b0f 100644
--- a/hog/src/commands/auth/status.ts
+++ b/hog/src/commands/auth/status.ts
@@ -4,7 +4,7 @@ import { checkAuthStatus } from '@/posthog/auth-status'
import type { CredentialSource } from '@/posthog/credentials'
const SOURCE_LABELS: Record<CredentialSource, string> = {
- env: 'the HOG_API_KEY environment variable',
+ env: 'the HOG_PERSONAL_API_KEY environment variable',
'dotenv-file': 'the --dotenv-file file',
'credentials-file': 'the credentials file',
}
diff --git a/hog/src/core/globals.ts b/hog/src/core/globals.ts
index 338fbe820c9d..22364da567de 100644
--- a/hog/src/core/globals.ts
+++ b/hog/src/core/globals.ts
@@ -17,7 +17,8 @@ export const GLOBAL_OPTIONS = {
type: 'string',
placeholder: 'path',
env: ['HOG_DOTENV_FILE'],
- description: 'Read HOG_API_KEY, HOG_PROJECT_ID and HOG_HOST from this file when the environment has none',
+ description:
+ 'Read HOG_PERSONAL_API_KEY, HOG_PROJECT_ID and HOG_HOST from this file when the environment has none',
},
output: {
type: 'string',
diff --git a/hog/src/posthog/credentials.test.ts b/hog/src/posthog/credentials.test.ts
index 30b4e19a524f..c62cd2bc870f 100644
--- a/hog/src/posthog/credentials.test.ts
+++ b/hog/src/posthog/credentials.test.ts
@@ -5,8 +5,8 @@ import { fakeRuntime } from '@/testing'
import { DEFAULT_HOST, resolveCredentials } from './credentials'
-const ENV = { HOG_API_KEY: 'phx_env', HOG_PROJECT_ID: '1', HOG_HOST: 'https://env.example.com' }
-const DOTENV = 'HOG_API_KEY="phx_dotenv"\n# comment\nHOG_PROJECT_ID=2\n'
+const ENV = { HOG_PERSONAL_API_KEY: 'phx_env', HOG_PROJECT_ID: '1', HOG_HOST: 'https://env.example.com' }
+const DOTENV = 'HOG_PERSONAL_API_KEY="phx_dotenv"\n# comment\nHOG_PROJECT_ID=2\n'
const STORED = JSON.stringify({ token: 'phx_stored', env_id: '3', host: 'https://stored.example.com' })
describe('resolveCredentials', () => {
@@ -87,14 +87,14 @@ describe('resolveCredentials', () => {
],
[
'a key without the phx_ prefix',
- { HOG_API_KEY: 'abc', HOG_PROJECT_ID: '1' },
+ { HOG_PERSONAL_API_KEY: 'abc', HOG_PROJECT_ID: '1' },
'invalid_credentials',
{},
undefined,
],
[
'a project ID that is not a number',
- { HOG_API_KEY: 'phx_a', HOG_PROJECT_ID: 'two' },
+ { HOG_PERSONAL_API_KEY: 'phx_a', HOG_PROJECT_ID: 'two' },
'invalid_credentials',
{},
undefined,
@@ -134,6 +134,6 @@ describe('resolveCredentials', () => {
expect(error.code).toBe('not_authenticated')
expect(error.hint).toContain('HOG_HOME')
- expect(error.hint).toContain('HOG_API_KEY')
+ expect(error.hint).toContain('HOG_PERSONAL_API_KEY')
})
})
diff --git a/hog/src/posthog/credentials.ts b/hog/src/posthog/credentials.ts
index 9ba72ea66c18..9bbedcc28dea 100644
--- a/hog/src/posthog/credentials.ts
+++ b/hog/src/posthog/credentials.ts
@@ -22,12 +22,12 @@ interface RawCredentials {
host: string | undefined
}
-export const API_KEY_ENV_VAR = 'HOG_API_KEY'
+export const PERSONAL_API_KEY_ENV_VAR = 'HOG_PERSONAL_API_KEY'
// The host only counts when it comes from the same source as the key, so a stray host cannot
// redirect a key from somewhere else.
function fromLookup(lookup: (name: string) => string | undefined): RawCredentials | undefined {
- const apiKey = lookup(API_KEY_ENV_VAR)
+ const apiKey = lookup(PERSONAL_API_KEY_ENV_VAR)
const projectId = lookup('HOG_PROJECT_ID')
if (!apiKey || !projectId) {
return undefined
@@ -80,7 +80,7 @@ async function readDotenv(runtime: Runtime, path: string): Promise<string | unde
}
const NO_HOME_HINT =
- 'Set HOG_HOME to a folder hog can write to, or set HOG_API_KEY and HOG_PROJECT_ID to skip logging in.'
+ 'Set HOG_HOME to a folder hog can write to, or set HOG_PERSONAL_API_KEY and HOG_PROJECT_ID to skip logging in.'
function posthogHomeDir(env: Env, homeDir: string | undefined): string | undefined {
if (env.HOG_HOME) {
@@ -185,7 +185,7 @@ export async function resolveCredentials(
if (!fromFile) {
throw new HogError(
'not_authenticated',
- `hog couldn't find HOG_API_KEY and HOG_PROJECT_ID in the environment or in ${dotenvFile}.`,
+ `hog couldn't find HOG_PERSONAL_API_KEY and HOG_PROJECT_ID in the environment or in ${dotenvFile}.`,
'Add both variables to the file, or remove --dotenv-file.'
)
}
@@ -219,6 +219,6 @@ export async function resolveCredentials(
throw new HogError(
'not_authenticated',
"hog couldn't find PostHog credentials.",
- 'Run `hog auth login`, or set HOG_API_KEY and HOG_PROJECT_ID.'
+ 'Run `hog auth login`, or set HOG_PERSONAL_API_KEY and HOG_PROJECT_ID.'
)
}
diff --git a/hog/src/testing.ts b/hog/src/testing.ts
index c0a25feccc34..3f56555cd3bd 100644
--- a/hog/src/testing.ts
+++ b/hog/src/testing.ts
@@ -158,7 +158,7 @@ export function fakeRuntime(options: FakeRuntimeOptions = {}): FakeRuntime {
// Credentials that pass validation, plus NO_COLOR so text output has no escape codes.
export const TEST_CREDENTIALS = {
- HOG_API_KEY: 'phx_test',
+ HOG_PERSONAL_API_KEY: 'phx_test',
HOG_PROJECT_ID: '7',
HOG_HOST: 'https://ph.example.com',
NO_COLOR: '1',
diff --git a/hog/test/parity/run.ts b/hog/test/parity/run.ts
index e7ee3c5f4d82..e137881804c9 100644
--- a/hog/test/parity/run.ts
+++ b/hog/test/parity/run.ts
@@ -27,7 +27,7 @@ function environment(serverUrl: string, home: string): Record<string, string> {
POSTHOG_CLI_API_KEY: 'phx_parity',
POSTHOG_CLI_PROJECT_ID: '1',
POSTHOG_CLI_HOST: serverUrl,
- HOG_API_KEY: 'phx_parity',
+ HOG_PERSONAL_API_KEY: 'phx_parity',
HOG_PROJECT_ID: '1',
HOG_HOST: serverUrl,
NO_COLOR: '1',