Skip to main content
skill CX Codex

llm-analytics-setup — Claude Code skill: PostHog LLM analytics

llm-analytics-setup adds PostHog LLM analytics to an app running on any supported provider, tracking tokens, latency and cost for every generation.

MIT 120 installs ★ 80 updated 2026-10-24

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add PostHog/skills --skill llm-analytics-setup -a claude-code
Open on GitHub

What llm-analytics-setup does

The skill instruments LLM calls in your app and sends them to PostHog: input and output tokens, which model answered, how long it took, what it cost. Your existing provider calls stay where they are, the analytics goes alongside.

A references folder holds one doc per stack: OpenAI, Azure OpenAI, Anthropic, Google, Mistral, Groq, Ollama, OpenRouter, LangChain, LlamaIndex, DSPy, LiteLLM, Vercel AI SDK, Portkey, Helicone and more. The agent opens the file that matches your code and works through it, from SDK install to config to example calls. Anything missing from that list falls back to manual-capture.md, a generic event capture route.

You need the posthog Python package (pip install posthog) and keys kept in environment variables, since hardcoding them is off the table. In a CLI or a script, skipping posthog.shutdown() before exit loses every event. Emails, names and phone numbers do not belong in capture() properties. Use set(distinct_id=...) for those, as the Python SDK has no identify().

What it helps with

  • instrument an app that already calls OpenAI or Anthropic, without rewriting it
  • work out the cost of each LLM call from token counts
  • attach generations to signed-in users by distinct ID
  • find setup steps for LangChain, DSPy or LiteLLM without guessing
  • keep personal data out of capture() events

Example prompts for the agent

  • Add PostHog LLM analytics to our service that calls the Anthropic API, reading keys from env vars.
  • Our agent runs on LangGraph. Instrument the generations with token counts and cost.
  • Check that no user emails or names end up in capture() properties.

How to install llm-analytics-setup

1Skills CLI (Vercel)

npx skills add PostHog/skills --skill llm-analytics-setup -a claude-code

2Manually: put the files in place

~/.claude/skills/llm-analytics-setup/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/llm-analytics-setup/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about llm-analytics-setup

How do I install llm-analytics-setup in Claude Code?

Run npx skills add PostHog/skills --skill llm-analytics-setup -a claude-code. The skill lands at ~/.claude/skills/llm-analytics-setup/SKILL.md.

What does llm-analytics-setup do?

It wires PostHog tracking into your LLM calls: input and output tokens, model name, latency and cost, tied back to identified users.

What if my provider is not in the list?

The skill uses references/manual-capture.md instead, which describes a generic event capture approach that works with any provider.

Source text

SKILL.md · MIT
---
name: llm-analytics-setup
description: PostHog LLM analytics for all supported providers
metadata:
  author: PostHog
  version: 1.9.4
---

# PostHog LLM analytics

This skill helps you add PostHog LLM analytics to any application using AI/LLM providers.

## Reference files

- `references/openai.md` - Openai llm analytics installation - docs
- `references/azure-openai.md` - Azure openai llm analytics installation - docs
- `references/anthropic.md` - Anthropic llm analytics installation - docs
- `references/google.md` - Google llm analytics installation - docs
- `references/cohere.md` - Cohere llm analytics installation - docs
- `references/mistral.md` - Mistral llm analytics installation - docs
- `references/perplexity.md` - Perplexity llm analytics installation - docs
- `references/deepseek.md` - Deepseek llm analytics installation - docs
- `references/groq.md` - Groq llm analytics installation - docs
- `references/together-ai.md` - Together ai llm analytics installation - docs
- `references/fireworks-ai.md` - Fireworks ai llm analytics installation - docs
- `references/xai.md` - Xai llm analytics installation - docs
- `references/cerebras.md` - Cerebras llm analytics installation - docs
- `references/hugging-face.md` - Hugging face llm analytics installation - docs
- `references/ollama.md` - Ollama llm analytics installation - docs
- `references/openrouter.md` - Openrouter llm analytics installation - docs
- `references/langchain.md` - Langchain llm analytics installation - docs
- `references/llamaindex.md` - Llamaindex llm analytics installation - docs
- `references/crewai.md` - Crewai llm analytics installation - docs
- `references/autogen.md` - Autogen llm analytics installation - docs
- `references/dspy.md` - Dspy llm analytics installation - docs
- `references/langgraph.md` - Langgraph llm analytics installation - docs
- `references/pydantic-ai.md` - Pydantic ai llm analytics installation - docs
- `references/vercel-ai.md` - Vercel ai SDK llm analytics installation - docs
- `references/litellm.md` - Litellm llm analytics installation - docs
- `references/instructor.md` - Instructor llm analytics installation - docs
- `references/semantic-kernel.md` - Semantic kernel llm analytics installation - docs
- `references/mirascope.md` - Mirascope llm analytics installation - docs
- `references/mastra.md` - Mastra llm analytics installation - docs
- `references/smolagents.md` - Smolagents llm analytics installation - docs
- `references/openai-agents.md` - Openai agents SDK llm analytics installation - docs
- `references/portkey.md` - Portkey llm analytics installation - docs
- `references/helicone.md` - Helicone llm analytics installation - docs
- `references/manual-capture.md` - Manual capture llm analytics installation - docs
- `references/basics.md` - Llm analytics basics - docs
- `references/traces.md` - Traces - docs
- `references/calculating-costs.md` - Calculating llm costs - docs

Each provider reference contains installation instructions, SDK setup, and code examples specific to that provider or framework. Find the reference that matches the user's stack and follow its instructions.

If the user's provider isn't listed, use `manual-capture.md` as a fallback — it covers the generic event capture approach that works with any provider.

## Key principles

- **Environment variables**: Always use environment variables for PostHog and LLM provider keys. Never hardcode them.
- **Minimal changes**: Add LLM analytics alongside existing LLM calls. Don't replace or restructure existing code.
- **Trace all generations**: Capture input tokens, output tokens, model name, latency, and costs for every LLM call.
- **Link to users**: Associate LLM generations with identified users via distinct IDs when possible.
- **One provider at a time**: Only instrument the provider(s) the user is actually using. Don't add instrumentation for providers not present in the codebase.

## Framework guidelines

- Remember that source code is available in the venv/site-packages directory
- posthog is the Python SDK package name
- Install dependencies with `pip install posthog` or `pip install -r requirements.txt` and do NOT use unquoted version specifiers like `>=` directly in shell commands
- In CLIs and scripts: MUST call posthog.shutdown() before exit or all events are lost
- Always use the Posthog() class constructor (instance-based API) instead of module-level posthog.api_key config
- Always include enable_exception_autocapture=True in the Posthog() constructor to automatically track exceptions
- NEVER send PII in capture() event properties — no emails, full names, phone numbers, physical addresses, IP addresses, or user-generated content
- PII belongs in identify() person properties, NOT in capture() event properties. Safe event properties are metadata like message_length, form_type, boolean flags.
- Register posthog_client.shutdown with atexit.register() to ensure all events are flushed on exit
- The Python SDK has NO identify() method — use posthog_client.set(distinct_id=user_id, properties={...}) to set person properties, or use identify_context(user_id) within a context

© PostHog · MIT · PostHog/skills

Similar skills

All skills for AI and ML →
product-analytics-setup rampstackco product-analytics-setup — a skill for instrumenting product analytics correctly through clean event taxonomies, property schemas, and funnels. It prevents untrusted metrics when shipping features. CX Codex +1 285installs setup-agent-analytics Pendo setup-agent-analytics finds AI agents in your codebase and instruments them with Pendo Agent Analytics through Python SDK, TypeScript SDK, client-side trackAgent(), or Conversations API. ★ 2repo stars llm-public-opinion-analytics-assistant reason-machines llm-public-opinion-analytics-assistant is a Claude Code skill that crawls trends from 15 platforms, clusters themes, and analyzes sentiment with an LLM. It sends results to Telegram, email, or WeChat. CX Codex +1 2,400installs llm-intelligent-public-opinion-analytics reason-machines llm-intelligent-public-opinion-analytics is a Claude Code skill that deploys a crawler for trending lists on Weibo, Bilibili, Zhihu, Baidu and other services, with topic analysis and notifications. CX Codex +1 2,100installs observability-llm-obs elastic observability-llm-obs reads LLM telemetry that already sits in Elastic and answers questions about latency, errors, token spend, guardrail hits and agent call chains. CX Codex +1 4,400installs signals-scout-product-analytics PostHog signals-scout-product-analytics — a skill for Claude Code and Codex monitoring core product analytics flows in PostHog. Detects derived-rate regressions across funnels and retention while entrant volume holds steady. CX Codex +1 204installs

From the same set112

The whole set →
feature-flags-nextjs feature-flags-nextjs puts PostHog feature flags into a Next.js app: checks inside components, evaluation on the server, and flag management from chat when the PostHog MCP server is connected. CX Codex +1 140installs writing-simplified-technical-english writing-simplified-technical-english rewrites English prose to the ASD-STE100 controlled-language standard: one meaning per word, active voice, short sentences. Built for reports, PR descriptions and prompts. CX Codex +1 138installs integration-javascript_node integration-javascript_node adds PostHog analytics to a server-side Node.js app with posthog-node: events in route handlers, user identification, exception tracking. CX Codex +1 131installs integration-javascript_web integration-javascript_web guides client-side PostHog setup in browser JavaScript apps using posthog-js. CX Codex +1 125installs experiment-audit The experiment-audit Claude Code skill checks a PostHog experiment's setup, variant data, attribution, and metrics. It runs on requests to review or validate an A/B test. CX Codex +1 118installs error-tracking-web error-tracking-web adds PostHog error tracking to a JavaScript web app: exception capture, source maps, alerts and issue triage, with the agent editing your code. CX Codex +1 116installs monthly-to-annual The monthly-to-annual Claude Code skill evaluates a PostHog customer’s move from monthly billing to an annual prepaid credit plan. It produces a discount briefing and a plain-text Slack draft. CX Codex +1 115installs feature-flags-web The feature-flags-web skill helps add PostHog feature flags to JavaScript web apps. Use it for boolean checks, server-side evaluation, and flag management through MCP. CX Codex +1 114installs

Project sponsors

Companies that keep this analytics open