consuming-endpoints-from-client-code
它能做什么
本技能说明如何从独立的应用(例如移动应用或服务器)调用 PostHog 端点。适合希望在自己的产品中使用 PostHog 数据的开发者。
适用场景
- ✓当你想从自己的应用或服务器调用 PostHog 端点时。
- ✓当你需要根据端点的 OpenAPI 规范生成带类型的客户端时。
- ✓当对该端点的调用因认证或速率限制错误而失败的时候。
技能链接
https://github.com/PostHog/posthog/blob/master/products/endpoints/skills/consuming-endpoints-from-client-code/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我如何从移动应用调用我的 PostHog 端点?请求是什么样子的?”
每周 5 个新技能,1 分钟读完。
工作原理
它会读取端点的配置和 OpenAPI 规范,然后说明如何发送正确的认证请求头和变量。它还可以推荐代码生成器,以构建带类型的客户端。
技术内容(原始 SKILL.md)
作者在 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_idis the project ID (numeric). Available in PostHog under project settings, or viaprojects-getif the user doesn't know it.nameis the endpoint name — seeendpoints-get-allif the user isn't sure.- The trailing
/runis 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
常见问题
这项技能会更改 PostHog 中的任何内容吗?
不会。它只帮助你从其他代码库连接到端点。
它能为任何语言生成客户端吗?
涵盖为 TypeScript、Python 和 Go 生成带类型的客户端,使用 openapi-generator 或 @hey-api/openapi-ts 等生成器。
如果调用因缺少变量而被拒绝怎么办?
本技能会说明物化端点的变量应如何构造,以确保包含所需的值。
详情
作者的原始描述
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
热度
- GitHub 星标
- 41k
- 排名
- #6858
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
depot-ci
41k帮你的智能体设置并运行 Depot CI 工作流(GitHub Actions 的替代方案),包括迁移现有工作流和读取运行日志。
depot-container-builds
41k帮你的智能体在 Depot 的远程构建器上构建 Docker 镜像,包括多平台镜像、推送到镜像仓库,以及修复构建失败。
depot-github-runners
41k帮你的智能体把 GitHub Actions 任务迁移到 Depot 托管的运行器上,选择运行器规格和标签,并排查运行器设置问题。
editing-agents-md
41k帮你的智能体判断某条规则应写入 AGENTS.md 还是 CLAUDE.md,并以不会让文件臃肿的方式写下,确保规则真正生效。