---
title: "PostHog"
description: "Forward Respan LLM events to PostHog via the gateway for product analytics and observability."
---

[PostHog](https://posthog.com/) 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.

<Accordion title="Set up Respan">
Create an account at [platform.respan.ai](https://platform.respan.ai) and grab an [API key](https://platform.respan.ai/platform/gateway/api-keys). For gateway, also add [credits](https://platform.respan.ai/platform/gateway/credits) or a [provider key](https://platform.respan.ai/platform/gateway/api-keys?providers=1).
</Accordion>

<Tabs>
<Tab title="Gateway">

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

Paste this into your coding agent:

```text
Help me set up Respan tracing with the PostHog integration.
Follow https://www.respan.ai/docs/integrations/posthog.md
```

## Setup

<Steps>
<Step title="Create your PostHog account">

Go to [PostHog](https://posthog.com/) and create an account. From your [PostHog project settings](https://us.posthog.com/settings/project), grab your PostHog API key and host.

</Step>

<Step title="Set environment variables">

```bash
export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
export POSTHOG_API_KEY="YOUR_POSTHOG_API_KEY"
```

</Step>

<Step title="Add posthog_integration to your request body">

```python
import os
import requests

response = requests.post(
    "https://api.respan.ai/api/chat/completions",
    headers={
        "Content-Type": "application/json",
        "Authorization": f"Bearer {os.environ['RESPAN_API_KEY']}",
    },
    json={
        "model": "gpt-4.1-nano",
        "messages": [{"role": "user", "content": "Hello"}],
        "posthog_integration": {
            "posthog_api_key": os.environ["POSTHOG_API_KEY"],
            "posthog_base_url": "https://us.posthog.com",
        },
    },
)
print(response.json())
```

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

</Step>

<Step title="Use the Respan template in PostHog">

Use the [official Respan template in PostHog](https://us.posthog.com/shared/p1AymhS7EEm97nZOGA8nWmsdshhzYA) to create a dashboard for monitoring LLM performance.

</Step>
</Steps>

</Tab>
</Tabs>
