Loading...
Loading...
Compare original and translation side by side
creating-an-endpointcreating-an-endpointuser_idcreating-an-endpointuser_idcreating-an-endpoint| Tool | Purpose |
|---|---|
| Full config for a named endpoint, including the query shape and required variables |
| OpenAPI 3.0 spec for one endpoint, ready to feed to a code generator |
| A live call against the endpoint — useful to confirm a payload works before sharing it with the user's app |
| 工具名称 | 用途 |
|---|---|
| 获取指定端点的完整配置,包括查询结构和必填变量 |
| 获取单个端点的OpenAPI 3.0规范,可直接用于代码生成器 |
| 对端点发起实时调用——在将请求体提供给用户应用前,可用于验证其有效性 |
/api/projects/{team_id}/endpoints/{name}/runteam_idposthog-get-projectsnameendpoints-get-all/runPOSTGET/api/projects/{team_id}/endpoints/{name}/runteam_idposthog-get-projectsnameendpoints-get-all/runPOSTGETPOSTAuthorization: Bearer <key>endpoint:readAuthorization: Bearer <key>endpoint:read{
"variables": { "code_name_1": value, "code_name_2": value },
"limit": 100,
"offset": 0,
"refresh": "cache"
}| Field | Notes |
|---|---|
| Keyed by |
| Max rows returned. |
| Skip rows. Only HogQL endpoints |
| |
endpoint-getcode_name{
"variables": { "code_name_1": value, "code_name_2": value },
"limit": 100,
"offset": 0,
"refresh": "cache"
}| 字段 | 说明 |
|---|---|
| 对于HogQL端点,键为 |
| 返回的最大行数。 |
| 跳过的行数。仅适用于HogQL端点 |
| 可选值: |
endpoint-getcode_nameendpoint-getis_materialized: trueagent-feedbackendpoint-getis_materialized: trueagent-feedbackendpoint-openapi-spec| Language | Tool | Command shape |
|---|---|---|
| TypeScript | | |
| TypeScript | | |
| Python | | |
| Go | | |
endpoint-openapi-spec| 语言 | 工具名称 | 命令格式 |
|---|---|---|
| TypeScript | | |
| TypeScript | | |
| Python | | |
| Go | | |
{
"results": [[...], [...]],
"columns": ["col_a", "col_b"],
"types": ["Int64", "String"],
"hasMore": false,
"name": "endpoint_name",
"endpoint_version": 4,
"endpoint_version_created_at": "2026-01-15T..."
}resultscolumnsendpoint_version?version=NTrendsQueryLifecycleQueryRetentionQueryFunnelsQuery{
"results": [[...], [...]],
"columns": ["col_a", "col_b"],
"types": ["Int64", "String"],
"hasMore": false,
"name": "endpoint_name",
"endpoint_version": 4,
"endpoint_version_created_at": "2026-01-15T..."
}resultscolumnsendpoint_version?version=NTrendsQueryLifecycleQueryRetentionQueryFunnelsQueryposthog-cliposthog-cli exp endpoints runposthog-cli exp endpoints {list,get,pull,push,diff}posthog-cli loginPOSTHOG_CLI_API_KEYPOSTHOG_CLI_PROJECT_IDPOSTHOG_CLI_HOSTexpposthog-cliposthog-cli exp endpoints runposthog-cli exp endpoints {list,get,pull,push,diff}posthog-cli loginPOSTHOG_CLI_API_KEYPOSTHOG_CLI_PROJECT_IDPOSTHOG_CLI_HOSTexp| Status | When | Handling |
|---|---|---|
| 400 | Missing required variable on a materialised endpoint, or invalid variable type | Surface the error message; fix the call |
| 401 | Missing / wrong personal API key | Check the Authorization header |
| 403 | Key lacks | Adjust key scopes |
| 404 | Endpoint name typo, or endpoint not active | Confirm name; check |
| 429 | Rate limited — limits are per team, not per endpoint (see note below) | Exponential backoff; cache responses client-side if possible |
| 5xx | Query execution failure (ClickHouse error, timeout, etc.) | Retry with backoff. If persistent, hand off to |
| 状态码 | 触发场景 | 处理方式 |
|---|---|---|
| 400 | 物化端点缺少必填变量,或变量类型无效 | 显示错误消息;修正调用请求 |
| 401 | 缺少/错误的个人API密钥 | 检查Authorization请求头 |
| 403 | 密钥缺少 | 调整密钥权限 |
| 404 | 端点名称拼写错误,或端点未激活 | 确认名称;检查 |
| 429 | 触发速率限制——限制是按团队而非端点设置(见下方说明) | 指数退避重试;尽可能在客户端缓存响应 |
| 5xx | 查询执行失败(ClickHouse错误、超时等) | 退避重试。若问题持续,移交至 |
execute-sqlsystem.data_modeling_endpointsendpoints-get-allendpoint-getendpoint-openapi-specendpoint-run?version=Nsystem.data_modeling_endpointsexecute-sqlendpoints-get-allendpoint-getendpoint-openapi-specendpoint-run?version=NUser: "I want to call monthly_active_users from my Node.js backend.
Can you help me wire it up with types?"
Agent steps:
- endpoint-get monthly_active_users → HogQL, variables: lookback_days
(int, default 30), org_id (string, no default), is_materialized: true
- "Two things to know upfront:
1. This endpoint is materialised, so both lookback_days and org_id
must be passed on every call. Calls without them will be rejected.
2. You'll need a personal API key with endpoint:read scope. Set it
as PH_API_KEY in your server env — never ship it in client code."
- endpoint-openapi-spec monthly_active_users → returns spec
- "Here's the spec. Drop it in your repo and run:
pnpm dlx @hey-api/openapi-ts -i spec.json -o ./generated/posthog
That gives you typed client functions.
A minimum call looks like:
POST /api/projects/12345/endpoints/monthly_active_users/run
Authorization: Bearer <PH_API_KEY>
Content-Type: application/json
{ 'variables': { 'org_id': 'acme', 'lookback_days': 30 } }
The response includes columns and rows — your client will pick that
up from the generated types.
Want me to do a sample call to verify the payload works?"用户:“我想从Node.js后端调用monthly_active_users端点。你能帮我接入并添加类型吗?”
Agent步骤:
- 调用endpoint-get monthly_active_users → 结果为HogQL类型,变量:lookback_days(整数,默认30)、org_id(字符串,无默认值),is_materialized: true
- “有两点需要提前说明:
1. 该端点已物化,因此每次调用必须同时传入lookback_days和org_id。缺少任一变量的调用都会被拒绝。
2. 你需要一个拥有endpoint:read权限的个人API密钥。将其设置为服务器环境变量PH_API_KEY——切勿将其嵌入客户端代码中。”
- 调用endpoint-openapi-spec monthly_active_users → 返回规范
- “这是规范文件。将其放入你的仓库并运行:
pnpm dlx @hey-api/openapi-ts -i spec.json -o ./generated/posthog
运行后会得到类型化的客户端函数。
最简调用示例如下:
POST /api/projects/12345/endpoints/monthly_active_users/run
Authorization: Bearer <PH_API_KEY>
Content-Type: application/json
{ 'variables': { 'org_id': 'acme', 'lookback_days': 30 } }
响应结果包含columns和rows——生成的类型会自动识别这些结构。
需要我发起一次示例调用来验证请求体是否有效吗?”?version=Ndata_freshness_secondsagent-feedback?version=Ndata_freshness_secondsagent-feedback