creating-an-endpoint
Ce qu’il fait
Cette skill vous guide pour transformer une requête ou un insight enregistré en endpoint que d'autres systèmes peuvent appeler. Elle s'adresse aux personnes qui veulent rendre les données PostHog accessibles à une application ou un pipeline externe.
Quand l’utiliser
- ✓Quand vous voulez exposer une requête PostHog comme route d'API appelable.
- ✓Quand vous voulez transformer un insight existant en endpoint pour un système externe.
- ✓Quand une nouvelle application ou un pipeline a besoin de données PostHog et que vous choisissez le mode de livraison.
Lien du skill
https://github.com/PostHog/posthog/blob/master/products/endpoints/skills/creating-an-endpoint/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Crée un endpoint qui renvoie nos utilisateurs actifs hebdomadaires pour que mon application mobile puisse l'appeler.”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
La skill passe par quelques décisions dans l'ordre : si un endpoint est le bon outil, quelles variables exposer, à quel point les données doivent être fraîches, et s'il faut stocker les résultats. Elle crée ensuite l'endpoint.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis 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
Questions fréquentes
Quand ne faut-il pas créer d'endpoint ?
Si seul votre propre tableau de bord PostHog a besoin des données, utilisez directement l'insight. Une exploration ponctuelle se fait mieux avec une requête SQL.
Que signifie la fraîcheur des données ?
Elle fixe l'âge maximal des données renvoyées avant leur recalcul. Vous arbitrez donc entre vitesse et résultats à jour.
Faut-il stocker les résultats dès le début ?
La skill vous aide à décider, en fonction du poids de la requête et de la fréquence prévue des appels.
Détails
Description originale de l’auteur
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
Popularité
- Étoiles GitHub
- 41k
- Position au classement
- #6860
- Licence
- —
- Mis à jour
- 02/11/2026
Commentaires
- …
Autres skills de ce dépôt
depot-ci
41kAide votre agent à configurer et exécuter des workflows Depot CI, alternative à GitHub Actions, en migrant les workflows existants et en lisant les journaux.
depot-container-builds
41kAide votre agent à construire des images Docker sur les constructeurs distants de Depot, y compris les images multiplateformes et la correction des échecs.
depot-github-runners
41kAide votre agent à faire tourner les jobs GitHub Actions sur les machines gérées par Depot, à choisir la taille des runners et leurs labels, et à résoudre les problèmes de configuration.
editing-agents-md
41kAide votre agent à décider si une règle doit figurer dans un fichier AGENTS.md ou CLAUDE.md, et à la rédiger pour qu'elle soit suivie sans alourdir le fichier.
Skills similaires
discrawl
394kPermet à votre agent de rechercher et de résumer une archive locale des messages Discord, de vérifier sa fraîcheur et de lire les messages privés.
clickhouse-io
280kAide votre agent à optimiser requêtes et schémas ClickHouse selon les bonnes pratiques pour les analyses hautes performances. À utiliser si les requêtes sont trop lentes.
scientific-db-pubmed-database
280kAide votre agent à rechercher des articles scientifiques dans le domaine biomédical. Utile pour les recherches nécessitant des informations médicales précises.