Skip to content
PluginStats

aisdk-posthog weekly downloads statistics

By orchlab · npm · AI SDKs

PostHog LLM analytics integration for the Vercel AI SDK (OpenTelemetry-based)

View on npm Fresh · Dec 6, 2026

aisdk-posthog has 1,291 recorded weekly downloads on npm, an increase of 141% over the past 30 days, ranking #2010 of 3,247 tracked listings.

Weekly downloads
1,291
Official API · Dec 5, 2026
7-day growth
+8.3%
+99 weekly downloads
30-day growth
+141%
+755 weekly downloads
90-day growth
+2052%
+1.2K weekly downloads
Rank
#2010
▼ 73 in 7 days

About aisdk-posthog

aisdk-posthog

PostHog LLM analytics integration for the Vercel AI SDK, built on OpenTelemetry.

Maps the spans emitted by AI SDK v7's @ai-sdk/otel integration (invoke_agent, chat, execute_tool, ...) to PostHog LLM observability events: $ai_trace, $ai_generation, $ai_span. Requires ai ^7 (v6 users: stay on aisdk-posthog@0.2.x). Includes split input/output/total cost in USD via llm-info, a deterministic execution-trace ID derived from your own ID, and a streaming-aware buffer that fixes parent-child span relationships when the AI SDK's TransformStream boundaries break OTel context propagation.

Status: community-maintained. Not an official PostHog SDK.

Install

npm install aisdk-posthog ai @ai-sdk/otel
# or
pnpm add aisdk-posthog ai @ai-sdk/otel

ai (>=7) and @ai-sdk/otel are required peer dependencies. Node 22.12+.

Two ways to use it

The package supports two modes that compose freely. Mix and match per file.

Mode A — drop-in subpath (zero per-call boilerplate)

Register a default telemetry instance once at app boot, then change one import line per file. Every LLM call inside is auto-instrumented; tool calls trace automatically; sub-agents pick up the right functionId via subAgent().

// app/boot.ts — register once
import { createAISDKTelemetry, setDefaultTelemetry } from 'aisdk-posthog';

const telemetry = createAISDKTelemetry({
  apiKey: process.env.POSTHOG_API_KEY!,
  enabled: process.env.NODE_ENV === 'production',
  getContext: ({ spanAttributes, executionUidByTraceId }) => {
    const executionUid =
      (spanAttributes['ai.telemetry.metadata.executionUid'] as
        | string
        | undefined) ?? executionUidByTraceId;
    if (!executionUid) return undefined;
    // …look up your user/workspace/chat from `executionUid`…
    return {
      distinctId: 'user_42',
      groupId: 'workspace_99',
      groupType: 'workspace_id',
    };
  },
});
setDefaultTelemetry(telemetry);
// anywhere else — only the import line changes
- import { generateText, streamText, ToolLoopAgent, tool } from 'ai';
+ import { generateText, streamText, ToolLoopAgent, tool } from 'aisdk-posthog/ai';

// call sites stay literally identical
await generateText({ model, prompt });   // auto-instrumented
await streamText({ model, messages });   // auto-instrumented

const agent = new ToolLoopAgent({ model, instructions, tools }); // auto-instrumented

If setDefaultTelemetry is never called or telemetry is disabled, the wrappers forward untouched — calls behave exactly like importing from 'ai' directly.

Mode B — per-call embedding (explicit, no globals)

Hold the instance and pass telemetry: telemetry.getTelemetry(...) per call. No subpath, no module-level state. Use this when you want fine-grained control over functionId per call site.

import { generateText } from 'ai';
import { telemetry } from './boot';

await generateText({
  model,
  prompt,
  telemetry: telemetry.getTelemetry('chat-reply', {
    executionUid,
  }),
});
Mixing modes

Both modes coexist. Caller-supplied telemetry (or the deprecated experimental_telemetry alias) always wins over the auto-injected default, so you can use the subpath everywhere and override per call when you want a custom functionId:

import { generateText } from 'aisdk-posthog/ai';
import { telemetry } from './boot';

// Most calls auto-instrument with default config
await generateText({ model, prompt });

// One specific call wants a custom functionId
await generateText({
  model,
  prompt,
  telemetry: telemetry.getTelemetry('special-case'),
});

Sub-agents (tools that call LLMs internally)

Wrap the tool with subAgent('name', tool({...})). Inside the wrapped tool, the AI SDK functions imported from the subpath automatically use 'name' as their functionId so the sub-agent shows up by name in PostHog. This works for both generateText patterns and ToolLoopAgent patterns.

import { subAgent } from 'aisdk-posthog';
import { generateText, ToolLoopAgent, tool, stepCountIs } from 'aisdk-posthog/ai';
import { z } from 'zod';

tools: {
  research: subAgent('research', tool({
    description: 'Research a topic',
    inputSchema: z.object({ topic: z.string() }),
    execute: async ({ topic }, { abortSignal }) => {
      // Functions imported from 'aisdk-posthog/ai' read the current
      // sub-agent name from AsyncLocalStorage and tag the span as
      // `functionId: 'research'`. No telemetry threading.
      const agent = new ToolLoopAgent({
        model, instructions, tools: innerTools, stopWhen: stepCountIs(12),
      });
      return (await agent.generate({ prompt: topic, abortSignal })).text;
    },
  })),
}

For per-call mode, read the current sub-agent name yourself:

import { tool } from 'ai';
import { subAgent, currentSubAgentName } from 'aisdk-posthog';
import { generateText } from 'ai';

tools: {
  research: subAgent('research', tool({
    description, inputSchema,
    execute: async ({ topic }, { abortSignal }) => {
      return generateText({
        model, prompt: `Research: ${topic}`,
        telemetry: telemetry.getTelemetry(
          currentSubAgentName() ?? 'fallback',
        ),
        abortSignal,
      });
    },
  })),
}

Wrapping a top-level execution

Use withExecutionTrace to anchor an entire request under one PostHog trace with a stable, deterministic traceId derived from your own execution ID:

import { randomUUID } from 'node:crypto';

const requestId = randomUUID();

await telemetry.withExecutionTrace(
  requestId,
  'chat.reply',
  { userId: req.user.id, channel: 'slack' },
  async () => {
    // every LLM call inside lands as a child of `chat.reply`
    return generateText({ model, prompt }); // subpath: auto-instrumented
  },
);…

Description from the npm listing.

  • ai-sdk
  • vercel-ai-sdk
  • posthog
  • analytics
  • llm
  • ai
  • observability
  • telemetry
  • opentelemetry

README badge

Show your rank in a README or on your website. The badge updates automatically.

Charts

Images: 30d · 1y · all time · 1600×900 dark

Adoption over time

aisdk-posthog weekly downloads on npm, last 90 days: 1,291 weekly downloads as of Dec 5, 2026, +2052% over 90 days.aisdk-posthogWeekly downloads on npm · Last 90 days1,291downloads / week+2052% over 90 days02004006008001K1.2K1.4KSep 6Sep 21Oct 6Oct 21Nov 5Nov 20Dec 5downloads / weekobservedarchived (Internet Archive)no observationsSep 7, 2026 – Dec 5, 2026 · 90 observations · Updated Dec …pluginstats.com
aisdk-posthog weekly downloads on npm, last 90 days: 1,291 weekly downloads as of Dec 5, 2026, +2052% over 90 days.

7/30/90-day growth

aisdk-posthog weekly downloads growth on npm: +8.3% over 7 days, +141% over 30 days, +2052% over 90 days.aisdk-posthogWeekly downloads growth on npm1,291downloads / week now7-day growth+99 weekly downloads+8.3%30-day growth+755 weekly downloads+141%90-day growth+1,231 weekly downloads+2052%Growth vs. nearest observation to each baseline date · Updated Dec 5, 2026pluginstats.com
aisdk-posthog weekly downloads growth on npm: +8.3% over 7 days, +141% over 30 days, +2052% over 90 days.

Ranking history

aisdk-posthog npm ranking history: currently #2010 (by weekly downloads).aisdk-posthognpm ranking · by weekly downloads · Last 90 days#2010current rank#1500#1600#1700#1800#1900#2000#2100Sep 7Sep 22Oct 7Oct 22Nov 6Nov 21Dec 6rankNov 12, 2026 – Dec 6, 2026 · 25 observations · Updated Dec 5, 2026pluginstats.com
aisdk-posthog npm ranking history: currently #2010 (by weekly downloads).

Listing placement

All npm3,247 listings · 163 pages · 1,084 shown · page 101, #10 (overall #2,010)
All npm: every listing in weekly downloads order

Listing placement

AI SDKs378 listings · 19 pages · page 11, #10 (overall #210)
AI SDKs: every listing in weekly downloads order

Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.

Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.

Recent observations

Full history (142)
Recent weekly downloads observations for aisdk-posthog
Date (UTC)Weekly downloadsChange vs. previous
1,291+48
1,243-54
1,297+74
1,223+71
1,152-13
1,165-106
1,271+79
1,192-20
1,212+39
1,173+128
1,045+46
999-15
1,014+8
1,006—

Similar npm AI SDKs plugins

All 20 aisdk-posthog alternatives

Data source

Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.

Listing: https://www.npmjs.com/package/aisdk-posthog. First seen Nov 12, 2026; last successful collection Dec 6, 2026. See the methodology.