mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-10-30 18:34:19 +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
670 B
670 B
OpenAI + PostHog AI Examples
Track OpenAI API calls with PostHog.
Setup
pnpm install
cp .env.example .env
# Fill in your API keys in .env
Examples
- chat-completions.ts - Chat Completions API with tool calling
- chat-completions-streaming.ts - Chat Completions with streaming
- responses.ts - Responses API with tool calling
- responses-streaming.ts - Responses API with streaming
- embeddings.ts - Text embeddings
- transcription.ts - Audio transcription (Whisper)
- image-generation.ts - Image generation via Responses API
Run
source .env
npx tsx chat-completions.ts
npx tsx responses-streaming.ts