AI GatewayIntegrations

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.com
npm install openai
# or
yarn add openai
pip install openai
import { 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")
    },
)
You can find all supported models at corevalue.dev/models.

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)
With the above setup, any calls to Posthog will automatically be logged and monitored by CoreValue. Review them in your CoreValue dashboard.
  1. Go to your PostHog Events page
  2. Look for events with the corevalue_request event name
  3. 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!

On this page