This package provides a TypeScript client for interacting with the PostHog API, automatically generated from the PostHog OpenAPI schema. It aims to offer a type-safe and convenient way to access PostHog's functionalities programmatically, including managing events, persons, and insights. Currently at version 0.0.12, it is in its early stages of development, meaning the API surface may evolve rapidly and breaking changes are likely before a stable 1.0 release. The package is primarily designed for TypeScript environments and relies on environment variables for API key and base URL configuration. Its key differentiator is providing a pre-generated, typed client, saving developers the effort of manual API request handling and type definition.
npm install posthog-openapi-clientVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the `PosthogAPIClient` using environment variables and then make authenticated API calls to fetch events and persons from your PostHog instance.
Regularly consult the package's changelog or regenerate your client from the latest PostHog schema if you are maintaining a fork. Pin exact versions (`"posthog-openapi-client": "0.0.12"`) to prevent unexpected breaks.
Ensure these environment variables are correctly set in your execution environment. For programmatic configuration, pass the base URL and API key directly to the `PosthogAPIClient` constructor as `{ BASE: 'your_url', TOKEN: 'your_key' }`.Monitor the `posthog-openapi-client` npm page for updates. If you require the absolute latest schema and no package update is available, you may need to regenerate the client locally using `openapi-typescript-codegen` as described in the package's README.
Set the `POSTHOG_PERSONAL_API_KEY` environment variable in your shell (e.g., `export POSTHOG_PERSONAL_API_KEY=YOUR_KEY`) or pass it directly to the client constructor: `new PosthogAPIClient({ TOKEN: 'YOUR_KEY', ... })`.Verify the exact structure and method names by inspecting the generated client code or the PostHog API documentation. Ensure your `posthog-openapi-client` package is up-to-date with the latest PostHog API schema.
Check that `POSTHOG_BASE_URL` is correctly set (e.g., `https://app.posthog.com` or `https://eu.posthog.com`). Verify your network connection and ensure no firewall or proxy is blocking access. For browser usage, check for CORS policies.
No dependency data recorded yet.