mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-11-02 14:31:14 +00:00
* feat: Add AI provider integration examples Add self-contained examples for each AI provider supported by @posthog/ai: - OpenAI (Chat Completions, Responses, streaming, embeddings, transcription, image generation) - Anthropic (chat, streaming) - Google Gemini (chat, streaming, image generation) - Vercel AI SDK (generateText, streamText, generateObject, streamObject, Anthropic, Google backends) - LangChain (callback handler) - Mastra (manual instrumentation workflow) - OpenTelemetry (PostHogTraceExporter) Each example directory follows the existing example-* convention with its own package.json, pnpm-workspace.yaml, tsconfig.json, and README. Files are designed to be copy-pasted by users as starting points. * fix: use subpath imports for @posthog/ai Use provider-specific subpath imports (e.g. @posthog/ai/openai instead of @posthog/ai) to avoid pulling in the OTEL dependency which fails at import time when @opentelemetry/exporter-trace-otlp-http is not installed. * fix: fix image gen, transcription, mastra, and vercel middleware - Use images.generate API instead of responses API for image generation - Gracefully skip transcription when audio file is missing - Update Mastra to v1 with correct model ID and execute signature - Fix vercel middleware crash when result.content is undefined * revert: remove vercel middleware fix from examples branch Moving this fix to a separate PR. * Add comment about incomplete tool-calling loop in examples
322 B
322 B
Mastra + PostHog AI Examples
Track Mastra agent runs with PostHog using manual instrumentation.
Setup
pnpm install
cp .env.example .env
# Fill in your API keys in .env
Examples
- workflow.ts - Mastra agent with manual PostHog event capture
Run
source .env
npx tsx workflow.ts