Skip to content

: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.

37.3 KB
Raw Blame
/**
 * Auto-generated from the Django backend OpenAPI schema.
 * To modify these types, update the Django serializers or views, then run:
 *   hogli build:openapi
 * Questions or issues? #team-devex on Slack
 *
 * PostHog API - generated
 * OpenAPI spec version: 1.0.0
 */
/**
 * * `insight` - Insight
 * * `dashboard` - Dashboard
 * * `ai_prompt` - AI prompt
 */
export type SubscriptionResourceTypeEnumApi =
    (typeof SubscriptionResourceTypeEnumApi)[keyof typeof SubscriptionResourceTypeEnumApi]

export const SubscriptionResourceTypeEnumApi = {
    Insight: 'insight',
    Dashboard: 'dashboard',
    AiPrompt: 'ai_prompt',
} as const

/**
 * * `since_last_sent` - Since last report
 * * `last_n_days` - Last N days
 * * `days_ago_range` - Between X and Y days ago
 */
export type SubscriptionAIWindowModeEnumApi =
    (typeof SubscriptionAIWindowModeEnumApi)[keyof typeof SubscriptionAIWindowModeEnumApi]

export const SubscriptionAIWindowModeEnumApi = {
    SinceLastSent: 'since_last_sent',
    LastNDays: 'last_n_days',
    DaysAgoRange: 'days_ago_range',
} as const

export interface AIWindowConfigApi {
    /** What the report analyzes each run:
     * * `since_last_sent` (default) — everything since the previous successful scheduled delivery (gap-free; test/manual sends don't move the anchor)
     * * `last_n_days` — a fixed trailing window of start_days_ago days
     * * `days_ago_range` — the explicit range from start_days_ago to end_days_ago days ago
     *
     * * `since_last_sent` - Since last report
     * * `last_n_days` - Last N days
     * * `days_ago_range` - Between X and Y days ago */
    mode?: SubscriptionAIWindowModeEnumApi
    /**
     * Lower bound of the analysis window, in days before the run. Required for 'last_n_days' (the N) and 'days_ago_range'; ignored for 'since_last_sent'. 1-365.
     * @minimum 1
     * @maximum 365
     * @nullable
     */
    start_days_ago?: number | null
    /**
     * Upper bound of the analysis window, in days before the run (0 = now). Required for 'days_ago_range' and must be less than start_days_ago; ignored for other modes. 0-365.
     * @minimum 0
     * @maximum 365
     * @nullable
     */
    end_days_ago?: number | null
}

export interface AIPromptConfigApi {
    /** Analysis window for the report. Omitted = 'since_last_sent' (everything since the previous scheduled delivery). */
    window?: AIWindowConfigApi
}

export interface SubscriptionDashboardContextApi {
    /** Dashboard ID used to open the context dashboard. */
    dashboard_id: number
    /** Current display name of the context dashboard. */
    dashboard_name: string
}

export interface SubscriptionInsightContextApi {
    /** Database ID of the context insight. */
    insight_id: number
    /** Stable insight identifier used to open the context insight. */
    insight_short_id: string
    /** Current display name of the context insight. */
    insight_name: string
}

export type SubscriptionContextApi = SubscriptionDashboardContextApi | SubscriptionInsightContextApi

export type AIQueryPlanStatusEnumApi = (typeof AIQueryPlanStatusEnumApi)[keyof typeof AIQueryPlanStatusEnumApi]

export const AIQueryPlanStatusEnumApi = {
    Frozen: 'frozen',
    NotFrozen: 'not_frozen',
    PlannerUpdated: 'planner_updated',
} as const

/**
 * * `email` - Email
 * * `slack` - Slack
 * * `teams` - Microsoft Teams
 */
export type SubscriptionTargetEnumApi = (typeof SubscriptionTargetEnumApi)[keyof typeof SubscriptionTargetEnumApi]

export const SubscriptionTargetEnumApi = {
    Email: 'email',
    Slack: 'slack',
    Teams: 'teams',
} as const

/**
 * * `daily` - Daily
 * * `weekly` - Weekly
 * * `monthly` - Monthly
 * * `yearly` - Yearly
 */
export type RecurrenceIntervalEnumApi = (typeof RecurrenceIntervalEnumApi)[keyof typeof RecurrenceIntervalEnumApi]

export const RecurrenceIntervalEnumApi = {
    Daily: 'daily',
    Weekly: 'weekly',
    Monthly: 'monthly',
    Yearly: 'yearly',
} as const

/**
 * * `monday` - Monday
 * * `tuesday` - Tuesday
 * * `wednesday` - Wednesday
 * * `thursday` - Thursday
 * * `friday` - Friday
 * * `saturday` - Saturday
 * * `sunday` - Sunday
 */
export type SubscriptionApiByweekdayItem =
    (typeof SubscriptionApiByweekdayItem)[keyof typeof SubscriptionApiByweekdayItem]

export const SubscriptionApiByweekdayItem = {
    Monday: 'monday',
    Tuesday: 'tuesday',
    Wednesday: 'wednesday',
    Thursday: 'thursday',
    Friday: 'friday',
    Saturday: 'saturday',
    Sunday: 'sunday',
} as const

/**
 * * `engineering` - Engineering
 * * `data` - Data
 * * `product` - Product Management
 * * `founder` - Founder
 * * `leadership` - Leadership
 * * `marketing` - Marketing
 * * `sales` - Sales / Success
 * * `student` - Student
 * * `other` - Other
 */
export type RoleAtOrganizationEnumApi = (typeof RoleAtOrganizationEnumApi)[keyof typeof RoleAtOrganizationEnumApi]

export const RoleAtOrganizationEnumApi = {
    Engineering: 'engineering',
    Data: 'data',
    Product: 'product',
    Founder: 'founder',
    Leadership: 'leadership',
    Marketing: 'marketing',
    Sales: 'sales',
    Student: 'student',
    Other: 'other',
} as const

export type BlankEnumApi = (typeof BlankEnumApi)[keyof typeof BlankEnumApi]

export const BlankEnumApi = {
    '': '',
} as const

/**
 * @nullable
 */
export type UserBasicApiHedgehogConfig = { [key: string]: unknown } | null

export interface UserBasicApi {
    readonly id: number
    readonly uuid: string
    /**
     * @maxLength 200
     * @nullable
     */
    distinct_id?: string | null
    /** @maxLength 150 */
    first_name?: string
    /** @maxLength 150 */
    last_name?: string
    /** @maxLength 254 */
    email: string
    /** @nullable */
    is_email_verified?: boolean | null
    /** @nullable */
    readonly hedgehog_config: UserBasicApiHedgehogConfig
    role_at_organization?: RoleAtOrganizationEnumApi | BlankEnumApi | null
}

/**
 * Typed view over the Subscription.delivery_config JSON blob.
 */
export interface DeliveryConfigApi {
    /** Slack subscriptions only. Insight and dashboard subscriptions: when true, upload all insight images together in the main Slack message instead of posting the first image in the main message and the rest as threaded replies. Prompt subscriptions: when true, post the chart images in the main message with the summary; when false, post them in the first thread reply. Defaults to false. The request is rejected when target_type is not 'slack', or when an insight or dashboard subscription's Slack integration does not hold the files:write permission. Omit it unless the user asks for all images or charts in the main message. */
    post_all_insights_in_main_message?: boolean
    /** Prompt subscriptions only: include generated chart images. Defaults to true when omitted. The request is rejected when the subscription sets insight or dashboard instead of prompt. It does not control the AI summary on an insight or dashboard subscription: use summary_enabled and summary_prompt_guide for that. */
    include_images?: boolean
    /** Prompt subscriptions only: include report feedback links. Defaults to true when omitted. The request is rejected when the subscription sets insight or dashboard instead of prompt. It does not control the AI summary on an insight or dashboard subscription: use summary_enabled and summary_prompt_guide for that. */
    include_feedback?: boolean
    /** Prompt subscriptions only: include a link to manage the subscription. Defaults to true when omitted. The request is rejected when the subscription sets insight or dashboard instead of prompt. It does not control the AI summary on an insight or dashboard subscription: use summary_enabled and summary_prompt_guide for that. */
    include_manage_link?: boolean
    /** Prompt subscriptions only: include PostHog product guidance. Defaults to true when omitted. Only a Slack report renders the guidance. Email and Microsoft Teams reports leave it out and accept the option without an error, unlike post_all_insights_in_main_message. The request is rejected when the subscription sets insight or dashboard instead of prompt. It does not control the AI summary on an insight or dashboard subscription: use summary_enabled and summary_prompt_guide for that. */
    include_posthog_hint?: boolean
}

/**
 * Standard Subscription serializer.
 */
export interface SubscriptionApi {
    readonly id: number
    /** What the subscription delivers: 'insight' (snapshot of one insight), 'dashboard' (snapshot of one dashboard), or 'ai_prompt' (LLM-generated report). Read-only — derived from the populated target (insight → insight, dashboard → dashboard, prompt → ai_prompt).
     *
     * * `insight` - Insight
     * * `dashboard` - Dashboard
     * * `ai_prompt` - AI prompt */
    readonly resource_type: SubscriptionResourceTypeEnumApi
    /**
     * Dashboard ID to subscribe to (mutually exclusive with insight on create).
     * @nullable
     */
    dashboard?: number | null
    /**
     * Insight ID to subscribe to (mutually exclusive with dashboard on create).
     * @nullable
     */
    insight?: number | null
    /** @nullable */
    readonly insight_short_id: string | null
    /** @nullable */
    readonly resource_name: string | null
    /** List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 20. */
    dashboard_export_insights?: number[]
    /**
     * Free-text prompt that drives the AI-generated report. Required when resource_type is 'ai_prompt'. Max 4000 characters.
     * @nullable
     */
    prompt?: string | null
    /** Configuration for AI report subscriptions (analysis window, future knobs). Only valid when resource_type is 'ai_prompt'. Replaced wholesale on writes. */
    ai_prompt_config?: AIPromptConfigApi
    /** Dashboards and insights that ground this AI report. Deleted resources are omitted. */
    readonly contexts: readonly SubscriptionContextApi[]
    /** Query plan reuse state for AI prompt subscriptions: frozen, not_frozen, or planner_updated. Null for other subscription types. */
    readonly ai_query_plan_status: AIQueryPlanStatusEnumApi | null
    /** Delivery channel: email, slack, or teams.
     *
     * * `email` - Email
     * * `slack` - Slack
     * * `teams` - Microsoft Teams */
    target_type: SubscriptionTargetEnumApi
    /** Recipient(s): comma-separated email addresses for email, Slack channel name/ID for slack, or a Microsoft Teams webhook URL for teams. A Teams webhook URL is only ever returned as its host, because the URL authorizes a post to the channel by itself. On update, omit the field to keep the stored URL, or send a full URL to replace it. */
    target_value: string
    /** How often to deliver: daily, weekly, monthly, or yearly.
     *
     * * `daily` - Daily
     * * `weekly` - Weekly
     * * `monthly` - Monthly
     * * `yearly` - Yearly */
    frequency: RecurrenceIntervalEnumApi
    /**
     * Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Required on create; must be 1 or greater.
     * @minimum 1
     * @maximum 2147483647
     */
    interval: number
    /**
     * Days of week for daily or weekly subscriptions: monday, tuesday, wednesday, thursday, friday, saturday, sunday.
     * @nullable
     */
    byweekday?: SubscriptionApiByweekdayItem[] | null
    /**
     * Position within byweekday set for monthly frequency (e.g. 1 for first, -1 for last).
     * @minimum -2147483648
     * @maximum 2147483647
     * @nullable
     */
    bysetpos?: number | null
    /**
     * Total number of deliveries before the subscription stops. Null for unlimited.
     * @minimum -2147483648
     * @maximum 2147483647
     * @nullable
     */
    count?: number | null
    /** When to start delivering (ISO 8601 datetime). The date anchors the recurrence and may be in the past. Deliveries run on half-hour cycles at :00 and :30. Other minute values are accepted for backward compatibility, but delivery happens during the next cycle instead of at that exact minute. */
    start_date: string
    /**
     * When to stop delivering (ISO 8601 datetime). Null for indefinite.
     * @nullable
     */
    until_date?: string | null
    readonly created_at: string
    readonly created_by: UserBasicApi
    /** Set to true to soft-delete. Subscriptions cannot be hard-deleted. */
    deleted?: boolean
    /** Whether the subscription is active. Set to false to pause delivery without deleting. Auto-set to false when the delivery integration becomes invalid. */
    enabled?: boolean
    /**
     * Human-readable name for this subscription.
     * @maxLength 100
     * @nullable
     */
    title?: string | null
    /** Human-readable schedule summary, e.g. 'sent daily'. */
    readonly summary: string
    /** @nullable */
    readonly next_delivery_date: string | null
    /**
     * ID of a connected Slack integration. Required when target_type is slack.
     * @nullable
     */
    integration_id?: number | null
    /**
     * Optional message included in the invitation email when adding new recipients.
     * @nullable
     */
    invite_message?: string | null
    /** Whether to immediately deliver the subscription once on save so the editor can confirm it looks right. Defaults to true on create. When omitted on update, a delivery is sent only if the edit changed what gets delivered (recipient, channel, source) or re-enabled the subscription. The recurring schedule is unaffected. */
    send_test_now?: boolean
    /** Whether to attach an AI-generated summary to each delivery (insight and dashboard subscriptions only). Requires the organization to have approved AI data processing, and is subject to the org's active-summary cap and AI credit budget; otherwise the write is rejected. Not applicable to prompt subscriptions, which are themselves AI-generated. */
    summary_enabled?: boolean
    /**
     * Optional free-text guidance (max 500 chars) steering the AI summary, e.g. which metrics to emphasize. Only settable when AI summary context is enabled for the organization; clearing it (empty string) is always allowed.
     * @maxLength 500
     */
    summary_prompt_guide?: string
    /** Per-delivery rendering options. Every option applies to one subscription kind or delivery target only, and each option's own description says where it applies and whether a mismatch is rejected or ignored. Omit this field unless the user asks for one of the options. */
    delivery_config?: DeliveryConfigApi
}

export interface PaginatedSubscriptionListApi {
    count: number
    /** @nullable */
    next?: string | null
    /** @nullable */
    previous?: string | null
    results: SubscriptionApi[]
}

export type SubscriptionWriteApiContextsItem =
    | {
          /** @minimum 1 */
          dashboard_id: number
      }
    | {
          /** @minimum 1 */
          insight_id: number
      }

/**
 * * `monday` - Monday
 * * `tuesday` - Tuesday
 * * `wednesday` - Wednesday
 * * `thursday` - Thursday
 * * `friday` - Friday
 * * `saturday` - Saturday
 * * `sunday` - Sunday
 */
export type SubscriptionWriteApiByweekdayItem =
    (typeof SubscriptionWriteApiByweekdayItem)[keyof typeof SubscriptionWriteApiByweekdayItem]

export const SubscriptionWriteApiByweekdayItem = {
    Monday: 'monday',
    Tuesday: 'tuesday',
    Wednesday: 'wednesday',
    Thursday: 'thursday',
    Friday: 'friday',
    Saturday: 'saturday',
    Sunday: 'sunday',
} as const

/**
 * Standard Subscription serializer.
 */
export interface SubscriptionWriteApi {
    readonly id: number
    /** What the subscription delivers: 'insight' (snapshot of one insight), 'dashboard' (snapshot of one dashboard), or 'ai_prompt' (LLM-generated report). Read-only — derived from the populated target (insight → insight, dashboard → dashboard, prompt → ai_prompt).
     *
     * * `insight` - Insight
     * * `dashboard` - Dashboard
     * * `ai_prompt` - AI prompt */
    readonly resource_type: SubscriptionResourceTypeEnumApi
    /**
     * Dashboard ID to subscribe to (mutually exclusive with insight on create).
     * @nullable
     */
    dashboard?: number | null
    /**
     * Insight ID to subscribe to (mutually exclusive with dashboard on create).
     * @nullable
     */
    insight?: number | null
    /** @nullable */
    readonly insight_short_id: string | null
    /** @nullable */
    readonly resource_name: string | null
    /** List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 20. */
    dashboard_export_insights?: number[]
    /**
     * Free-text prompt that drives the AI-generated report. Required when resource_type is 'ai_prompt'. Max 4000 characters.
     * @nullable
     */
    prompt?: string | null
    /** Configuration for AI report subscriptions (analysis window, future knobs). Only valid when resource_type is 'ai_prompt'. Replaced wholesale on writes. */
    ai_prompt_config?: AIPromptConfigApi
    /**
     * Complete dashboard and insight context for an AI report. Omit on PATCH to preserve, pass an empty list to clear, or pass up to 3 items to replace all contexts.
     * @maxItems 3
     */
    contexts?: SubscriptionWriteApiContextsItem[]
    /** Query plan reuse state for AI prompt subscriptions: frozen, not_frozen, or planner_updated. Null for other subscription types. */
    readonly ai_query_plan_status: AIQueryPlanStatusEnumApi | null
    /** Delivery channel: email, slack, or teams.
     *
     * * `email` - Email
     * * `slack` - Slack
     * * `teams` - Microsoft Teams */
    target_type: SubscriptionTargetEnumApi
    /** Recipient(s): comma-separated email addresses for email, Slack channel name/ID for slack, or a Microsoft Teams webhook URL for teams. A Teams webhook URL is only ever returned as its host, because the URL authorizes a post to the channel by itself. On update, omit the field to keep the stored URL, or send a full URL to replace it. */
    target_value: string
    /** How often to deliver: daily, weekly, monthly, or yearly.
     *
     * * `daily` - Daily
     * * `weekly` - Weekly
     * * `monthly` - Monthly
     * * `yearly` - Yearly */
    frequency: RecurrenceIntervalEnumApi
    /**
     * Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Required on create; must be 1 or greater.
     * @minimum 1
     * @maximum 2147483647
     */
    interval: number
    /**
     * Days of week for daily or weekly subscriptions: monday, tuesday, wednesday, thursday, friday, saturday, sunday.
     * @nullable
     */
    byweekday?: SubscriptionWriteApiByweekdayItem[] | null
    /**
     * Position within byweekday set for monthly frequency (e.g. 1 for first, -1 for last).
     * @minimum -2147483648
     * @maximum 2147483647
     * @nullable
     */
    bysetpos?: number | null
    /**
     * Total number of deliveries before the subscription stops. Null for unlimited.
     * @minimum -2147483648
     * @maximum 2147483647
     * @nullable
     */
    count?: number | null
    /** When to start delivering (ISO 8601 datetime). The date anchors the recurrence and may be in the past. Deliveries run on half-hour cycles at :00 and :30. Other minute values are accepted for backward compatibility, but delivery happens during the next cycle instead of at that exact minute. */
    start_date: string
    /**
     * When to stop delivering (ISO 8601 datetime). Null for indefinite.
     * @nullable
     */
    until_date?: string | null
    readonly created_at: string
    readonly created_by: UserBasicApi
    /** Set to true to soft-delete. Subscriptions cannot be hard-deleted. */
    deleted?: boolean
    /** Whether the subscription is active. Set to false to pause delivery without deleting. Auto-set to false when the delivery integration becomes invalid. */
    enabled?: boolean
    /**
     * Human-readable name for this subscription.
     * @maxLength 100
     * @nullable
     */
    title?: string | null
    /** Human-readable schedule summary, e.g. 'sent daily'. */
    readonly summary: string
    /** @nullable */
    readonly next_delivery_date: string | null
    /**
     * ID of a connected Slack integration. Required when target_type is slack.
     * @nullable
     */
    integration_id?: number | null
    /**
     * Optional message included in the invitation email when adding new recipients.
     * @nullable
     */
    invite_message?: string | null
    /** Whether to immediately deliver the subscription once on save so the editor can confirm it looks right. Defaults to true on create. When omitted on update, a delivery is sent only if the edit changed what gets delivered (recipient, channel, source) or re-enabled the subscription. The recurring schedule is unaffected. */
    send_test_now?: boolean
    /** Whether to attach an AI-generated summary to each delivery (insight and dashboard subscriptions only). Requires the organization to have approved AI data processing, and is subject to the org's active-summary cap and AI credit budget; otherwise the write is rejected. Not applicable to prompt subscriptions, which are themselves AI-generated. */
    summary_enabled?: boolean
    /**
     * Optional free-text guidance (max 500 chars) steering the AI summary, e.g. which metrics to emphasize. Only settable when AI summary context is enabled for the organization; clearing it (empty string) is always allowed.
     * @maxLength 500
     */
    summary_prompt_guide?: string
    /** Per-delivery rendering options. Every option applies to one subscription kind or delivery target only, and each option's own description says where it applies and whether a mismatch is rejected or ignored. Omit this field unless the user asks for one of the options. */
    delivery_config?: DeliveryConfigApi
}

export type PatchedSubscriptionWriteApiContextsItem =
    | {
          /** @minimum 1 */
          dashboard_id: number
      }
    | {
          /** @minimum 1 */
          insight_id: number
      }

/**
 * * `monday` - Monday
 * * `tuesday` - Tuesday
 * * `wednesday` - Wednesday
 * * `thursday` - Thursday
 * * `friday` - Friday
 * * `saturday` - Saturday
 * * `sunday` - Sunday
 */
export type PatchedSubscriptionWriteApiByweekdayItem =
    (typeof PatchedSubscriptionWriteApiByweekdayItem)[keyof typeof PatchedSubscriptionWriteApiByweekdayItem]

export const PatchedSubscriptionWriteApiByweekdayItem = {
    Monday: 'monday',
    Tuesday: 'tuesday',
    Wednesday: 'wednesday',
    Thursday: 'thursday',
    Friday: 'friday',
    Saturday: 'saturday',
    Sunday: 'sunday',
} as const

/**
 * Standard Subscription serializer.
 */
export interface PatchedSubscriptionWriteApi {
    readonly id?: number
    /** What the subscription delivers: 'insight' (snapshot of one insight), 'dashboard' (snapshot of one dashboard), or 'ai_prompt' (LLM-generated report). Read-only — derived from the populated target (insight → insight, dashboard → dashboard, prompt → ai_prompt).
     *
     * * `insight` - Insight
     * * `dashboard` - Dashboard
     * * `ai_prompt` - AI prompt */
    readonly resource_type?: SubscriptionResourceTypeEnumApi
    /**
     * Dashboard ID to subscribe to (mutually exclusive with insight on create).
     * @nullable
     */
    dashboard?: number | null
    /**
     * Insight ID to subscribe to (mutually exclusive with dashboard on create).
     * @nullable
     */
    insight?: number | null
    /** @nullable */
    readonly insight_short_id?: string | null
    /** @nullable */
    readonly resource_name?: string | null
    /** List of insight IDs from the dashboard to include. Required for dashboard subscriptions, max 20. */
    dashboard_export_insights?: number[]
    /**
     * Free-text prompt that drives the AI-generated report. Required when resource_type is 'ai_prompt'. Max 4000 characters.
     * @nullable
     */
    prompt?: string | null
    /** Configuration for AI report subscriptions (analysis window, future knobs). Only valid when resource_type is 'ai_prompt'. Replaced wholesale on writes. */
    ai_prompt_config?: AIPromptConfigApi
    /**
     * Complete dashboard and insight context for an AI report. Omit on PATCH to preserve, pass an empty list to clear, or pass up to 3 items to replace all contexts.
     * @maxItems 3
     */
    contexts?: PatchedSubscriptionWriteApiContextsItem[]
    /** Query plan reuse state for AI prompt subscriptions: frozen, not_frozen, or planner_updated. Null for other subscription types. */
    readonly ai_query_plan_status?: AIQueryPlanStatusEnumApi | null
    /** Delivery channel: email, slack, or teams.
     *
     * * `email` - Email
     * * `slack` - Slack
     * * `teams` - Microsoft Teams */
    target_type?: SubscriptionTargetEnumApi
    /** Recipient(s): comma-separated email addresses for email, Slack channel name/ID for slack, or a Microsoft Teams webhook URL for teams. A Teams webhook URL is only ever returned as its host, because the URL authorizes a post to the channel by itself. On update, omit the field to keep the stored URL, or send a full URL to replace it. */
    target_value?: string
    /** How often to deliver: daily, weekly, monthly, or yearly.
     *
     * * `daily` - Daily
     * * `weekly` - Weekly
     * * `monthly` - Monthly
     * * `yearly` - Yearly */
    frequency?: RecurrenceIntervalEnumApi
    /**
     * Interval multiplier (e.g. 2 with weekly frequency means every 2 weeks). Required on create; must be 1 or greater.
     * @minimum 1
     * @maximum 2147483647
     */
    interval?: number
    /**
     * Days of week for daily or weekly subscriptions: monday, tuesday, wednesday, thursday, friday, saturday, sunday.
     * @nullable
     */
    byweekday?: PatchedSubscriptionWriteApiByweekdayItem[] | null
    /**
     * Position within byweekday set for monthly frequency (e.g. 1 for first, -1 for last).
     * @minimum -2147483648
     * @maximum 2147483647
     * @nullable
     */
    bysetpos?: number | null
    /**
     * Total number of deliveries before the subscription stops. Null for unlimited.
     * @minimum -2147483648
     * @maximum 2147483647
     * @nullable
     */
    count?: number | null
    /** When to start delivering (ISO 8601 datetime). The date anchors the recurrence and may be in the past. Deliveries run on half-hour cycles at :00 and :30. Other minute values are accepted for backward compatibility, but delivery happens during the next cycle instead of at that exact minute. */
    start_date?: string
    /**
     * When to stop delivering (ISO 8601 datetime). Null for indefinite.
     * @nullable
     */
    until_date?: string | null
    readonly created_at?: string
    readonly created_by?: UserBasicApi
    /** Set to true to soft-delete. Subscriptions cannot be hard-deleted. */
    deleted?: boolean
    /** Whether the subscription is active. Set to false to pause delivery without deleting. Auto-set to false when the delivery integration becomes invalid. */
    enabled?: boolean
    /**
     * Human-readable name for this subscription.
     * @maxLength 100
     * @nullable
     */
    title?: string | null
    /** Human-readable schedule summary, e.g. 'sent daily'. */
    readonly summary?: string
    /** @nullable */
    readonly next_delivery_date?: string | null
    /**
     * ID of a connected Slack integration. Required when target_type is slack.
     * @nullable
     */
    integration_id?: number | null
    /**
     * Optional message included in the invitation email when adding new recipients.
     * @nullable
     */
    invite_message?: string | null
    /** Whether to immediately deliver the subscription once on save so the editor can confirm it looks right. Defaults to true on create. When omitted on update, a delivery is sent only if the edit changed what gets delivered (recipient, channel, source) or re-enabled the subscription. The recurring schedule is unaffected. */
    send_test_now?: boolean
    /** Whether to attach an AI-generated summary to each delivery (insight and dashboard subscriptions only). Requires the organization to have approved AI data processing, and is subject to the org's active-summary cap and AI credit budget; otherwise the write is rejected. Not applicable to prompt subscriptions, which are themselves AI-generated. */
    summary_enabled?: boolean
    /**
     * Optional free-text guidance (max 500 chars) steering the AI summary, e.g. which metrics to emphasize. Only settable when AI summary context is enabled for the organization; clearing it (empty string) is always allowed.
     * @maxLength 500
     */
    summary_prompt_guide?: string
    /** Per-delivery rendering options. Every option applies to one subscription kind or delivery target only, and each option's own description says where it applies and whether a mismatch is rejected or ignored. Omit this field unless the user asks for one of the options. */
    delivery_config?: DeliveryConfigApi
}

/**
 * * `starting` - Starting
 * * `completed` - Completed
 * * `failed` - Failed
 * * `skipped` - Skipped
 */
export type SubscriptionDeliveryStatusEnumApi =
    (typeof SubscriptionDeliveryStatusEnumApi)[keyof typeof SubscriptionDeliveryStatusEnumApi]

export const SubscriptionDeliveryStatusEnumApi = {
    Starting: 'starting',
    Completed: 'completed',
    Failed: 'failed',
    Skipped: 'skipped',
} as const

export interface AIReportQueryDiagnosticApi {
    /** What this query step was meant to compute. */
    description: string
    /** The HogQL the assistant generated for this step. */
    hogql: string
    /** Whether the query ran successfully. */
    ok: boolean
    /**
     * Exception class name when the query failed; null on success.
     * @nullable
     */
    error_type: string | null
    /**
     * Stable query API error code when available; null on success and for unclassified errors.
     * @nullable
     */
    error_code?: string | null
    /**
     * Human-readable failure reason, present only for query errors safe to surface to the subscription owner (e.g. an unresolved field name); null on success and for internal errors, which expose error_type only.
     * @nullable
     */
    human_readable_error?: string | null
}

export interface AIReportChartApi {
    /** Id of the rendered PNG export backing this chart. */
    export_asset_id: number
    /** Chart caption, taken from the plan step it illustrates. */
    title: string
    /** Index of the plan step this chart came from. */
    step_index: number
}

export interface SubscriptionDeliveryApi {
    /** Primary key for this delivery row. */
    readonly id: string
    /** Parent subscription id. */
    readonly subscription: number
    /** Temporal workflow id for this delivery run. */
    readonly temporal_workflow_id: string
    /** Dedupes activity retries for the same logical run. */
    readonly idempotency_key: string
    /** Why the run started (e.g. scheduled, manual, subscription update). */
    readonly trigger_type: string
    /**
     * Planned send time when applicable.
     * @nullable
     */
    readonly scheduled_at: string | null
    /** Channel snapshot at send time: email, slack, or teams. */
    readonly target_type: string
    /** Destination snapshot at send time: the email list, the Slack channel id, or the host of the Microsoft Teams webhook. The webhook URL itself is never returned. */
    readonly target_value: string
    /**
     * ExportedAsset ids generated for this send.
     * @items.minimum -2147483648
     * @items.maximum 2147483647
     */
    readonly exported_asset_ids: readonly number[]
    /** Snapshot at send time: dashboard metadata, total_insight_count, and per-exported-insight entries (id, short_id, name, query_hash, cache_key, query_results, optional query_error). */
    readonly content_snapshot: unknown
    /** Per-destination outcomes; items use status success, failed, or partial. */
    readonly recipient_results: unknown
    /** Overall run status: starting, completed, failed, or skipped.
     *
     * * `starting` - Starting
     * * `completed` - Completed
     * * `failed` - Failed
     * * `skipped` - Skipped */
    readonly status: SubscriptionDeliveryStatusEnumApi
    /** Top-level failure payload when status is failed, if any. */
    readonly error: unknown
    /** When the delivery row was created. */
    readonly created_at: string
    /** Last ORM update to this row. */
    readonly last_updated_at: string
    /**
     * When the run finished, if applicable.
     * @nullable
     */
    readonly finished_at: string | null
    /**
     * AI-generated summary included in this delivery, when one was produced.
     * @nullable
     */
    readonly change_summary: string | null
    /**
     * AI-generated report markdown delivered by this run. Null for non-AI deliveries or runs without a persisted report.
     * @nullable
     */
    readonly ai_report: string | null
    /**
     * Per-step query diagnostics (generated HogQL + failure type) for this report. Null for non-AI deliveries or runs without persisted diagnostics.
     * @nullable
     */
    readonly ai_report_diagnostics: readonly AIReportQueryDiagnosticApi[] | null
    /**
     * Charts rendered for this report, in the order they were delivered. Empty when the report had no charts. Null for non-AI deliveries and for deliveries recorded before charts existed.
     * @nullable
     */
    readonly ai_report_charts: readonly AIReportChartApi[] | null
    /**
     * The subscription's prompt as it was when this report was generated. Null for older deliveries and non-AI deliveries.
     * @nullable
     */
    readonly ai_report_prompt: string | null
    /** Query plan state recorded for this delivery: frozen, not_frozen, or planner_updated. Null for older deliveries and non-AI deliveries. */
    readonly ai_query_plan_status: AIQueryPlanStatusEnumApi | null
}

export interface PaginatedSubscriptionDeliveryListApi {
    count: number
    /** @nullable */
    next?: string | null
    /** @nullable */
    previous?: string | null
    results: SubscriptionDeliveryApi[]
}

export interface SubscriptionSummaryApi {
    /** ID of the delivery that included this summary. */
    readonly id: string
    /** ID of the subscription that generated this summary. */
    readonly subscription: number
    /**
     * Title of the subscription that generated this summary. Null when the subscription has no title.
     * @nullable
     */
    readonly subscription_title: string | null
    /** Channel the summary was sent to: email, slack, or teams. */
    readonly target_type: string
    /**
     * AI-generated summary text included in the delivery.
     * @nullable
     */
    readonly change_summary: string | null
    /**
     * Start of the period this summary covers: the time of the previous completed delivery of the same subscription. Null for the first delivery, which has no earlier data to compare with.
     * @nullable
     */
    readonly period_start: string | null
    /** When the delivery started. This is also the end of the covered period. */
    readonly created_at: string
}

export interface PaginatedSubscriptionSummaryListApi {
    count: number
    /** @nullable */
    next?: string | null
    /** @nullable */
    previous?: string | null
    results: SubscriptionSummaryApi[]
}

export type SubscriptionsListParams = {
    /**
     * Filter by creator user UUID.
     */
    created_by?: string
    /**
     * Filter by dashboard ID.
     */
    dashboard?: number
    /**
     * Filter to subscriptions on insights that are tiles of the given dashboard ID.
     */
    dashboard_tiles?: number
    /**
     * Filter by insight ID.
     */
    insight?: number
    /**
     * Filter by a comma-separated list of insight IDs.
     */
    insights?: string
    /**
     * Number of results to return per page.
     * @maximum 1000
     */
    limit?: number
    /**
     * The initial index from which to return the results.
     */
    offset?: number
    /**
     * Which field to use when ordering the results.
     */
    ordering?: string
    /**
     * Filter by subscription resource: insight, dashboard export, or AI report.
     */
    resource_type?: SubscriptionsListResourceType
    /**
     * A search term.
     */
    search?: string
    /**
     * Filter by delivery channel: email, Slack, or Microsoft Teams.
     */
    target_type?: SubscriptionsListTargetType
}

export type SubscriptionsListResourceType =
    (typeof SubscriptionsListResourceType)[keyof typeof SubscriptionsListResourceType]

export const SubscriptionsListResourceType = {
    AiPrompt: 'ai_prompt',
    Dashboard: 'dashboard',
    Insight: 'insight',
} as const

export type SubscriptionsListTargetType = (typeof SubscriptionsListTargetType)[keyof typeof SubscriptionsListTargetType]

export const SubscriptionsListTargetType = {
    Email: 'email',
    Slack: 'slack',
    Teams: 'teams',
} as const

export type SubscriptionsDeliveriesListParams = {
    /**
     * The pagination cursor value.
     */
    cursor?: string
    /**
     * Return only deliveries in this run status (starting, completed, failed, or skipped).
     */
    status?: SubscriptionsDeliveriesListStatus
}

export type SubscriptionsDeliveriesListStatus =
    (typeof SubscriptionsDeliveriesListStatus)[keyof typeof SubscriptionsDeliveriesListStatus]

export const SubscriptionsDeliveriesListStatus = {
    Completed: 'completed',
    Failed: 'failed',
    Skipped: 'skipped',
    Starting: 'starting',
} as const

export type SubscriptionsSummariesListParams = {
    /**
     * The pagination cursor value.
     */
    cursor?: string
    /**
     * Dashboard ID. Returns summaries from the subscriptions on this dashboard. Set either dashboard or insight.
     * @minimum 1
     */
    dashboard?: number
    /**
     * Insight ID. Returns summaries from the subscriptions on this insight. Set either insight or dashboard.
     * @minimum 1
     */
    insight?: number
}

export type SubscriptionsSummaryQuotaRetrieve200 = {
    active_count: number
    /** @nullable */
    limit: number | null
    at_limit: boolean
}