@posthog/ai 7.8.11 → 7.8.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -31,6 +31,7 @@ type PromptVariables = Record<string, string | number | boolean>;
31
31
  */
32
32
  interface PromptsDirectOptions {
33
33
  personalApiKey: string;
34
+ projectApiKey: string;
34
35
  host?: string;
35
36
  defaultCacheTtlSeconds?: number;
36
37
  }
@@ -308,6 +309,7 @@ type PromptsOptions = PromptsWithPostHogOptions | PromptsDirectOptions;
308
309
  * // Or with direct options (no PostHog client needed)
309
310
  * const prompts = new Prompts({
310
311
  * personalApiKey: 'phx_xxx',
312
+ * projectApiKey: 'phc_xxx',
311
313
  * host: 'https://us.posthog.com',
312
314
  * })
313
315
  *
@@ -326,6 +328,7 @@ type PromptsOptions = PromptsWithPostHogOptions | PromptsDirectOptions;
326
328
  */
327
329
  declare class Prompts {
328
330
  private personalApiKey;
331
+ private projectApiKey;
329
332
  private host;
330
333
  private defaultCacheTtlSeconds;
331
334
  private cache;
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import { uuidv7 } from '@posthog/core';
5
5
  import AnthropicOriginal from '@anthropic-ai/sdk';
6
6
  import { GoogleGenAI } from '@google/genai';
7
7
 
8
- var version = "7.8.11";
8
+ var version = "7.8.13";
9
9
 
10
10
  // Type guards for safer type checking
11
11
  const isString = value => {
@@ -4375,6 +4375,7 @@ function isPromptsWithPostHog(options) {
4375
4375
  * // Or with direct options (no PostHog client needed)
4376
4376
  * const prompts = new Prompts({
4377
4377
  * personalApiKey: 'phx_xxx',
4378
+ * projectApiKey: 'phc_xxx',
4378
4379
  * host: 'https://us.posthog.com',
4379
4380
  * })
4380
4381
  *
@@ -4397,10 +4398,12 @@ class Prompts {
4397
4398
  this.defaultCacheTtlSeconds = options.defaultCacheTtlSeconds ?? DEFAULT_CACHE_TTL_SECONDS;
4398
4399
  if (isPromptsWithPostHog(options)) {
4399
4400
  this.personalApiKey = options.posthog.options.personalApiKey ?? '';
4401
+ this.projectApiKey = options.posthog.apiKey ?? '';
4400
4402
  this.host = options.posthog.host;
4401
4403
  } else {
4402
4404
  // Direct options
4403
4405
  this.personalApiKey = options.personalApiKey;
4406
+ this.projectApiKey = options.projectApiKey;
4404
4407
  this.host = options.host ?? 'https://us.posthog.com';
4405
4408
  }
4406
4409
  }
@@ -4484,7 +4487,12 @@ class Prompts {
4484
4487
  if (!this.personalApiKey) {
4485
4488
  throw new Error('[PostHog Prompts] personalApiKey is required to fetch prompts. ' + 'Please provide it when initializing the Prompts instance.');
4486
4489
  }
4487
- const url = `${this.host}/api/environments/@current/llm_prompts/name/${encodeURIComponent(name)}/`;
4490
+ if (!this.projectApiKey) {
4491
+ throw new Error('[PostHog Prompts] projectApiKey is required to fetch prompts. ' + 'Please provide it when initializing the Prompts instance.');
4492
+ }
4493
+ const encodedPromptName = encodeURIComponent(name);
4494
+ const encodedProjectApiKey = encodeURIComponent(this.projectApiKey);
4495
+ const url = `${this.host}/api/environments/@current/llm_prompts/name/${encodedPromptName}/?token=${encodedProjectApiKey}`;
4488
4496
  const response = await fetch(url, {
4489
4497
  method: 'GET',
4490
4498
  headers: {