Instrument Llm Analytics logo

Instrument Llm Analytics

Organization
PostHog
instrument-llm-analytics

Add PostHog AI Observability to trace AI model usage. Use after implementing LLM features or reviewing PRs to ensure all generations are captured with token counts, latency, and costs. Also handles initial PostHog SDK setup if not yet installed.

Overview

PublisherPostHog
Repositoryskills
Skill nameinstrument-llm-analytics
Stars
77
Forks
8
Bundled files
38
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 38 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by PostHog on GitHub. Read the source before you install it.

Installation

Install the Instrument Llm Analytics AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/PostHog/skills/tree/main/skills/omnibus/instrument-llm-analytics
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/PostHog/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/skills/omnibus/instrument-llm-analytics .claude/skills/instrument-llm-analytics
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Instrument Llm Analytics in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Instrument Llm Analytics on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Instrument Llm Analytics is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Add PostHog AI Observability

Use this skill to add PostHog AI Observability that traces AI model usage in new or changed code. Use it after implementing LLM features or reviewing PRs to ensure all generations are captured with token counts, latency, and costs. If PostHog is not yet installed, this skill also covers initial SDK setup. Supports any provider or framework.

Supported providers: OpenAI, Azure OpenAI, Anthropic, Google, Cohere, Mistral, Perplexity, DeepSeek, Groq, Together AI, Fireworks AI, xAI, Cerebras, Hugging Face, Ollama, OpenRouter.

Supported frameworks: LangChain, LlamaIndex, CrewAI, AutoGen, DSPy, LangGraph, Pydantic AI, Vercel AI, LiteLLM, Instructor, Semantic Kernel, Mirascope, Mastra, SmolAgents, OpenAI Agents.

Proxy/gateway: Portkey, Helicone.

Instructions

Follow these steps IN ORDER:

STEP 1: Analyze the codebase and detect the LLM stack.

  • Look for LLM provider SDKs (openai, anthropic, google-generativeai, etc.) and AI frameworks (langchain, llamaindex, crewai, etc.) in dependency files and imports.
  • Look for lockfiles to determine the package manager.
  • Check for existing PostHog or observability setup. If PostHog is already installed and LLM tracing is configured, skip to STEP 4 to add tracing for any new LLM calls.

STEP 2: Research instrumentation. (Skip if PostHog LLM tracing is already set up.) 2.1. Find the reference file below that matches the detected provider or framework — it is the source of truth for callback setup, middleware configuration, and event capture. Read it now. 2.2. If no reference matches, use manual-capture.md as a fallback — it covers the generic event capture approach that works with any provider.

STEP 3: Install the PostHog SDK. (Skip if PostHog is already set up.)

  • Add the PostHog SDK and any required callback/integration packages.
  • Do not manually edit dependency files — use the package manager's install command.

STEP 4: Add LLM tracing.

  • Instrument LLM calls to capture input tokens, output tokens, model name, latency, and costs for every generation.
  • Follow the provider-specific reference for the exact callback/middleware setup.
  • Do not alter the fundamental architecture of existing files. Make additions minimal and targeted.
  • You must read a file immediately before attempting to write it.

STEP 5: Link to users.

  • Associate LLM generations with identified users via distinct IDs when possible.

STEP 6: Set up environment variables.

  • Check if the project already has PostHog environment variables configured (e.g. in .env, .env.local, or framework-specific env files). If valid values already exist, skip this step.
  • If the PostHog project token is missing, use the PostHog MCP server's projects-get tool to retrieve the project's api_token. If multiple projects are returned, ask the user which project to use. If the MCP server is not connected or not authenticated, ask the user for their PostHog project token instead.
  • For the PostHog host URL: check the projects-get MCP response for a region field — US maps to https://us.i.posthog.com, EU maps to https://eu.i.posthog.com. If the region is not available from the MCP response or from existing project configuration, ask the user: "Are you on PostHog US Cloud or EU Cloud?" Do not assume US Cloud.
  • Write these values to the appropriate env file using the framework's naming convention.
  • Reference these environment variables in code instead of hardcoding them.

Reference files

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

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.

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.

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Instrument Llm Analytics AI skill do?

Add PostHog AI Observability to trace AI model usage. Use after implementing LLM features or reviewing PRs to ensure all generations are captured with token counts, latency, and costs. Also handles initial PostHog SDK setup if not yet installed.

Why use Instrument Llm Analytics on TypingMind?

Because you install it once and use it with any model. Instrument Llm Analytics is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Instrument Llm Analytics in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/PostHog/skills/tree/main/skills/omnibus/instrument-llm-analytics. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Instrument Llm Analytics?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Instrument Llm Analytics?

As many as you like. As long as a model supports skills, you can use Instrument Llm Analytics with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Instrument Llm Analytics AI skill free?

Yes. It is published on GitHub by PostHog under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇