Aller au contenu
Skillpedia
API et serveurs (backend)41k · #6858

consuming-endpoints-from-client-code

Ce qu’il fait

Cette skill montre comment appeler un endpoint PostHog depuis une application séparée, comme une application mobile ou un serveur. Elle s'adresse aux développeurs qui veulent utiliser les données PostHog dans leur propre produit.

Quand l’utiliser

  • ✓Quand vous voulez appeler un endpoint PostHog depuis votre propre application ou serveur.
  • ✓Quand vous avez besoin de générer un client typé à partir de la spécification OpenAPI de l'endpoint.
  • ✓Quand un appel à l'endpoint échoue avec une erreur d'authentification ou de limitation de débit.

Lien du skill

https://github.com/PostHog/posthog/blob/master/products/endpoints/skills/consuming-endpoints-from-client-code/SKILL.md

Copiez-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

Utilise ce skill pour m’aider : https://github.com/PostHog/posthog/blob/master/products/endpoints/skills/consuming-endpoints-from-client-code/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Comment appeler mon endpoint PostHog depuis mon application mobile, et à quoi ressemble la requête ?”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

La skill lit la configuration de l'endpoint et sa spécification OpenAPI, puis montre comment envoyer le bon en-tête d'authentification et les bonnes variables. Elle peut aussi suggérer un générateur de code pour construire un client typé.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis GitHub.

Consuming endpoints from client code

This skill is the caller-side counterpart to creating-an-endpoint. It helps integrate an existing endpoint into a separate codebase — a mobile app, server backend, customer dashboard, or downstream pipeline. No PostHog code is modified here.

When to use this skill

  • "How do I call my endpoint?" / "What does a request look like?"
  • "Generate a typed TypeScript / Python / Go client for this endpoint"
  • "I'm getting a 401 calling the endpoint" / auth questions
  • "The endpoint rejects my call when I omit user_id" → materialised-endpoint variable questions
  • "How do I handle rate limits?"

If the user is creating the endpoint, use creating-an-endpoint first.

Available tools

Tool Purpose
endpoint-get Full config for a named endpoint, including the query shape and required variables
endpoint-openapi-spec OpenAPI 3.0 spec for one endpoint, ready to feed to a code generator
endpoint-run A live call against the endpoint — useful to confirm a payload works before sharing it with the user's app

The endpoint URL

/api/projects/{team_id}/endpoints/{name}/run
  • team_id is the project ID (numeric). Available in PostHog under project settings, or via projects-get if the user doesn't know it.
  • name is the endpoint name — see endpoints-get-all if the user isn't sure.
  • The trailing /run is required.

POST is the canonical method. GET also works for simple cases without a request body but POST is preferred — variables go in the body.

Auth

Endpoints are authenticated with a personal API key. The header is:

Authorization: Bearer <key>

Keys are scoped — for endpoints, the key needs at least endpoint:read. If the user gets a 403, they're usually missing the scope; if they get a 401, the key is missing or malformed.

Never put a personal API key in client-side code that's shipped to end users (mobile apps, browser JS). Personal API keys grant scoped account access. For customer-facing apps, route through the user's own backend, which holds the key.

The request payload

{
  "variables": { "code_name_1": value, "code_name_2": value },
  "limit": 100,
  "offset": 0,
  "refresh": "cache"
}
Field Notes
variables Keyed by code_name for HogQL endpoints; for insight endpoints with breakdowns, key is the breakdown property name
limit Max rows returned.
offset Skip rows. Only HogQL endpoints
refresh "cache" (return cached results if fresh enough), "force" (always recalculate), "direct" (bypass materialisation, materialised endpoints only). Default is "cache"

Call endpoint-get to see the exact variable shape. The response includes the query definition with declared variables — each variable's code_name is what the client should send.

Materialised endpoints: all variables are required

If endpoint-get shows is_materialized: true on the current version, the endpoint requires every declared variable to be passed on each call. This is a security boundary — without filters, a single call would return the entire pre-aggregated dataset.

Common symptom: the user's app worked when the endpoint was unmaterialised, then started returning 400 errors after materialisation was enabled. The error message lists which variables are missing.

Optional/partial variables on materialised endpoints are a known limit

Questions fréquentes

Cette skill modifie-t-elle quelque chose dans PostHog ?

Non. Elle vous aide seulement à vous connecter à un endpoint depuis une autre base de code.

Peut-elle générer un client dans n'importe quel langage ?

Elle couvre la génération de clients typés pour TypeScript, Python et Go, à l'aide de générateurs comme openapi-generator ou @hey-api/openapi-ts.

Que faire si mon appel est rejeté parce qu'une variable manque ?

La skill explique comment les variables doivent être structurées pour les endpoints matérialisés, afin que les valeurs requises soient incluses.

Détails

Description originale de l’auteur

Wire a PostHog endpoint into a client app or SDK. Covers fetching the OpenAPI spec, generating a typed client with openapi-generator or @hey-api/openapi-ts, sending the right auth header, shaping the variables payload (HogQL code_name vs insight breakdown property), handling rate-limit and materialised-endpoint error responses. Use when the user says "how do I call my endpoint", "generate a client for this", or "what auth header do I use".

repo: PostHog/posthog

Popularité

Étoiles GitHub
41k
Position au classement
#6858
Licence
—
Mis à jour
02/11/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires