instrument-llm-analytics

Instrument LLM calls to emit $ai_generation events to PostHog.

58|5|Updated Jan 19, 2026
One-click install
npx skills add https://github.com/PostHog/skills --skill instrument-llm-analytics
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: instrument-llm-analytics
Source: https://github.com/PostHog/skills/tree/main/skills/omnibus/instrument-llm-analytics
Command: npx skills add https://github.com/PostHog/skills --skill instrument-llm-analytics

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Instrumentation of LLM calls to automatically generate and push $ai_generation events to PostHog, enabling observability of model usage, latency, tokens, and costs across your stack.

Core Features & Use Cases

  • Auto-instrument LLM calls across providers and frameworks using OpenTelemetry and PostHog instrumentation to generate $ai_generation events with model, provider, input/output tokens, latency, and cost data.
  • Link events to users and traces, enabling per-user analytics, traces, spans, and sessions for debugging and performance optimization.
  • Quick start guidance for installation, environment configuration, and minimal code changes to instrument LLM calls without restructuring your architecture.
  • Supports multiple providers and frameworks as listed in the SKILL.md to ensure broad coverage.

Quick Start

Configure your project to enable PostHog LLM analytics instrumentation, install the required SDKs, and instrument your LLM calls with minimal code changes.

Frequently Asked Questions about instrument-llm-analytics

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I track LLM generation costs and latency in PostHog?

Track LLM analytics costs and latency by instrumenting LLM calls to emit $ai_generation events via PostHog. This captures model, provider, input/output tokens, latency, and cost data automatically to enable end-to-end observability across your stack.

What is the best way to instrument OpenTelemetry traces for LLM calls without restructuring my architecture?

Instrument OpenTelemetry traces for LLM calls by applying PostHog instrumentation with minimal code changes. This approach auto-generates $ai_generation events without restructuring your architecture, linking traces and spans to identified users for debugging and performance optimization.

How do I associate LLM analytics events with identified users for per-user tracing?

Associate LLM analytics events with identified users by instrumenting LLM calls through PostHog. This generates $ai_generation events linked to users and traces, enabling per-user analytics, session tracking, and debugging across multiple providers and frameworks.

Does PostHog LLM analytics instrumentation work across multiple providers and frameworks?

Yes, PostHog LLM analytics instrumentation broadens coverage by supporting multiple providers and frameworks as listed in its configuration. It applies OpenTelemetry instrumentation across your codebase to capture LLM generations regardless of the specific provider used.

What environment variables and SDK setup are required to start capturing LLM generations?

Capturing LLM generations requires configuring environment variables and installing the required SDKs for PostHog and OpenTelemetry. The setup enforces environment variable configuration to enable minimal code changes for instrumenting LLM calls.

Why are my LLM traces not showing input and output token data in PostHog?

LLM traces may lack token data if environment variable configuration is incomplete or the required SDKs are not installed. Properly instrumenting LLM calls via PostHog ensures $ai_generation events capture input/output tokens, latency, and costs correctly.