# PostHog for AI agents. Managed auth, ready-made tools.

> Query product analytics, read insights and dashboards, and manage feature flags in PostHog on behalf of each of your users.

- Page: https://www.agent200.com/connectors/posthog/
- Category: Search and data
- Authentication: Managed OAuth
- Identifier in code: `posthog`
- Create an API key: https://agent200.com/platform/apikeys/
- Updated: 2026-11-18

## Instructions for AI agents

Connector: PostHog, through Agent200. In code: "posthog".
What it does: Query product analytics, read insights and dashboards, and manage feature flags in PostHog on behalf of each of your users.
Page: https://www.agent200.com/connectors/posthog/

1. Get an Agent200 API key. If the developer has none, send them to https://agent200.com/platform/apikeys/ and ask them to choose "Create an API key". Read the key from the AGENT200_API_KEY environment variable. Never ask for it in chat, and never write it into code, prompts or logs.
2. Sign-in is managed OAuth. Each end user approves access once, on PostHog's own page, through the authorization link Agent200 returns. Never ask a user for a PostHog password or token in chat.
3. Give every request a stable id for the end user. Agent200 uses only that user's own connection.
4. Read tools: posthog_run_query, posthog_list_insights, posthog_list_dashboards, posthog_list_persons, posthog_list_feature_flags. Write tools: posthog_create_feature_flag, posthog_update_feature_flag. Name "posthog" in the tools of a request; the model decides which tool to call.
5. Stay within the project's settings. If a tool is turned off or a call is refused, tell the user. Do not work around it.
6. Before a write, confirm with the user, unless they asked for that exact change.
7. For setup with a specific framework, follow its guide:
   https://www.agent200.com/connectors/posthog/framework/claude/
   https://www.agent200.com/connectors/posthog/framework/chatgpt/
   https://www.agent200.com/connectors/posthog/framework/claude-code/
   https://www.agent200.com/connectors/posthog/framework/muse/
   https://www.agent200.com/connectors/posthog/framework/grok-bot/
   https://www.agent200.com/connectors/posthog/framework/openai-dots/
   https://www.agent200.com/connectors/posthog/framework/claude-duet/
   https://www.agent200.com/connectors/posthog/framework/hermes-agent/
   https://www.agent200.com/connectors/posthog/framework/openclaw/

The code on the connector page is a conceptual example of the SDK. SDK reference: https://docs.igpt.ai/

## About

With the PostHog connector, your agent works with each user's own PostHog projects. It can run an analytics query, read insights and dashboards, look up persons and list, create or update feature flags, using only the tools your project allows.

PostHog is a product analytics platform with feature flags, session replay and experiments.

## PostHog tools

- **Run a query** (`posthog_run_query`, read): Run a HogQL query on the project's events.
- **List insights** (`posthog_list_insights`, read): List the saved insights in a project.
- **List dashboards** (`posthog_list_dashboards`, read): List the dashboards in a project.
- **List persons** (`posthog_list_persons`, read): Search and list persons.
- **List feature flags** (`posthog_list_feature_flags`, read): List the feature flags in a project.
- **Create a feature flag** (`posthog_create_feature_flag`, write): Create a new feature flag.
- **Update a feature flag** (`posthog_update_feature_flag`, write): Change a flag's rollout or turn it on or off.

## Limits you can set

**Turn single tools on or off.** Let the agent query data and read flags, and switch off `posthog_update_feature_flag` so it can never change a rollout.

**Restrict what the agent reaches.** Choose the endpoints and scopes a project may use, for example queries and insights but not feature flags. A call outside them is refused.

## Get started

### Step 1: Set up the SDK

Add the Agent200 SDK to the codebase you already have and authenticate with your API key. The key covers every connector enabled for the project.

File `agent.js`:

```js
// One Agent200 API key covers every connector enabled for the project.
const agent200 = new Agent200({
  apiKey: process.env.AGENT200_API_KEY,
});
```

(Conceptual example of the Agent200 SDK.)

### Step 2: Let your user connect PostHog

Each end user authorizes their own PostHog account once. Agent200 runs the OAuth flow, handles the callback, stores the tokens and refreshes them.

File `connect.js`:

```js
// Each end user authorizes their own PostHog account, once.
const connection = await agent200
  .user("user_123")
  .connect("posthog");

if (connection.authorizationUrl) {
  // Show this link to your user; Agent200 handles the rest.
  console.log(connection.authorizationUrl);
}
```

(Conceptual example of the Agent200 SDK.)

### Step 3: Run with the PostHog tools

Name the user, the model and the tools. The model decides which PostHog tools to call, and Agent200 executes them with that user's connection.

File `run.js`:

```js
const result = await agent200
  .user("user_123")
  .run({
    model: "openai/gpt-5.6-sol",
    input: "How many users signed up last week",
    tools: ["posthog"],
  });

console.log(result.output);
```

(Conceptual example of the Agent200 SDK.)

## Sign-in and permissions

**Who signs in.** Each of your users, once, on PostHog's own sign-in page. You never see or store their PostHog password.

**What access is requested.** The scopes the connection needs, such as reading insights or writing feature flags, listed on PostHog's authorization screen. Users can remove the app later from their PostHog account settings.

## Example requests

- "How many users signed up last week"
- "Roll out the new_checkout flag to 20 percent of users"
- "Which feature flags are turned off right now"
- "Show me the insights on my growth dashboard"

## Guides: PostHog with your AI framework

- [PostHog + Claude](https://www.agent200.com/connectors/posthog/framework/claude.md): Set up PostHog for Claude with Agent200, then check which tools are available to your agent.
- [PostHog + ChatGPT](https://www.agent200.com/connectors/posthog/framework/chatgpt.md): Set up PostHog for ChatGPT with Agent200, then check which tools are available to your agent.
- [PostHog + Claude Code](https://www.agent200.com/connectors/posthog/framework/claude-code.md): Set up PostHog for Claude Code with Agent200, then check which tools are available to your agent.
- [PostHog + Muse](https://www.agent200.com/connectors/posthog/framework/muse.md): Set up PostHog for Muse with Agent200, then check which tools are available to your agent.
- [PostHog + Grok Bot](https://www.agent200.com/connectors/posthog/framework/grok-bot.md): Set up PostHog for Grok Bot with Agent200, then check which tools are available to your agent.
- [PostHog + OpenAI Dots](https://www.agent200.com/connectors/posthog/framework/openai-dots.md): Set up PostHog for OpenAI Dots with Agent200, then check which tools are available to your agent.
- [PostHog + Claude Duet](https://www.agent200.com/connectors/posthog/framework/claude-duet.md): Set up PostHog for Claude Duet with Agent200, then check which tools are available to your agent.
- [PostHog + Hermes Agent](https://www.agent200.com/connectors/posthog/framework/hermes-agent.md): Set up PostHog for Hermes Agent with Agent200, then check which tools are available to your agent.
- [PostHog + OpenClaw](https://www.agent200.com/connectors/posthog/framework/openclaw.md): Set up PostHog for OpenClaw with Agent200, then check which tools are available to your agent.

## FAQ

### Who handles the PostHog OAuth flow and the tokens?

Agent200. It runs the authorization, handles the callback on its own domain, stores the tokens and refreshes them. You do not build or maintain an OAuth integration for PostHog.

### Does my agent act as the end user?

Within what that user authorized, yes. Every request names an end user, and Agent200 uses only that user's PostHog connection, never another user's. It cannot reach anything the user or PostHog has not authorized.

### Can I limit what my agent can do in PostHog?

Yes. You choose which services, endpoints and authorization scopes are allowed in your Agent200 configuration, and the agent works only within them.

## Related connectors

- [Tavily](https://www.agent200.com/connectors/tavily.md): Web search built for agents, reached with your Agent200 API key.
- [Exa](https://www.agent200.com/connectors/exa.md): Search the web by meaning, read page contents and find similar pages, reached with your Agent200 API key.
- [Firecrawl](https://www.agent200.com/connectors/firecrawl.md): Scrape pages into Markdown, crawl and map sites, and extract structured data, reached with your Agent200 API key.
- [Brave Search](https://www.agent200.com/connectors/brave-search.md): Search the web, news, images and videos from Brave's independent index, reached with your Agent200 API key.

---

Agent200: https://www.agent200.com/ · API keys: https://agent200.com/platform/apikeys/ · Docs: https://docs.igpt.ai/
