PostHog

PostHog is an open-source product analytics platform. Connect it with Respan to forward LLM call events to PostHog and monitor LLM performance alongside your product analytics.

Create an account at platform.respan.ai and grab an API key. For gateway, also add credits or a provider key.

Run npx @respan/cli setup to set up with your coding agent.

The PostHog integration runs through the Respan gateway. Pass your PostHog credentials in posthog_integration and Respan forwards LLM events to your PostHog project.

Setup

1

Create your PostHog account

Go to PostHog and create an account. From your PostHog project settings, grab your PostHog API key and host.

2

Set environment variables

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
$export POSTHOG_API_KEY="YOUR_POSTHOG_API_KEY"
3

Add posthog_integration to your request body

1import os
2import requests
3
4response = requests.post(
5 "https://api.respan.ai/api/chat/completions",
6 headers={
7 "Content-Type": "application/json",
8 "Authorization": f"Bearer {os.environ['RESPAN_API_KEY']}",
9 },
10 json={
11 "model": "gpt-4.1-nano",
12 "messages": [{"role": "user", "content": "Hello"}],
13 "posthog_integration": {
14 "posthog_api_key": os.environ["POSTHOG_API_KEY"],
15 "posthog_base_url": "https://us.posthog.com",
16 },
17 },
18)
19print(response.json())

The posthog_base_url is usually https://us.posthog.com or https://eu.posthog.com.

4

Use the Respan template in PostHog

Use the official Respan template in PostHog to create a dashboard for monitoring LLM performance.