consuming-endpoints-from-client-code

Integrates PostHog endpoints into client applications with typed clients and correct authentication.

713|118|Updated Aug 11, 2020
One-click install
npx skills add https://github.com/PostHog/posthog-foss --skill consuming-endpoints-from-client-code
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: consuming-endpoints-from-client-code
Source: https://github.com/PostHog/posthog-foss/tree/main/products/endpoints/skills/consuming-endpoints-from-client-code
Command: npx skills add https://github.com/PostHog/posthog-foss --skill consuming-endpoints-from-client-code

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Calling a PostHog endpoint from an external app involves several easy-to-get-wrong details: the correct URL shape, personal API key auth with the right scope, the variables payload format, and error handling for rate limits and materialised endpoints. This Skill walks through each of these so client integrations work on the first attempt.

Core Features & Use Cases

  • Typed client generation: Fetches the endpoint's OpenAPI 3.0 spec and guides generation of TypeScript, Python, or Go clients using @hey-api/openapi-ts, openapi-generator-cli, or oapi-codegen.
  • Auth and payload guidance: Explains the Bearer personal API key header, required endpoint:read scope, and how to shape the variables payload for HogQL versus insight breakdown endpoints.
  • Error handling playbook: Maps 400/401/403/404/429/5xx responses to concrete fixes, including the rule that materialised endpoints require every declared variable.
  • Use Case: A developer wants to call a monthly_active_users endpoint from a Node.js backend. The Skill retrieves the endpoint config, confirms it is materialised (so all variables are mandatory), hands over the OpenAPI spec for client generation, and provides a working sample POST request.

Quick Start

Ask the agent to help you call your PostHog endpoint from your app, for example: "Help me wire up the monthly_active_users endpoint in my Node.js backend with a typed client."

Frequently Asked Questions about consuming-endpoints-from-client-code

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I call a PostHog endpoint from my app?

Send a POST request to /api/projects/{team_id}/endpoints/{name}/run with an Authorization: Bearer header containing a personal API key. Put variables in the JSON body, and use the endpoint-get tool first to see the exact variable names and types required.

How do I generate a typed TypeScript client for a PostHog endpoint?

Fetch the endpoint's OpenAPI 3.0 spec with endpoint-openapi-spec, then run a generator such as @hey-api/openapi-ts or openapi-generator-cli against it. Regenerate the client whenever the endpoint's query changes, since new versions may alter variables.

What auth header does a PostHog endpoint require?

Endpoints use a personal API key sent as Authorization: Bearer <key>, and the key needs at least the endpoint:read scope. A 401 means the key is missing or malformed, while a 403 means the scope is missing. Never ship personal API keys in browser or mobile client code.

Why does my endpoint return 400 after materialisation was enabled?

Materialised endpoints require every declared variable on each call as a security boundary, so omitting any variable returns a 400 listing the missing ones. The fix is in the request payload, not the endpoint configuration.

How are PostHog endpoint rate limits structured?

Rate limits are per team, not per endpoint. Non-materialised endpoints share the team-wide API query budget of roughly 240 requests per minute, while materialised endpoints use a separate higher bucket around 1200 per minute. Handle 429 responses with exponential backoff.