Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
.PHONY: setup run-trace-generator run-trace-generator-debug demo-data demo-data-quick demo-data-tools demo-data-negative
.PHONY: setup link-local-sdk run-trace-generator run-trace-generator-debug demo-data demo-data-quick demo-data-tools demo-data-negative

## Install all dependencies
setup:
@uv sync
@pnpm install

## Build & link a local @posthog/ai for unreleased SDK testing (override path with POSTHOG_JS_PATH)
link-local-sdk:
@./scripts/link_local_ai_sdk.sh

## Run the trace generator (mock trace data, no LLM calls)
run-trace-generator:
@uv run trace-generator/trace_generator.py
Expand Down
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,20 @@ uv run scripts/test_litellm.py
uv run scripts/test_langchain_otel.py
uv run scripts/test_pydantic_ai_otel.py

# Node (Vercel AI SDK)
npx tsx scripts/test_vercel_ai_otel.ts
npx tsx scripts/test_vercel_anthropic.ts
# Node — @posthog/ai
npx tsx scripts/test_posthog_ai_sdk.ts # subpath clients + captureAiGeneration
npx tsx scripts/test_vercel_ai_otel.ts # OTel via PostHogSpanProcessor
npx tsx scripts/test_vercel_anthropic.ts # withTracing (Vercel AI SDK)
```

The Node scripts read `POSTHOG_API_KEY` / `POSTHOG_HOST` from the environment.
For a local PostHog, fetch the project key first and pass it through `op run`
(which resolves the provider keys in `.env`):

```bash
KEY=$(uv run scripts/get_localhost_api_key.py -q)
POSTHOG_API_KEY="$KEY" POSTHOG_HOST=http://localhost:8010 \
op run --env-file=.env -- pnpm exec tsx scripts/test_posthog_ai_sdk.ts
```

## Local SDK Development
Expand All @@ -87,6 +98,22 @@ POSTHOG_PYTHON_PATH=../../posthog-python
POSTHOG_JS_PATH=../../posthog-js
```

### Testing unreleased `@posthog/ai`

By default `package.json` pins the **published** `@posthog/ai`, so `make setup`
works with no posthog-js checkout. To run the Node scripts against a local SDK
build instead (e.g. to validate an unreleased change), link it in:

```bash
make link-local-sdk # uses ../posthog-js
POSTHOG_JS_PATH=/path/to/posthog-js make link-local-sdk # or any location
```

`link-local-sdk` builds `@posthog/ai` (and its workspace deps, in topo order)
and rewrites `package.json` to point `@posthog/ai` + `posthog-node` at your
checkout. That edit is local-only — don't commit it. To restore the published
SDK: `git checkout -- package.json pnpm-lock.yaml && pnpm install`.

## License

MIT License - see LICENSE file for details.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
"dependencies": {
"@ai-sdk/anthropic": "^3.0.58",
"@ai-sdk/openai": "^3.0.41",
"@anthropic-ai/sdk": "^0.78.0",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.213.0",
"@opentelemetry/resources": "^2.6.0",
"@opentelemetry/sdk-node": "^0.213.0",
"@posthog/ai": "^7.12.1",
"@opentelemetry/sdk-trace-base": "^2.0.0",
"@posthog/ai": "^7.20.14",
"ai": "^6.0.116",
"dotenv": "^17.3.1",
"posthog-node": "^5.28.4",
"openai": "^6.25.0",
"posthog-node": "^5.35.14",
"zod": "^4.3.6"
},
"devDependencies": {
Expand Down
Loading