AI Observability API

The API is both how trace data gets into PostHog and how you drive AI Observability from your own code. Your app sends LLM events through the capture API, and the PostHog API exposes the rest of the product – evaluations, datasets, review queues, clustering, summarization, and provider keys – so you can wire scoring and review into CI or your own tooling instead of clicking through the app.

Before you start

  1. Set up AI Observability – install a PostHog LLM SDK or provider integration so traces are captured.
  2. Get API access – Choose a credential for the operations you need.

What you can do here

Send traces in

Everything AI Observability shows is built from events your app captures: $ai_generation for a single model call, $ai_trace for the request that wrapped it, $ai_span for the steps in between, $ai_metric for numbers you attach yourself, and $ai_feedback for what your users thought. The PostHog SDKs send these for you when you wrap your model provider, and you can also capture them manually if your setup isn't covered.

Query your trace data

The query API runs HogQL against your LLM events, so cost by model, latency percentiles, and error rates are all available without the dashboard. Prompts and completions live on the posthog.ai_events table rather than events – see the data model for which fields go where.

Run evaluations and reviews

Evaluations, their runs, and their scheduled reports are all API resources, alongside the score definitions that decide what gets scored. Datasets and dataset items, review queues, and individual trace reviews are too, so a human-review workflow can be built into your own tools.

Manage enrichment

Clustering runs and configuration, trace summarization, and custom parser recipes are all callable, so the enrichment that normally happens in the app can be triggered from a pipeline.

Configure model access

Provider keys and their validation are managed through the API, as is the list of models available to your project. There's also a hosted LLM proxy that forwards completions to your configured provider, so the playground and evaluation runs have a model to call.

Authentication

A project secret API key can manage datasets, scorers, offline experiments, and trace reviews in its project. For example, list datasets with dataset:read:

Terminal
curl -H "Authorization: Bearer $POSTHOG_PROJECT_SECRET_API_KEY" \
"https://us.posthog.com/api/projects/$POSTHOG_PROJECT_ID/datasets/"

You can also use a personal API key with your own project and resource access. Use one for dataset exports and other endpoints that require a user. Store either key on the server or in your CI secret store.

Provider keys, the credentials PostHog uses to call your model provider, are write-only through the API. You can set and validate them.

Still have questions?

Was this page useful?