본문으로 건너뛰기
Skillpedia
데이터베이스41k · #6860

creating-an-endpoint

하는 일

이 스킬은 저장된 쿼리나 인사이트를 다른 시스템이 호출할 수 있는 엔드포인트로 바꾸는 과정을 안내합니다. 외부 앱이나 파이프라인이 PostHog 데이터를 쓰도록 하려는 사람을 위한 것입니다.

사용하는 경우

  • ✓PostHog 쿼리를 호출 가능한 API 경로로 노출하고 싶을 때.
  • ✓기존 인사이트를 외부 시스템용 엔드포인트로 바꾸고 싶을 때.
  • ✓새 앱이나 파이프라인에 PostHog 데이터가 필요하고 전달 방식을 고르는 중일 때.

스킬 링크

https://github.com/PostHog/posthog/blob/master/products/endpoints/skills/creating-an-endpoint/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/PostHog/posthog/blob/master/products/endpoints/skills/creating-an-endpoint/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“모바일 앱에서 호출할 수 있도록, 주간 활성 사용자를 반환하는 엔드포인트를 만들어 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

몇 가지 결정을 순서대로 거칩니다. 엔드포인트가 적합한 도구인지, 어떤 변수를 노출할지, 데이터가 얼마나 최신이어야 하는지, 결과를 저장할지입니다. 그다음 엔드포인트를 만듭니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 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-sql tool (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_org over metrics
  • 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 on code_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, and RetentionQuery: these can be materialised, and the breakdown can act as a variable (Trends and Retention only; Lifecycle has no breakdown). Other insight kinds such as FunnelsQuery can 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 single lookback_days integer
  • 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_clause variable 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

자주 묻는 질문

언제 엔드포인트를 만들면 안 되나요?

사용자 자신의 PostHog 대시보드만 데이터가 필요하다면 인사이트를 직접 쓰세요. 일회성 탐색은 SQL 쿼리가 더 낫습니다.

데이터 최신성은 무엇을 뜻하나요?

반환되는 데이터가 다시 계산되기 전에 얼마나 오래되어도 되는지를 정하므로, 속도와 최신 결과 사이에서 선택하게 됩니다.

첫날부터 결과를 저장해야 하나요?

스킬은 쿼리가 얼마나 무거운지와 얼마나 자주 호출될지를 바탕으로 결정하도록 돕습니다.

상세 정보

작성자의 원본 설명

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

인기도

GitHub 스타
41k
순위
#6860
라이선스
—
업데이트
2026. 11. 2.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬