posthog-instrument-llm-analytics

添加 PostHog 的 LLM 分析以追踪 AI 模型使用情况,确保捕获所有生成内容(包括 token 数量、延迟和成本)。在实现 LLM 功能或审查 PR 后使用,若尚未安装则处理 PostHog SDK 的初始设置。作者:PostHog。

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "posthog-instrument-llm-analytics":https://skillpi.com/zh/skills/deepskill-466264dab6b0337d5af9cc942e4664896b55e14ca1a7bb4963bbc97bd686182b。安装前核对上游来源和版本:https://skills.sh/posthog/ai-plugin/instrument-llm-analytics。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

skills.sh

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

添加 PostHog 的 LLM 分析以追踪 AI 模型使用情况,确保捕获所有生成内容(包括 token 数量、延迟和成本)。在实现 LLM 功能或审查 PR 后使用,若尚未安装则处理 PostHog SDK 的初始设置。作者:PostHog。

0 下载

介绍来源: third_party · posthog · 1.0.0 参考来源

SkillPi 解读

实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: instrument-llm-analytics
description: >-
  Add PostHog LLM analytics 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.
metadata:
  author: PostHog

Add PostHog LLM analytics

Use this skill to add PostHog LLM analytics that trace 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 - docs
  • references/azure-openai.md - Azure openai observability installation - docs
  • references/README.md - PostHog.ai for .net
  • references/anthropic.md - Anthropic ai observability installation - docs
  • references/google.md - Google ai observability installation - docs
  • references/cohere.md - Cohere ai observability installation - docs
  • references/mistral.md - Mistral ai observability installation - docs
  • references/perplexity.md - Perplexity ai observability installation - docs
  • references/deepseek.md - Deepseek ai observability installation - docs
  • references/groq.md - Groq ai observability installation - docs
  • references/together-ai.md - Together ai observability installation - docs
  • references/fireworks-ai.md - Fireworks ai observability installation - docs
  • references/xai.md - Xai observability installation - docs
  • references/cerebras.md - Cerebras ai observability installation - docs
  • references/hugging-face.md - Hugging face ai observability installation - docs
  • references/ollama.md - Ollama ai observability installation - docs
  • references/openrouter.md - Openrouter ai observability installation - docs
  • references/langchain.md - Langchain ai observability installation - docs
  • references/llamaindex.md - Llamaindex ai observability installation - docs
  • references/crewai.md - Crewai observability installation - docs
  • references/autogen.md - Autogen ai observability installation - docs
  • references/dspy.md - Dspy ai observability installation - docs
  • references/langgraph.md - Langgraph ai observability installation - docs
  • references/pydantic-ai.md - Pydantic ai observability installation - docs
  • references/vercel-ai.md - Vercel ai SDK observability installation - docs
  • references/litellm.md - Litellm ai observability installation - docs
  • references/instructor.md - Instructor ai observability installation - docs
  • references/semantic-kernel.md - Semantic kernel ai observability installation - docs
  • references/mirascope.md - Mirascope ai observability installation - docs
  • references/mastra.md - Mastra ai observability installation - docs
  • references/smolagents.md - Smolagents ai observability installation - docs
  • references/openai-agents.md - Openai agents SDK observability installation - docs
  • references/portkey.md - Portkey ai observability installation - docs
  • references/helicone.md - Helicone ai observability installation - docs
  • references/manual-capture.md - Manual capture ai observability installation - docs
  • references/basics.md - Ai observability basics - docs
  • references/traces.md - Traces - docs
  • references/calculating-costs.md - Calculating llm costs - docs
  • 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.

当前收录版本

1.0.0

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值90/100

亮点

  • 直接解决AI模型使用情况追踪的核心任务痛点
  • 支持广泛的AI提供商和框架,适用性强
  • 显著提升开发效率和可观测性
触发精准85/100

亮点

  • 触发词精准完整,覆盖多种变体和场景
  • 边界清晰,用户容易理解何时使用
结构规范88/100

亮点

  • Phase/步骤清晰,有明确的出口条件
  • frontmatter完整,结构良好
  • 提供了详细的参考文件列表
执行可靠82/100

亮点

  • 工具来源明确,参数正确
  • 覆盖主要异常情况
  • 提供了fallback方案(manual-capture.md)
证据可验 (前四项均值)86/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

文档引用的域名或地址

这些地址可能用于文档链接或示例,不是已批准的联网清单。使用前核对实际目的地及发送的数据。

  • eu.i.posthog.com
  • us.i.posthog.com

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。