:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(feature-flags): declare the static cohort endpoint schema (#113684)
Daniel Marchukcf37b5b18911
diff --git a/products/feature_flags/backend/api/feature_flag.py b/products/feature_flags/backend/api/feature_flag.pyindex fd89685e2612..d945ed84ad67 100644--- a/products/feature_flags/backend/api/feature_flag.py+++ b/products/feature_flags/backend/api/feature_flag.py@@ -3914,6 +3914,13 @@ class FlagRolloutWriteRequest(FlagLifecycleWriteRequest):self.data = {"version": version}+class CreateStaticCohortForFlagResponseSerializer(serializers.Serializer):+ cohort = CohortSerializer(+ read_only=True,+ help_text="The new static cohort. It fills with the people the flag matches in the background, so is_calculating is usually still true in this response.",+ )++# ClickHouse cost attribution: this viewset currently has no direct ClickHouse calls —# all ClickHouse work is delegated to helpers (user_blast_radius.py, flag_analytics.py)# that already tag their queries. If you add a new ClickHouse query reachable from an@@ -5470,6 +5477,7 @@ class FeatureFlagViewSet(return Response({"affected": result.affected, "total": result.total})+ @extend_schema(request=None, responses={201: CreateStaticCohortForFlagResponseSerializer})@action(methods=["POST"], detail=True)def create_static_cohort_for_flag(self, request: request.Request, **kwargs):feature_flag = self.get_object()diff --git a/products/feature_flags/frontend/generated/api.schemas.ts b/products/feature_flags/frontend/generated/api.schemas.tsindex 7c9ed2475463..ed87c6c001e9 100644--- a/products/feature_flags/frontend/generated/api.schemas.ts+++ b/products/feature_flags/frontend/generated/api.schemas.ts@@ -1361,6 +1361,285 @@ export interface FlagApprovalConflictApi {required_approvers: unknown}+export type PropertyGroupOperatorEnumApi =+ (typeof PropertyGroupOperatorEnumApi)[keyof typeof PropertyGroupOperatorEnumApi]++export const PropertyGroupOperatorEnumApi = {+ And: 'AND',+ Or: 'OR',+} as const++export type EventPropFilterTypeEnumApi = (typeof EventPropFilterTypeEnumApi)[keyof typeof EventPropFilterTypeEnumApi]++export const EventPropFilterTypeEnumApi = {+ Event: 'event',+ Element: 'element',+} as const++export interface EventPropFilterApi {+ type: EventPropFilterTypeEnumApi+ key: string+ value: unknown+ operator?: string | null+}++export interface HogQLFilterApi {+ type: 'hogql'+ key: string+ value?: unknown+}++export interface BehavioralFilterApi {+ bytecode?: unknown[] | null+ bytecode_error?: string | null+ conditionHash?: string | null+ type: 'behavioral'+ key: string | number+ value: string+ event_type: string+ time_value?: number | null+ time_interval?: string | null+ negation?: boolean+ operator?: string | null+ operator_value?: number | null+ seq_time_interval?: string | null+ seq_time_value?: number | null+ seq_event?: string | number | null+ seq_event_type?: string | null+ total_periods?: number | null+ min_periods?: number | null+ event_filters?: (EventPropFilterApi | HogQLFilterApi)[] | null+ explicit_datetime?: string | null+ explicit_datetime_to?: string | null+}++export interface CohortFilterApi {+ bytecode?: unknown[] | null+ bytecode_error?: string | null+ conditionHash?: string | null+ type: 'cohort'+ key: 'id'+ value: number+ negation?: boolean+}++export interface PersonFilterApi {+ operator?: string | null+ value?: unknown+ bytecode?: unknown[] | null+ bytecode_error?: string | null+ conditionHash?: string | null+ type: 'person'+ key: string+ negation?: boolean+}++/**+ * Filter on a top-level persons-table column (e.g. created_at) rather than the+ * properties JSON. The matching key must be one of PERSON_METADATA_FIELDS.+ */+export interface PersonMetadataFilterApi {+ operator?: string | null+ value?: unknown+ bytecode?: unknown[] | null+ bytecode_error?: string | null+ conditionHash?: string | null+ type: 'person_metadata'+ key: string+ negation?: boolean+}++/**+ * AND/OR group containing cohort filters. Named to avoid collision with analytics Group model.+ */+export interface CohortFilterGroupApi {+ type: PropertyGroupOperatorEnumApi+ values: (BehavioralFilterApi | CohortFilterApi | PersonFilterApi | PersonMetadataFilterApi | CohortFilterGroupApi)[]+}++export interface CohortFiltersApi {+ properties: CohortFilterGroupApi+ filterTestAccounts?: boolean | null+}++/**+ * * `static` - static+ * * `person_property` - person_property+ * * `behavioral` - behavioral+ * * `realtime` - realtime+ * * `analytical` - analytical+ */+export type CohortTypeEnumApi = (typeof CohortTypeEnumApi)[keyof typeof CohortTypeEnumApi]++export const CohortTypeEnumApi = {+ Static: 'static',+ PersonProperty: 'person_property',+ Behavioral: 'behavioral',+ Realtime: 'realtime',+ Analytical: 'analytical',+} as const++export interface CohortConditionTypeFlagsApi {+ /** The filters include a person property or person_metadata condition. */+ person_properties: boolean+ /** The filters include a behavioral condition that is not lifecycle-style (e.g. performed_event, performed_event_multiple, performed_event_sequence, or their negations). */+ behavioral: boolean+ /** The filters include a lifecycle-style behavioral condition (first-seen/regularly/stopped/restarted performing an event). */+ lifecycle: boolean+ /** The filters include a nested reference to another cohort. */+ cohorts: boolean+}++/**+ * * `static` - Static+ * * `person_properties` - Person properties+ * * `daily` - Daily+ * * `building` - Building+ * * `rebuilding` - Rebuilding+ * * `ready` - Ready+ * * `needs_attention` - Needs attention+ */+export type CohortRealtimeStateEnumApi = (typeof CohortRealtimeStateEnumApi)[keyof typeof CohortRealtimeStateEnumApi]++export const CohortRealtimeStateEnumApi = {+ Static: 'static',+ PersonProperties: 'person_properties',+ Daily: 'daily',+ Building: 'building',+ Rebuilding: 'rebuilding',+ Ready: 'ready',+ NeedsAttention: 'needs_attention',+} as const++/**+ * * `waiting` - Waiting+ * * `scanning` - Scanning+ * * `checking` - Checking+ */+export type CohortHistoryBuildPhaseEnumApi =+ (typeof CohortHistoryBuildPhaseEnumApi)[keyof typeof CohortHistoryBuildPhaseEnumApi]++export const CohortHistoryBuildPhaseEnumApi = {+ Waiting: 'waiting',+ Scanning: 'scanning',+ Checking: 'checking',+} as const++export interface CohortHistoryBuildApi {+ /** What the build is doing now: `waiting` to start, `scanning` past events, or `checking` the membership it produced. A build that is queued but has not started reports `waiting` too.+ *+ * * `waiting` - Waiting+ * * `scanning` - Scanning+ * * `checking` - Checking */+ phase: CohortHistoryBuildPhaseEnumApi+ /**+ * How much of the event history has been scanned, 0 to 100. Null outside the `scanning` phase, and while the scan is still being planned.+ * @nullable+ */+ percent_complete: number | null+ /**+ * When this build last made progress. Null while it is still queued.+ * @nullable+ */+ updated_at: string | null+}++export interface CohortRealtimeReadinessApi {+ /** Whether feature flags can target this cohort now. `ready`: they can, and they see membership changes within about a minute. `building` / `rebuilding`: PostHog is preparing the cohort from past events, and flags cannot target it yet. `needs_attention`: the cohort qualifies but nothing is preparing it. `daily`: its criteria are not supported in realtime, so its membership only comes from the once-a-day calculation. `person_properties`: it matches on person properties, which flags read directly, so they can always target it. `static`: it is a fixed list of people.+ *+ * * `static` - Static+ * * `person_properties` - Person properties+ * * `daily` - Daily+ * * `building` - Building+ * * `rebuilding` - Rebuilding+ * * `ready` - Ready+ * * `needs_attention` - Needs attention */+ state: CohortRealtimeStateEnumApi+ /**+ * When the cohort became targetable by feature flags. Null unless the state is `ready`.+ * @nullable+ */+ ready_at: string | null+ /** The build preparing the cohort. Null unless the state is `building` or `rebuilding`. */+ build: CohortHistoryBuildApi | null+}++export type SearchMatchTypeEnumApi = (typeof SearchMatchTypeEnumApi)[keyof typeof SearchMatchTypeEnumApi]++export const SearchMatchTypeEnumApi = {+ Exact: 'exact',+ Similar: 'similar',+} as const++export interface CohortApi {+ readonly id: number+ /**+ * @maxLength 400+ * @nullable+ */+ name?: string | null+ /** @maxLength 1000 */+ description?: string+ groups?: unknown+ deleted?: boolean+ filters?: CohortFiltersApi | null+ query?: unknown+ /** @nullable */+ readonly version: number | null+ /** @nullable */+ readonly pending_version: number | null+ readonly is_calculating: boolean+ readonly created_by: UserBasicApi+ /** @nullable */+ readonly created_at: string | null+ /** @nullable */+ readonly last_calculation: string | null+ /** @nullable */+ readonly last_backfill_person_properties_at: string | null+ readonly errors_calculating: number+ /** @nullable */+ readonly last_error_message: string | null+ /** @nullable */+ readonly count: number | null+ /**+ * Number of IDs supplied by the most recent static cohort import. Null if the cohort was never populated from a list of IDs.+ * @nullable+ */+ readonly last_import_total_count: number | null+ /**+ * How many of the IDs in the most recent static cohort import matched no person, and so were not added to the cohort.+ * @nullable+ */+ readonly last_import_unmatched_count: number | null+ is_static?: boolean+ /** Type of cohort based on filter complexity+ *+ * * `static` - static+ * * `person_property` - person_property+ * * `behavioral` - behavioral+ * * `realtime` - realtime+ * * `analytical` - analytical */+ cohort_type?: CohortTypeEnumApi | BlankEnumApi | null+ /** Flags describing which kinds of conditions the cohort's filters contain. Null when the cohort has no filters to classify. */+ readonly condition_type: CohortConditionTypeFlagsApi | null+ /** Whether feature flags can target this cohort, and the progress of the build that gets it there. Null outside the realtime cohort flag targeting rollout, on projects the realtime pipeline does not cover, and for cohorts that match on neither events nor person properties, which nothing in the flag API decides on. */+ readonly realtime: CohortRealtimeReadinessApi | null+ readonly experiment_set: readonly number[]+ /** How this row matched the `search` query parameter: `exact` (the term is a case-insensitive substring of a searched field) or `similar` (a fuzzy trigram match, returned only when no exact match exists). Null when the list is not filtered by `search`. */+ readonly search_match_type: SearchMatchTypeEnumApi | null+ _create_in_folder?: string+ /**+ * Person UUIDs to add to a new static cohort.+ * @maxItems 1000+ */+ _create_static_person_ids?: string[]+}++export interface CreateStaticCohortForFlagResponseApi {+ /** The new static cohort. It fills with the people the flag matches in the background, so is_calculating is usually still true in this response. */+ readonly cohort: CohortApi+}+export interface DependentFlagApi {/** Feature flag ID */id: numberdiff --git a/products/feature_flags/frontend/generated/api.ts b/products/feature_flags/frontend/generated/api.tsindex 24088a5e9cc4..fc6acf2ca43e 100644--- a/products/feature_flags/frontend/generated/api.ts+++ b/products/feature_flags/frontend/generated/api.ts@@ -20,6 +20,7 @@ import type {CopyFlagsDependencyRequirementsResponseApi,CopyFlagsRequestApi,CopyFlagsResponseApi,+ CreateStaticCohortForFlagResponseApi,DependentFlagApi,EvaluationContextSuggestionRequestApi,EvaluationContextSuggestionResponseApi,@@ -783,15 +784,15 @@ export const getFeatureFlagsCreateStaticCohortForFlagCreateUrl = (projectId: strexport const featureFlagsCreateStaticCohortForFlagCreate = async (projectId: string,id: number,- featureFlagApi: NonReadonly<FeatureFlagApi>,options?: RequestInit-): Promise<void> => {- return apiMutator<void>(getFeatureFlagsCreateStaticCohortForFlagCreateUrl(projectId, id), {- ...options,- method: 'POST',- headers: { 'Content-Type': 'application/json', ...options?.headers },- body: JSON.stringify(featureFlagApi),- })+): Promise<CreateStaticCohortForFlagResponseApi> => {+ return apiMutator<CreateStaticCohortForFlagResponseApi>(+ getFeatureFlagsCreateStaticCohortForFlagCreateUrl(projectId, id),+ {+ ...options,+ method: 'POST',+ }+ )}export const getFeatureFlagsDependentFlagsListUrl = (projectId: string, id: number) => {diff --git a/products/feature_flags/frontend/generated/api.zod.ts b/products/feature_flags/frontend/generated/api.zod.tsindex 44d5b066010a..07ad8f69fc4c 100644--- a/products/feature_flags/frontend/generated/api.zod.ts+++ b/products/feature_flags/frontend/generated/api.zod.ts@@ -1014,83 +1014,6 @@ export const FeatureFlagsPartialUpdateBody = /* @__PURE__ */ zod.object({),})-/**- * Create, read, update and delete feature flags. [See docs](https://posthog.com/docs/feature-flags) for more information on feature flags.- *- * If you're looking to use feature flags on your application, you can either use our JavaScript Library or our dedicated endpoint to check if feature flags are enabled for a given user.- */-export const featureFlagsCreateStaticCohortForFlagCreateBodyKeyMax = 400--export const featureFlagsCreateStaticCohortForFlagCreateBodyVersionDefault = 0--export const FeatureFlagsCreateStaticCohortForFlagCreateBody = /* @__PURE__ */ zod- .object({- name: zod- .string()- .optional()- .describe('contains the description for the flag (field name `name` is kept for backwards-compatibility)'),- key: zod.string().max(featureFlagsCreateStaticCohortForFlagCreateBodyKeyMax),- filters: zod.record(zod.string(), zod.unknown()).optional(),- deleted: zod.boolean().optional(),- active: zod.boolean().optional(),- archived: zod- .boolean()- .optional()- .describe(- 'Whether the flag is archived. Archived flags are hidden from the flag list by default and must be disabled (`active: false`).'- ),- version: zod.number().default(featureFlagsCreateStaticCohortForFlagCreateBodyVersionDefault),- ensure_experience_continuity: zod.boolean().nullish(),- tags: zod.array(zod.unknown()).optional(),- evaluation_contexts: zod.array(zod.unknown()).optional(),- analytics_dashboards: zod.array(zod.number()).optional(),- has_enriched_analytics: zod.boolean().nullish(),- creation_context: zod- .enum([- 'feature_flags',- 'experiments',- 'surveys',- 'early_access_features',- 'web_experiments',- 'product_tours',- ])- .describe(- '\* `feature_flags` - feature_flags\n\* `experiments` - experiments\n\* `surveys` - surveys\n\* `early_access_features` - early_access_features\n\* `web_experiments` - web_experiments\n\* `product_tours` - product_tours'- )- .optional()- .describe(- "Indicates the origin product of the feature flag. Choices: 'feature_flags', 'experiments', 'surveys', 'early_access_features', 'web_experiments', 'product_tours'.\n\n\* `feature_flags` - feature_flags\n\* `experiments` - experiments\n\* `surveys` - surveys\n\* `early_access_features` - early_access_features\n\* `web_experiments` - web_experiments\n\* `product_tours` - product_tours"- ),- is_remote_configuration: zod.boolean().nullish(),- has_encrypted_payloads: zod.boolean().nullish(),- evaluation_runtime: zod- .union([- zod- .enum(['server', 'client', 'all'])- .describe('\* `server` - Server\n\* `client` - Client\n\* `all` - All'),- zod.enum(['']),- zod.null(),- ])- .optional()- .describe(- 'Specifies where this feature flag should be evaluated\n\n\* `server` - Server\n\* `client` - Client\n\* `all` - All'- ),- bucketing_identifier: zod- .union([- zod- .enum(['distinct_id', 'device_id'])- .describe('\* `distinct_id` - User ID (default)\n\* `device_id` - Device ID'),- zod.enum(['']),- zod.null(),- ])- .optional()- .describe(- 'Identifier used for bucketing users into rollout and variants\n\n\* `distinct_id` - User ID (default)\n\* `device_id` - Device ID'- ),- _create_in_folder: zod.string().optional(),- })- .describe('Serializer mixin that handles tags for objects.')-/*** Serve a feature flag to every user.*diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex 52191d938716..2909dff46dac 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -26781,6 +26781,11 @@ export namespace Schemas {uploads: UploadTarget[];}+ export interface CreateStaticCohortForFlagResponse {+ /** The new static cohort. It fills with the people the flag matches in the background, so is_calculating is usually still true in this response. */+ readonly cohort: Cohort;+ }+/*** * `try_next` - try_next* * `consider` - consider