downloading-batch-export-files

작성자: posthog

PostHog 이벤트, 사용자 또는 세션을 요청 시 내보내고 결과 파일을 다운로드합니다. 사용자가 원시 PostHog 데이터를 다운로드/내보내거나 생성하도록 요청할 때 사용합니다.

npx skills add https://github.com/posthog/ai-plugin --skill downloading-batch-export-files

Downloading batch export files

Use this skill when a user wants a one-off downloadable export of PostHog data. The export is started and monitored through MCP, but the final file download uses the existing REST endpoint directly.

Available MCP tools

ToolPurpose
posthog:file-download-batch-exports-createStart an on-demand export and return the run ID
posthog:file-download-batch-exports-retrievePoll the run status and return file IDs after completion

Do not rely on a generated MCP tool for the /download/ endpoint. That endpoint is a redirecting file download endpoint, so raw HTTP/download handling is the right interface until MCP has explicit redirect support.

Workflow

1. Choose the export shape

Ask a short clarifying question if the user did not specify the required inputs:

  • model: one of events, persons, sessions, or hogql
  • data_interval_start and data_interval_end: ISO 8601 datetimes; the range must be at most one week. Required for events, persons, and sessions, and not supported for hogql
  • file.format: Parquet or JSONLines; prefer Parquet for compact analytics exports and JSONLines for line-oriented text processing
  • file.compression: optional, one of zstd, gzip, brotli, lz4, or snappy. If JSONLines was chosen as format, only gzip and brotli are supported.
  • file.max_size_mb: part size in MiB, 1024 by default. A part can go a little over this size. Lower it when the user wants smaller parts, raise it for fewer and bigger ones, or set it to null to write a single file of any size.

For events, include and exclude are optional event-name filters. Use them only when the user asks for specific events or wants to omit specific events.

For hogql, pass the query as hogql_query and leave out data_interval_start, data_interval_end, include, and exclude. The query runs as of the time the export starts, so there is no interval to choose. You may prompt the user to export a slice of data by including a WHERE clause in the HogQL query, for example limiting results from the events table by bounding timestamp. Always prefer limiting the data exported to the minimum necessary to solve the user's request. Every column in the SELECT clause must be a field or have an alias, and placeholders are not supported. This model is in closed beta and is enabled per team.

2. Start the export

Call posthog:file-download-batch-exports-create with the selected shape. The response contains an id for the export run.

Example request:

{
  "model": "events",
  "file": {
    "format": "JSONLines",
    "compression": "gzip"
  },
  "include": ["$pageview"],
  "data_interval_start": "2026-05-25T00:00:00Z",
  "data_interval_end": "2026-05-26T00:00:00Z"
}

Example request for the hogql model:

{
  "model": "hogql",
  "file": {
    "format": "Parquet"
  },
  "hogql_query": "SELECT event, timestamp, properties.$current_url AS url FROM events WHERE timestamp > now() - INTERVAL 1 HOUR"
}

3. Poll until completion

Call posthog:file-download-batch-exports-retrieve with the returned id.

Status handling:

StatusAction
Starting or RunningWait briefly and poll again
CompletedRead the files array and download each file
CancelledStop and report that the run was cancelled
Failed, FailedRetryable, FailedBilling, Terminated, or TimedOutStop and report the error field

When Completed, the files array contains file UUIDs. For single-file exports it usually contains one UUID. For split exports, download every UUID unless the user asked for a specific part.

A Completed response also carries records_completed, the number of rows the run exported. Report it to the user, because the count is otherwise only visible by opening every file.

4. Optionally, cancel a running export

If required by the user, a running export can be cancelled by calling posthog:file-download-batch-exports-cancel-create with the returned id.

An export that has already finished or has already failed may not be cancelled.

After cancelling an export, the id may not be used anymore and the export must start again from the beginning. However, you may still use the id to retrieve the export status (which will always be Cancelled).

5. Download files through REST

Use a direct authenticated HTTP request to the existing endpoint:

GET /api/projects/{project_id}/file_download_batch_exports/{run_id}/download/{part}/

part can be either:

  • a file UUID from the files array returned by file-download-batch-exports-retrieve
  • a zero-based file index, ordered by key

If there is only one file, this also works without part:

GET /api/projects/{project_id}/file_download_batch_exports/{run_id}/download/

Let the HTTP client follow the redirect, or inspect the Location header if you need the temporary signed URL. Use the same PostHog authentication context as other API calls.

6. Save, do not print, file contents

Treat the result as a file download, not a chat response. Parquet is binary and must be written as bytes. JSONLines may still be large; save it to a file rather than pasting the contents unless the user explicitly asks for a tiny sample.

Use a filename that includes the model, run ID, and part identifier when possible, for example:

posthog-events-<run_id>-<part>.jsonl.gz
posthog-persons-<run_id>-<part>.parquet

Important notes

  • The maximum export interval is one week. Split longer user requests into separate export runs or ask which week to export.
  • The hogql model is in closed beta and is enabled per team. A permission error that says HogQL batch exports are not enabled means the team does not have the beta. Report that instead of retrying with a different query, and tell the user they can contact PostHog support to request access.
  • The hogql model runs under stricter resource limits than the other models, because user queries are less predictable. If an export fails on memory, execution time, or bytes read, suggest narrowing the query with a WHERE clause instead of retrying it unchanged.
  • A run can briefly report Running after completion while file records are being created. Poll again instead of failing immediately.
  • Download URLs are temporary. If a URL expires, call the REST download endpoint again for a fresh redirect.
  • Do not send the signed URL to unrelated services unless the user explicitly asks; it grants temporary access to the exported file.
  • If the user wants all parts of a split export, iterate over every UUID in files; do not assume part 0 is enough.
  • Large batch exports may take a few minutes or even longer to complete. Suggest to the user that they can speed-up their download by including only certain events or narrowing the date range.

posthog의 다른 스킬

error-tracking-hono
posthog
PostHog 오류 추적 for Hono
tuning-incremental-sync-config
posthog
동기화의 구성은 ExternalDataSchema에 저장되며, external-data-schemas-partial-update를 통해 언제든지 변경할 수 있습니다. 대부분의 변경은 비파괴적이며(다음 동기화에 적용됨), 일부 변경(sync_type 전환, 기본 키 변경)은 동기화된 데이터 손상을 방지하기 위해 신중한 처리가 필요합니다.
playwright-test
posthog
플레이라이트 테스트를 작성하고, 실행이 잘 되며, 불안정하지 않도록 하세요.
error-tracking-ruby
posthog
PostHog Ruby 오류 추적
authoring-log-alerts
posthog
PostHog 프로젝트의 서비스에 유용하고 노이즈가 적은 로그 알림을 작성합니다. 사용자가 로그에 대한 알림 설정을 요청하거나 추가해야 할 알림을 제안할 때 사용하세요.
making-scenes-tab-aware
posthog
Guides converting PostHog frontend scenes to be tab aware for internal scene tabs. Use when adding or refactoring a `SceneExport` scene, fixing state leaking…
posthog-survey-creator
posthog
PostHog에서 안내 대화를 통해 설문조사를 생성하고 구성합니다. 사용자가 설문조사를 만들거나, 사용자 피드백을 수집하거나, 실행하려 할 때 이 스킬을 사용하세요.
authoring-scouts
posthog
PostHog Signals 스카우트를 작성, 편집 및 조정하는 방법 — 프로젝트를 스캔하고 Signals 인박스에 보고서를 작성하는 예약된 에이전트입니다. 사용자가…