creating-an-endpoint
What it does
This skill guides you through turning a saved query or insight into an endpoint that other systems can call. It is for people who want PostHog data available to an outside app or pipeline.
When to use it
- βWhen you want to expose a PostHog query as a callable API route.
- βWhen you want to turn an existing insight into an endpoint for an outside system.
- βWhen a new app or pipeline needs PostHog data and you are choosing how to deliver it.
Skill link
https://github.com/PostHog/posthog/blob/master/products/endpoints/skills/creating-an-endpoint/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βCreate an endpoint that returns our weekly active users so my mobile app can call it.β
5 new skills a week. 1 minute to read.
How it works
It works through a few decisions in order: whether an endpoint is the right tool, which variables to expose, how fresh the data should be, and whether to store results. Then it creates the endpoint.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Creating an endpoint
This skill walks through creating a new endpoint with the right configuration. Endpoints expose saved HogQL or insight queries as callable HTTP routes β the configuration choices made at creation time determine cost, latency, and how callers integrate.
The materialisation deep-dive lives at references/materializing.md. Pull it in when the
materialisation decision is non-obvious.
When to use this skill
- "Create an endpoint for [query]"
- "Expose this insight as an API"
- "Help me turn this HogQL into a callable endpoint"
- A new caller (mobile app, customer-facing dashboard, downstream pipeline) needs PostHog data and the user is choosing how to deliver it
Decisions to make in order
1. Should this even be an endpoint?
Endpoints are right when:
- An external system (someone else's code) needs to call PostHog for data
- The query is stable β not exploratory analysis
- The shape is reusable β same query with different parameters
Endpoints are wrong when:
- An internal PostHog dashboard or insight needs the data β use the insight directly; an endpoint only adds an external API surface you don't need internally
- One-off, exploratory analysis β use the
execute-sqltool (or the SQL editor) directly
Heavy aggregation is not a reason to avoid an endpoint. Endpoints are themselves saved queries, and a heavy, frequently-called aggregation is often the best case for an endpoint with materialisation turned on.
If the user is unsure, ask what's calling the endpoint and what shape they expect.
2. Pick a name
Names are URL-safe (letters, numbers, hyphens, underscores), start with a letter, max 128 chars, must be unique within the project. Lean toward:
- Descriptive over generic β
weekly_active_users_by_orgovermetrics - Snake_case β matches how the name appears in code paths and URLs
- No version in the name β versions are managed by the endpoint itself
- No "endpoint" in the name β redundant
The name appears in the URL: /api/projects/{team_id}/endpoints/{name}/run. It's not
trivially renameable later (callers depend on the path) β get it right at creation.
3. Pick the query kind
Two options exist:
- HogQL (
HogQLQuery) β raw SQL written by the user. Variables defined via{variables.x}syntax, matched oncode_name. Recommended for new endpoints when the caller cares about the exact column shape of the response. - Insight β wraps an existing insight definition. Best supported for
TrendsQuery,LifecycleQuery, andRetentionQuery: these can be materialised, and the breakdown can act as a variable (Trends and Retention only; Lifecycle has no breakdown). Other insight kinds such asFunnelsQuerycan run inline but cannot be materialised and don't expose breakdown variables β rewrite those as HogQL if you need either.
HogQL is the more flexible choice. Pick insight only when the user is genuinely re-publishing an existing insight (see "Creating from an existing insight" below) rather than building a new query.
4. Decide which inputs become variables
Anything that should change per-caller goes in variables; the rest is hard-coded in the query.
For HogQL endpoints, variables are declared in the query payload with code_name, type,
and default. Each execution call passes { "variables": { "<code_name>": value } }.
Common patterns:
- Time windows:
date_from,date_to, or a singlelookback_daysinteger - Identity filters:
user_id,account_id,team_id - Pagination control beyond
limit/offset(these are first-class on the run endpoint already)
For insight endpoints, the breakdown property acts as the variable (Trends and Retention
only β Lifecycle has no breakdown). Pass the breakdown property name as the key. date_from /
date_to are accepted as variables only on non-materialised insight endpoints β a materialised
endpoint bakes its date range into the view, so callers can't shift the window.
Avoid:
- Variables that change the shape of the result β keep the columns stable. If callers need fundamentally different result shapes, ship separate endpoints.
- Variables that bypass safety β don't expose a
where_clausevariable that lets callers inject arbitrary SQL.
Creating from an existing insight
There's no server-side "make an endpoint from insight N" operation. To do it: read the insight's query (via the insight tools), pass that quer
FAQ
When should I not make an endpoint?
If only your own PostHog dashboard needs the data, use the insight directly. One-off exploration is better done with a SQL query.
What does data freshness mean here?
It sets how old the returned data may be before it is recalculated, so you trade speed against up-to-date results.
Should I store the results from day one?
The skill helps you decide, based on how heavy the query is and how often it will be called.
Details
Original description by the author
Create a PostHog endpoint with the right shape on the first try β covers query kind choice, name conventions, what to expose as variables (HogQL code_name vs insight breakdown), data_freshness_seconds, and whether to materialise on day one. Use when the user says "create an endpoint", "expose this query as an API", "turn this insight into an endpoint", or asks for help structuring a new endpoint. Steers away from common mistakes: materialising a query with cohort breakdowns or an ineligible compare query, inline-only variables on a materialised endpoint, unbounded date ranges, ambiguous names.
repo: PostHog/posthog
Popularity
- GitHub stars
- 41k
- Ranking position
- #6860
- License
- β
- Updated
- 11/2/2026
Comments
- β¦
More skills from this repository
depot-ci
41kHelps your agent set up and run Depot CI workflows, a GitHub Actions alternative, including migrating existing workflows and reading run logs.
depot-container-builds
41kHelps your agent build Docker images on Depot's remote builders, including multi-platform images, pushing to registries, and fixing build failures.
depot-github-runners
41kHelps your agent move GitHub Actions jobs to Depot-managed runners, choosing runner sizes and labels, and troubleshooting runner setup issues.
editing-agents-md
41kHelps your agent decide whether a rule belongs in an AGENTS.md or CLAUDE.md file, and write it so it sticks without bloating the file.
Similar skills
discrawl
394kLets your agent search and summarize a saved local archive of Discord messages, check how fresh it is, and read direct messages.
clickhouse-io
280kHelps your agent optimize queries and schemas in ClickHouse databases. It applies best practices for high-performance analytical workloads. Use when analytical queries are too slow.
scientific-db-pubmed-database
280kHelps your agent search for scientific articles in the biomedical field. It's useful for research needing specific medical information.