PostHog Node AI
Initial Typescript SDK for LLM Observability
SEE FULL DOCS
Installation
npm install @posthog/ai
Usage
import { OpenAI } from '@posthog/ai'
import { PostHog } from 'posthog-node'
const phClient = new PostHog('<YOUR_PROJECT_API_KEY>', { host: 'https://us.i.posthog.com' })
const client = new OpenAI({
apiKey: '<YOUR_OPENAI_API_KEY>',
posthog: phClient,
})
const completion = await client.chat.completions.create({
model: 'gpt-3.5-turbo',
messages: [{ role: 'user', content: 'Tell me a fun fact about hedgehogs' }],
posthogDistinctId: 'user_123',
posthogTraceId: 'trace_123',
posthogProperties: { conversation_id: 'abc123', paid: true },
posthogGroups: { company: 'company_id_in_your_db' },
posthogPrivacyMode: false,
})
console.log(completion.choices[0].message.content)
await phClient.shutdown()
LLM Observability docs
Please see the main PostHog docs.
Questions?