PostHog Integration
Integrate CoreValue AI Gateway with PostHog to automatically export LLM request events to your PostHog analytics platform for unified product analytics.
Legacy / Unsupported. The Cova-Posthog-Key and Cova-Posthog-Host
request headers were supported by the legacy Cloudflare Worker proxy. They
are not read by the current AI Gateway (gateway/src/) and sending them
has no effect. To export LLM request events to PostHog, use the
Webhooks feature to forward gateway events to your own
integration layer. See the
Header Directory
for the full list of unsupported headers.
Introduction
PostHog is a comprehensive product analytics platform that helps you understand user behavior and product performance.
How to Integrate
Sign up at corevalue.dev and generate an API key.
Create a Posthog account if you don't have one. Get your Project API Key from your PostHog project settings.
COVA_API_KEY=sk-cova-XXXXXXXXXXXXXXXX
POSTHOG_PROJECT_API_KEY=phc_...
# Optional: PostHog host (defaults to https://app.posthog.com)
# Only needed if using a custom PostHog host
# POSTHOG_CLIENT_API_HOST=https://app.posthog.comnpm install openai
# or
yarn add openaipip install openaiimport { OpenAI } from "openai";
import dotenv from "dotenv";
dotenv.config();
const client = new OpenAI({
baseURL: "https://gateway.corevalue.dev/v1",
apiKey: process.env.COVA_API_KEY,
defaultHeaders: {
"Cova-Posthog-Key": POSTHOG_PROJECT_API_KEY,
"Cova-Posthog-Host": POSTHOG_CLIENT_API_HOST
},
});import os
from openai import OpenAI
from dotenv import load_dotenv
load_dotenv()
client = OpenAI(
base_url="https://gateway.corevalue.dev/v1",
api_key=os.getenv("COVA_API_KEY"),
default_headers={
"Cova-Posthog-Key": os.getenv("POSTHOG_PROJECT_API_KEY"),
"Cova-Posthog-Host": os.getenv("POSTHOG_CLIENT_API_HOST")
},
)Your existing OpenAI code continues to work without any changes. Events will automatically be exported to PostHog.
const response = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello, world!" }],
temperature: 0.7,
});
console.log(response.choices[0]?.message?.content); response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello, world!"}],
temperature=0.7,
)
print("Completion:", response.choices[0].message.content)- Go to your PostHog Events page
- Look for events with the
corevalue_requestevent name - Each event contains metadata about the LLM request including:
- Model used
- Token counts
- Latency
- Cost
- Request/response data
While you're here, why not give us a star on GitHub? It helps us a lot!
Request a CoreValue Integration
Looking for a framework or tool not listed here? Request it here!