building-on-capture-v1
Skill733 starsChanged 6 days agoMITView on GitHub
How to build on capture v1, PostHog's batch event intake API (`/i/v1/analytics/events`, `/i/v1/ai/events`). Use when sending events to capture from PostHog code, changing any capture code under `rust/capture/` (legacy or v1) or the `capture_internal` helpers, adding a per-event option (`event.options`) or a property that capture or ingestion must read, changing how Node ingestion or livestream applies capture `options`, changing the v1 request, batch, header or event schema, or checking whether an SDK or internal service uses capture v1 or legacy capture (`/batch`, `/e`, `/capture`, `$process_person_profile` or `$cookieless_mode` set as properties). Covers when to add an option versus a property and why options exist, the files to change for a new option, how to compose a v1 event at a call site, internal senders, and how to tell a v1 SDK from a legacy one.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- PostHog/posthogword for word, first seen Nov 29, 2026
Other versions1 project uses a version of this.
Word for word · 1
- PostHog/posthog★ 41k100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository131 other files it gives its agents.
- AGENTS.mdAGENTS.md
- common/AGENTS.mdAGENTS.md
- hog/AGENTS.mdAGENTS.md
- proto/AGENTS.mdAGENTS.md
- rust/AGENTS.mdAGENTS.md
- .cursor/rules/django-python.mdcCursor rule
- .cursor/rules/react-typescript.mdcCursor rule
- .cursor/rules/rust.mdcCursor rule
- adding-activity-loggingSkill
- adding-api-scopesSkill
- adding-dashboard-v2-custom-contentSkill
- adding-dashboard-v2-panel-typesSkill
- adding-inbound-webhooksSkill
- adding-inbox-sourcesSkill
- adding-ingestion-warningsSkill
- adding-mcp-store-serversSkill
- adding-personhog-rpcSkill
- adding-product-alertingSkill
- adding-project-secret-api-key-authSkill
- adding-today-highlightsSkill
- adopting-generated-api-typesSkill
- analyzing-experiment-precompute-canarySkill
- analyzing-experiment-query-performanceSkill
- analyzing-insights-across-teamsSkill
- announcing-behavior-changesSkill
- auditing-warehouse-source-coverageSkill
- authenticating-to-clickhouseSkill
- authoring-ci-workflowsSkill
- building-product-empty-statesSkill
- building-the-toolbarSkill
- calling-the-ai-gatewaySkill
- clickhouse-migrationsSkill
- creating-customer-analytics-account-widgetsSkill
- debugging-ci-failuresSkill
- debugging-local-replaySkill
- debugging-local-task-agent-runsSkill
- debugging-mcp-analyticsSkill
- debugging-signals-pipelineSkill
- debugging-table-access-deniedSkill
- depot-ciSkill
- depot-container-buildsSkill
- depot-github-runnersSkill
- developing-subscriptionsSkill
- developing-the-cliSkill
- django-migrationsSkill
- django-startup-timeSkill
- documenting-warehouse-sourcesSkill
- editing-agents-mdSkill
- establishing-code-ownershipSkill
- exporting-recordings-to-customer-s3Skill
- extending-hobby-smoke-testsSkill
- extending-personhog-test-harnessSkill
- extending-the-admin-consoleSkill
- fixing-flaky-testsSkill
- formatting-slack-messagesSkill
- gating-production-deploysSkill
- gating-sensitive-actionsSkill
- generating-clickhouse-query-performance-reportsSkill
- hogliSkill
- implementing-mcp-toolsSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
15 rules. About 0 are common, 10 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 28
On behalf of a customer team, from Django: use capture_internal or capture_batch_internal for analytics events, and capture_ai_internal for …
- Very specific: line 30
From Node: follow push-capture.ts. From Rust: follow batch-import-worker/src/emit/capture.rs.
- Distinctive: line 31
PostHog's own telemetry (team 2): use the PostHog SDK for the language, on its v1 major.
- Distinctive: line 32
Never produce to the ingestion Kafka topics directly.
- Very specific: line 37
Put settings in options explicitly, for example {"process_person_profile": false}.
- Distinctive: line 57
Add an option when capture must read, act on or change the value: timestamps, partitioning, quotas, routing or a drop decision.
- Distinctive: line 58
Add a property when only ingestion or later services read or change the value.
- Distinctive: line 61
Every v1 SDK passes unknown option keys through unchanged, so a new option needs no SDK change.
- Distinctive: line 67
Do not add one without agreement from the ingestion team and the SDK owners.
- Distinctive: line 71
Every step is required. A consumer that skips its step loses the setting, and nothing fails.
- Very specific: line 98
Only the ingestion processors that consume the events capture publishes read or change event.properties.
- Distinctive: line 110
Metric labels have a small, fixed set of values: Never a token, a team id, a distinct id or an event name.
- Distinctive: line 127
The v1 endpoint rejects input that legacy capture accepts: Keep these checks, and tell senders that move from legacy about them:
- Distinctive: line 136
Keep every per-event failure a per-event result.
- Very specific: line 139
Update the README, the sdk-specs capture spec and the public capture v1 API docs in the same change.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Building on capture v1
Capture v1 is the batch intake API that the v1 SDKs and PostHog's internal senders use.
Legacy capture (/batch, /e, /capture, /i/v0/e) still serves older SDKs and stays supported, but new senders use v1.
Sources of truth, in the order to read them:
rust/capture/src/v1/README.md: the request, response and options contract, and how capture hands events to ingestion.- The
capturespec in PostHog/sdk-specs: what every v1 SDK does. - Public docs: the capture v1 API for HTTP senders, and the per-SDK migration guides (Python, Go, Rust, Node.js) for SDK users.
Send events from PostHog code
- On behalf of a customer team, from Django: use
capture_internalorcapture_batch_internalfor analytics events, andcapture_ai_internalfor$ai_*events, fromposthog/api/capture.py. They implement the headers, retries and per-event results, so do not write a new HTTP client. - From Node: follow
push-capture.ts. From Rust: followbatch-import-worker/src/emit/capture.rs. - PostHog's own telemetry (team 2): use the PostHog SDK for the language, on its v1 major.
- Never produce to the ingestion Kafka topics directly. Capture owns quotas, restrictions, deduplication and routing.
- Some internal senders and internal SDK installs still use legacy capture at the first v1 release. references/internal-senders.md lists every sender and which capture it uses. Those move to v1 soon after the release; update the list and this skill when they do. Do not move one in an unrelated PR.
Compose a v1 event
- Put settings in
optionsexplicitly, for example{"process_person_profile": false}. Never set them as$process_person_profile,$cookieless_mode,$ignore_sent_ator$product_tour_idproperties. An HTTP sender has no SDK to move those properties into options, and capture ignores$ignore_sent_atand$product_tour_idinproperties. - Send
session_idandwindow_idas event fields, not as$session_idand$window_idproperties. - For events sent on a customer's behalf, set
"capture_internal": trueon the batch, not inproperties. Capture then records127.0.0.1instead of the PostHog server's IP. Capture v1 ignores acapture_internalproperty, which is where legacy capture reads it. - Send
$ai_*events to/i/v1/ai/eventsand every other event to/i/v1/analytics/events. Capture still routes$ai_*events from the analytics endpoint to the AI topic, but only for now. Do not rely on it. The AI endpoint, and an SDK's AI capture call, drop every event that is not$ai_*withmisrouted_event. That includes$mcp_*events: send them to the analytics endpoint. - Give every event its own UUID. On a retry, resend only the events with result
retry, with the same uuid,PostHog-Request-Idandcreated_at,PostHog-Attemptplus one, and a newPostHog-Request-Timestamp. - Set
PostHog-Sdk-Infoto<sender>/<version>. Ingestion uses it as$liband$lib_versiononly when the event has no$lib.
Choose an option or a property
Why options exist. Legacy capture took settings as $ properties inside the event data.
Capture forwards properties to Kafka as raw JSON, and the client controls them, so capture could not act on a setting and ingestion could not trust one.
Capture v1 moves settings into a separate options object.
Capture validates each option, acts on it, and publishes it beside the event in the Kafka message, outside the client-controlled data.
Ingestion then writes the matching $ property, so products and queries read the same property as before.
The rule:
- Add an option when capture must read, act on or change the value: timestamps, partitioning, quotas, routing or a drop decision. If services after capture also need the value, ingestion copies the option into a property.
- Add a property when only ingestion or later services read or change the value. A new property needs no capture change.
Any v1 sender can put any string key with any JSON value in options, as with properties.
Every v1 SDK passes unknown option keys through unchanged, so a new option needs no SDK change.
The v1 SDKs move the four legacy $ properties into options under the option names (see the mapping in the capture v1 API docs and the sdk-specs capture spec).
A new option has no legacy property: capture relays it in the Kafka message, and ingestion writes it into properties when later services need it.
Options are costly to add.
Capture tracks known keys in an 8-bit set (OptionKeys in analytics/types.rs), every consumer of the Kafka options keeps its own list of keys, and an option name is public API.
Do not add one without agreement from the ingestion team and the SDK owners.
How an option reaches the stored event
Every step is required. A consumer that skips its step loses the setting, and nothing fails.
- The sender sets the option. The v1 SDKs move the four legacy
$properties intooptionsbefore they send. Capture never copies a value frompropertiesinto an option. - Capture checks the type of each known option (
RawOptions::validate). It reads values leniently, and a value it cannot read drops that event withinvalid_options. Capture does not publish a key it does not know. - Capture publishes the options in the outer Kafka message, beside the event, on every v1 endpoint.
/i/v1/analytics/eventsand/i/v1/ai/eventsshare one handler, so the AI lane carries options the same way. The legacy endpoints and the OTel endpoint publish nooptions, so a consumer must accept a message without them. - Every consumer of capture's output checks
optionson every message. For an option that replaces a legacy property, it writes that property:session_id,window_id,cookieless_mode,disable_skew_correction(as$ignore_sent_at),product_tour_idandprocess_person_profile. Node ingestion does this in the shared parse step,CAPTURE_OPTION_OVERRIDES, which the analytics and AI pipelines both run. Livestream does it inapplyCaptureOptions. - A new option is either visible or internal. When a product or a query must see it, ingestion writes it into
properties. When only capture and ingestion use it, for routing or as a marker, the consumer reads it fromoptionsand never writes it intoproperties, so it does not reach ClickHouse.
Add an option
Change all of these in one PR, or in an ordered stack where consumers ship before capture sends the key:
- Capture,
analytics/types.rs:Options,ExpectedOption(ALL,as_str), the coercer and branch inRawOptions::validate,OutboundOptionsandoutbound_options, andbuild_property_injectionswhile the splice code exists. Act on the value where capture needs it (for exampleprocess.rs, orhas_propertyfor a quota predicate). - Capture tests: the option tests in
analytics/types.rs,test_utils.rsandtests/v1_publish.rs. - Consumers of the Kafka
options:CAPTURE_OPTION_OVERRIDESinparse-kafka-message.tsand its test, andlivestream/events/kafka.go. Services that read and re-produce capture messages must keep theoptionsfield and thelegacy_property_spliceheader (CapturedEventandCapturedEventHeadersincommon/types/src/event.rs, used by kafka-deduplicator). - Internal senders:
_OPTIONS_TO_LEGACY_PROPERTYand the docstring table inposthog/api/capture.py(test:posthog/api/test/test_capture_internal.py), andOPTIONS_TO_LEGACY_PROPERTYinpush-capture.ts. Only a key that replaces a legacy property needs an entry. - Docs and specs: the
invalid_optionsentry inresolving-ingestion-warnings, the options table in the v1 README, the sdk-specscapturespec, and the public capture v1 API docs. SDKs change only when an SDK sets the option itself or has a typed options class, such as posthog-kmp'sPostHogEventOptions. SDK behavior changes need the capture v1 suites in the SDK test harness.
Keep capture out of event properties
Capture works with event.options and leaves event.properties alone.
This applies to the legacy handlers and to the v1 handlers.
- Capture request handlers and processing code must not deserialize
event.properties, read a value from it or write a value into it. - The v1 endpoints (
/i/v1/*) must not gain a new use ofevent.properties. A value capture must read, act on or change is an option: see Choose an option or a property. - Only the ingestion processors that consume the events capture publishes read or change
event.properties. - The uses that capture has today are being removed, such as the legacy handlers that read
$option properties and the v1 legacy property splice. Do not copy them or add to them.
Rules for every capture change
These apply to the legacy handlers and to the v1 handlers.
- No panic on a request path. No
unwrap(),expect()or unchecked index on request data: a panic loses the whole batch and the sender gets no result. - No new store or external system. Capture depends on Kafka and Redis, and on S3 for AI blobs and the fallback sink. Anything more needs the ingestion team's agreement in
#team-ingestionbefore the code merges. - A new call on the request path has a timeout and a stated choice between failing open and failing closed.
- An endpoint that builds events itself applies every limit the main pipelines apply: quota, overflow, event restrictions and the AI byte limit.
- The AI lane is the
$ai_event name prefix (is_ai_event). The analytics endpoint sends those events to the AI topic, and the AI endpoint drops any other name asmisrouted_event. A new route by event name changes both endpoints, the quota check, the README and the public docs together. - Metric labels have a small, fixed set of values. Never a token, a team id, a distinct id or an event name.
Model a v1 endpoint on the analytics endpoint
/i/v1/analytics/events (analytics/handler.rs) is the reference for a v1 endpoint.
An endpoint that is added to v1 or moved to v1 later, such as AI or replay, meets the same requirements. Its payload can differ where its data differs.
The legacy endpoints and the OTel endpoint are not models for a v1 endpoint.
What the analytics endpoint has that legacy analytics capture does not. The v1 README has the full contract:
- Required headers.
Authorization: Bearer,PostHog-Sdk-Info,PostHog-Attempt,PostHog-Request-Id,PostHog-Request-Timestamp,Content-Type: application/jsonandUser-Agent. Legacy capture reads the token from the body and requires none of them. - Standard compression only.
Content-Encodingisgzip,deflate,brorzstd. Legacy capture also accepts lz-string and base64 bodies. - One batch shape with strict event fields.
event,uuid,distinct_idandtimestampare JSON strings. Legacy capture treatsuuidandtimestampas optional and accepts any JSON value asdistinct_id. - Settings in
options, with a type check on each one capture knows. - One result for each event:
ok,drop,warningorretry, with a publicdetailsreason. A sender resends only theretryevents. - Status codes with one meaning each: 400, 401, 402, 404, 413 and 415 for the request, 408 and 5xx with
Retry-After, and never 429.
The v1 endpoint rejects input that legacy capture accepts. Keep these checks, and tell senders that move from legacy about them:
- The whole request fails with 400 for a missing required header, a body that is not valid JSON, an empty or invalid batch, or an invalid
uuid. It fails with 415 for anotherContent-TypeorContent-Encoding. - One event drops for a missing or too long
eventname, a missing or too largedistinct_id(legacy capture cuts it to 200 characters), a badtimestamp,propertiesthat is not an object, or an option value capture cannot read (invalid_options). - A later copy of a uuid in the same batch is dropped and counted in
duplicates_dropped. - An event that is not
$ai_*drops on the AI endpoint withmisrouted_event.
Change capture v1 code
- Keep every per-event failure a per-event result. Only the cases in the README's "Response" section fail the whole request.
detailsvalues are public: SDKs and docs name them. Add a new one as a constant inanalytics/constants.rs.- SDKs on old versions keep sending for years, so contract changes stay backward compatible: a new header or field is optional, and a new result or
detailsvalue only adds to the old ones. Update the README, the sdk-specscapturespec and the public capture v1 API docs in the same change. - Watch the change with
monitoring-capture-service.
Check whether an SDK uses capture v1
An SDK is on v1 when it posts to /i/v1/analytics/events, sends the PostHog-Sdk-Info and PostHog-Request-Id headers, and takes options on its capture calls.
A legacy SDK posts to /batch, /e or /capture and sets settings as $ properties.
The v1 majors are:
- posthog-python 8, posthog-go v2, posthog-rs 1.0 and posthog-node 6 (with
@posthog/ai8 and@posthog/mcp1 on it). - posthog-ios 4.0, posthog-android 4.0, and posthog_flutter 6.0 on every platform except web.
@posthog/react-native-plugin3.0 for the events it sends natively: crash reports, fatal$exceptionevents and push-opened events.- posthog-kmp 0.11 on Android, iOS, macOS and the JVM.
posthog-js in the browser, React Native JS events, and Flutter and KMP on the web stay on legacy capture.
references/sdk-implementations.md shows where each v1 SDK builds its events, the order it applies properties and options in, and how $lib is set.
Related
resolving-ingestion-warnings: read when a v1 drop or ingestion warning needs explaining to a customer.adding-ingestion-warnings: read before adding a warning in ingestion for a new option.- Person processing handbook: read when a change touches
process_person_profile.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

