: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(endpoints): document the version param and the preview response (#104254)
Julian Bezab78ddc95786
diff --git a/products/endpoints/backend/presentation/views/api.py b/products/endpoints/backend/presentation/views/api.pyindex 3ac60b64dca7..e5892a0541bf 100644--- a/products/endpoints/backend/presentation/views/api.py+++ b/products/endpoints/backend/presentation/views/api.py@@ -18,6 +18,7 @@ from django.db.models import Count, F, Prefetchfrom django.shortcuts import get_object_or_404from django_filters.rest_framework import DjangoFilterBackend+from drf_spectacular.types import OpenApiTypesfrom drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema_viewfrom openai import APIConnectionErrorfrom pydantic import ValidationError as PydanticValidationError@@ -94,7 +95,9 @@ from products.endpoints.backend.presentation.throttles import (class MaterializationPreviewRequestSerializer(serializers.Serializer):- version = serializers.IntegerField(required=False)+ version = serializers.IntegerField(+ required=False, help_text="Endpoint version to preview. Defaults to the current version."+ )bucket_overrides = serializers.DictField(child=serializers.CharField(),required=False,@@ -103,6 +106,60 @@ class MaterializationPreviewRequestSerializer(serializers.Serializer):)+class MaterializationPreviewRangePairSerializer(serializers.Serializer):+ column = serializers.CharField(help_text="Column the query buckets on.")+ variables = serializers.ListField(+ child=serializers.CharField(),+ help_text="Query variables that filter on this column.",+ )+ bucket_fn = serializers.CharField(help_text="Bucket function applied to the column.")+++class MaterializationPreviewAggregateSerializer(serializers.Serializer):+ expression = serializers.CharField(help_text="Aggregate expression in the transformed query.")+ reaggregate_fn = serializers.CharField(+ allow_null=True,+ help_text="Function that combines materialized partials again, or null when there is none.",+ )+++class MaterializationPreviewResponseSerializer(serializers.Serializer):+ can_materialize = serializers.BooleanField(help_text="Whether the endpoint query can be materialized.")+ reason = serializers.CharField(+ allow_null=True,+ help_text="Why the query cannot be materialized, or null when it can.",+ )+ transformed_query = serializers.CharField(+ allow_null=True,+ help_text="Query rewritten for materialization, when one could be produced.",+ )+ execution_query = serializers.CharField(+ allow_null=True,+ help_text="Query that would run against the materialized table.",+ )+ display_execution_query = serializers.CharField(+ allow_null=True,+ help_text="Execution query formatted for display.",+ )+ range_pairs = MaterializationPreviewRangePairSerializer(+ many=True,+ help_text="Bucketed columns and the variables that filter on them.",+ )+ aggregates = MaterializationPreviewAggregateSerializer(+ many=True,+ help_text="Aggregate expressions and how to re-aggregate them.",+ )+++ENDPOINT_VERSION_PARAMETER = OpenApiParameter(+ name="version",+ type=OpenApiTypes.INT,+ location=OpenApiParameter.QUERY,+ required=False,+ description="Endpoint version to act on. Defaults to the current version.",+)++@extend_schema_view(partial_update=extend_schema(request=EndpointRequestSerializer,@@ -415,6 +472,7 @@ class EndpointViewSet(return Response({"results": results})@extend_schema(+ parameters=[ENDPOINT_VERSION_PARAMETER],responses={200: EndpointVersionResponseSerializer},description="Retrieve an endpoint, or a specific version via ?version=N.",)@@ -653,6 +711,7 @@ class EndpointViewSet(return Response({"results": results})@extend_schema(+ parameters=[ENDPOINT_VERSION_PARAMETER],responses={200: EndpointMaterializationSerializer},description="Get materialization status for an endpoint. Supports ?version=N query param.",)@@ -672,6 +731,7 @@ class EndpointViewSet(@validated_request(MaterializationPreviewRequestSerializer,+ responses={200: OpenApiResponse(response=MaterializationPreviewResponseSerializer)},description="Preview the materialization transform for an endpoint. Shows what the query will look like after materialization, including range pair detection and bucket functions.",)@action(methods=["POST"], detail=True, url_path="materialization_preview")@@ -809,15 +869,7 @@ class EndpointViewSet(# the `.` is rejected by lint_spec_consistency_hook + the MCP YAML scaffolder.operation_id="endpoints_openapi_spec_retrieve",description="Get OpenAPI 3.0 specification for this endpoint. Use this to generate typed SDK clients.",- parameters=[- OpenApiParameter(- name="version",- type=int,- location=OpenApiParameter.QUERY,- required=False,- description="Specific endpoint version to generate the spec for. Defaults to latest.",- ),- ],+ parameters=[ENDPOINT_VERSION_PARAMETER],)@action(methods=["GET"], detail=True, url_path="openapi.json")def openapi_spec(self, request: Request, name=None, *args, **kwargs) -> Response:diff --git a/products/endpoints/frontend/generated/api.schemas.ts b/products/endpoints/frontend/generated/api.schemas.tsindex 77b67591a162..21ef677aad09 100644--- a/products/endpoints/frontend/generated/api.schemas.ts+++ b/products/endpoints/frontend/generated/api.schemas.ts@@ -434,6 +434,7 @@ export interface PatchedEndpointRequestApi {export type MaterializationPreviewRequestApiBucketOverrides = { [key: string]: string } | nullexport interface MaterializationPreviewRequestApi {+ /** Endpoint version to preview. Defaults to the current version. */version?: number/*** Per-column bucket function overrides, e.g. {"timestamp": "hour"}@@ -442,6 +443,54 @@ export interface MaterializationPreviewRequestApi {bucket_overrides?: MaterializationPreviewRequestApiBucketOverrides}+export interface MaterializationPreviewRangePairApi {+ /** Column the query buckets on. */+ column: string+ /** Query variables that filter on this column. */+ variables: string[]+ /** Bucket function applied to the column. */+ bucket_fn: string+}++export interface MaterializationPreviewAggregateApi {+ /** Aggregate expression in the transformed query. */+ expression: string+ /**+ * Function that combines materialized partials again, or null when there is none.+ * @nullable+ */+ reaggregate_fn: string | null+}++export interface MaterializationPreviewResponseApi {+ /** Whether the endpoint query can be materialized. */+ can_materialize: boolean+ /**+ * Why the query cannot be materialized, or null when it can.+ * @nullable+ */+ reason: string | null+ /**+ * Query rewritten for materialization, when one could be produced.+ * @nullable+ */+ transformed_query: string | null+ /**+ * Query that would run against the materialized table.+ * @nullable+ */+ execution_query: string | null+ /**+ * Execution query formatted for display.+ * @nullable+ */+ display_execution_query: string | null+ /** Bucketed columns and the variables that filter on them. */+ range_pairs: MaterializationPreviewRangePairApi[]+ /** Aggregate expressions and how to re-aggregate them. */+ aggregates: MaterializationPreviewAggregateApi[]+}+/*** Request body for the AI materialization-fix suggestion action.*/@@ -1131,6 +1180,13 @@ export type EndpointsListParams = {offset?: number}+export type EndpointsRetrieveParams = {+ /**+ * Endpoint version to act on. Defaults to the current version.+ */+ version?: number+}+export type EndpointsLogsRetrieveParams = {/*** Only return entries after this ISO 8601 timestamp. Defaults to 7 days ago; pass an explicit value to read further back.@@ -1163,9 +1219,16 @@ export type EndpointsLogsRetrieveParams = {search?: string}+export type EndpointsMaterializationStatusRetrieveParams = {+ /**+ * Endpoint version to act on. Defaults to the current version.+ */+ version?: number+}+export type EndpointsOpenapiSpecRetrieveParams = {/**- * Specific endpoint version to generate the spec for. Defaults to latest.+ * Endpoint version to act on. Defaults to the current version.*/version?: number}diff --git a/products/endpoints/frontend/generated/api.ts b/products/endpoints/frontend/generated/api.tsindex d421b02b40c3..b20a318d8049 100644--- a/products/endpoints/frontend/generated/api.ts+++ b/products/endpoints/frontend/generated/api.ts@@ -21,9 +21,12 @@ import type {EndpointVersionResponseApi,EndpointsListParams,EndpointsLogsRetrieveParams,+ EndpointsMaterializationStatusRetrieveParams,EndpointsOpenapiSpecRetrieveParams,+ EndpointsRetrieveParams,EndpointsVersionsListParams,MaterializationPreviewRequestApi,+ MaterializationPreviewResponseApi,PaginatedEndpointResponseListApi,PaginatedEndpointVersionResponseListApi,PatchedEndpointRequestApi,@@ -80,8 +83,20 @@ export const endpointsCreate = async (})}-export const getEndpointsRetrieveUrl = (projectId: string, name: string) => {- return `/api/projects/${projectId}/endpoints/${name}/`+export const getEndpointsRetrieveUrl = (projectId: string, name: string, params?: EndpointsRetrieveParams) => {+ const normalizedParams = new URLSearchParams()++ Object.entries(params || {}).forEach(([key, value]) => {+ if (value !== undefined) {+ normalizedParams.append(key, value === null ? 'null' : String(value))+ }+ })++ const stringifiedParams = normalizedParams.toString()++ return stringifiedParams.length > 0+ ? `/api/projects/${projectId}/endpoints/${name}/?${stringifiedParams}`+ : `/api/projects/${projectId}/endpoints/${name}/`}/**@@ -90,9 +105,10 @@ export const getEndpointsRetrieveUrl = (projectId: string, name: string) => {export const endpointsRetrieve = async (projectId: string,name: string,+ params?: EndpointsRetrieveParams,options?: RequestInit): Promise<EndpointVersionResponseApi> => {- return apiMutator<EndpointVersionResponseApi>(getEndpointsRetrieveUrl(projectId, name), {+ return apiMutator<EndpointVersionResponseApi>(getEndpointsRetrieveUrl(projectId, name, params), {...options,method: 'GET',})@@ -194,8 +210,8 @@ export const endpointsMaterializationPreviewCreate = async (name: string,materializationPreviewRequestApi?: MaterializationPreviewRequestApi,options?: RequestInit-): Promise<void> => {- return apiMutator<void>(getEndpointsMaterializationPreviewCreateUrl(projectId, name), {+): Promise<MaterializationPreviewResponseApi> => {+ return apiMutator<MaterializationPreviewResponseApi>(getEndpointsMaterializationPreviewCreateUrl(projectId, name), {...options,method: 'POST',headers: { 'Content-Type': 'application/json', ...options?.headers },@@ -203,8 +219,24 @@ export const endpointsMaterializationPreviewCreate = async (})}-export const getEndpointsMaterializationStatusRetrieveUrl = (projectId: string, name: string) => {- return `/api/projects/${projectId}/endpoints/${name}/materialization_status/`+export const getEndpointsMaterializationStatusRetrieveUrl = (+ projectId: string,+ name: string,+ params?: EndpointsMaterializationStatusRetrieveParams+) => {+ const normalizedParams = new URLSearchParams()++ Object.entries(params || {}).forEach(([key, value]) => {+ if (value !== undefined) {+ normalizedParams.append(key, value === null ? 'null' : String(value))+ }+ })++ const stringifiedParams = normalizedParams.toString()++ return stringifiedParams.length > 0+ ? `/api/projects/${projectId}/endpoints/${name}/materialization_status/?${stringifiedParams}`+ : `/api/projects/${projectId}/endpoints/${name}/materialization_status/`}/**@@ -213,12 +245,16 @@ export const getEndpointsMaterializationStatusRetrieveUrl = (projectId: string,export const endpointsMaterializationStatusRetrieve = async (projectId: string,name: string,+ params?: EndpointsMaterializationStatusRetrieveParams,options?: RequestInit): Promise<EndpointMaterializationApi> => {- return apiMutator<EndpointMaterializationApi>(getEndpointsMaterializationStatusRetrieveUrl(projectId, name), {- ...options,- method: 'GET',- })+ return apiMutator<EndpointMaterializationApi>(+ getEndpointsMaterializationStatusRetrieveUrl(projectId, name, params),+ {+ ...options,+ method: 'GET',+ }+ )}export const getEndpointsMaterializationSuggestionCreateUrl = (projectId: string, name: string) => {diff --git a/products/endpoints/frontend/generated/api.zod.ts b/products/endpoints/frontend/generated/api.zod.tsindex 8ad7c2c48318..f19ba9b0b7b9 100644--- a/products/endpoints/frontend/generated/api.zod.ts+++ b/products/endpoints/frontend/generated/api.zod.ts@@ -169,7 +169,7 @@ export const EndpointsPartialUpdateBody = /* @__PURE__ */ zod* Preview the materialization transform for an endpoint. Shows what the query will look like after materialization, including range pair detection and bucket functions.*/export const EndpointsMaterializationPreviewCreateBody = /* @__PURE__ */ zod.object({- version: zod.number().optional(),+ version: zod.number().optional().describe('Endpoint version to preview. Defaults to the current version.'),bucket_overrides: zod.record(zod.string(), zod.string()).nullish()diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.tsindex eed93986064d..bf66516d9c80 100644--- a/services/mcp/src/api/generated.ts+++ b/services/mcp/src/api/generated.ts@@ -58460,6 +58460,25 @@ export namespace Schemas {Value: 'value',} as const;+ export interface MaterializationPreviewAggregate {+ /** Aggregate expression in the transformed query. */+ expression: string;+ /**+ * Function that combines materialized partials again, or null when there is none.+ * @nullable+ */+ reaggregate_fn: string | null;+ }++ export interface MaterializationPreviewRangePair {+ /** Column the query buckets on. */+ column: string;+ /** Query variables that filter on this column. */+ variables: string[];+ /** Bucket function applied to the column. */+ bucket_fn: string;+ }+/*** Per-column bucket function overrides, e.g. {"timestamp": "hour"}* @nullable@@ -58467,6 +58486,7 @@ export namespace Schemas {export type MaterializationPreviewRequestBucketOverrides = {[key: string]: string} | null;export interface MaterializationPreviewRequest {+ /** Endpoint version to preview. Defaults to the current version. */version?: number;/*** Per-column bucket function overrides, e.g. {"timestamp": "hour"}@@ -58475,6 +58495,35 @@ export namespace Schemas {bucket_overrides?: MaterializationPreviewRequestBucketOverrides;}+ export interface MaterializationPreviewResponse {+ /** Whether the endpoint query can be materialized. */+ can_materialize: boolean;+ /**+ * Why the query cannot be materialized, or null when it can.+ * @nullable+ */+ reason: string | null;+ /**+ * Query rewritten for materialization, when one could be produced.+ * @nullable+ */+ transformed_query: string | null;+ /**+ * Query that would run against the materialized table.+ * @nullable+ */+ execution_query: string | null;+ /**+ * Execution query formatted for display.+ * @nullable+ */+ display_execution_query: string | null;+ /** Bucketed columns and the variables that filter on them. */+ range_pairs: MaterializationPreviewRangePair[];+ /** Aggregate expressions and how to re-aggregate them. */+ aggregates: MaterializationPreviewAggregate[];+ }+/*** Input for materializing the labeled training feature matrix into the run's sandbox.*/@@ -105660,6 +105709,13 @@ export namespace Schemas {offset?: number;};+ export type EndpointsRetrieveParams = {+ /**+ * Endpoint version to act on. Defaults to the current version.+ */+ version?: number;+ };+export type EndpointsLogsRetrieveParams = {/*** Only return entries after this ISO 8601 timestamp. Defaults to 7 days ago; pass an explicit value to read further back.@@ -105692,9 +105748,16 @@ export namespace Schemas {search?: string;};+ export type EndpointsMaterializationStatusRetrieveParams = {+ /**+ * Endpoint version to act on. Defaults to the current version.+ */+ version?: number;+ };+export type EndpointsOpenapiSpecRetrieveParams = {/**- * Specific endpoint version to generate the spec for. Defaults to latest.+ * Endpoint version to act on. Defaults to the current version.*/version?: number;};diff --git a/services/mcp/src/generated/endpoints/api.ts b/services/mcp/src/generated/endpoints/api.tsindex ac7b02c83e23..ff2040fa15ac 100644--- a/services/mcp/src/generated/endpoints/api.ts+++ b/services/mcp/src/generated/endpoints/api.ts@@ -98,6 +98,10 @@ export const EndpointsRetrieveParams = () => zod.object({),})+export const EndpointsRetrieveQueryParams = () => zod.object({+ version: zod.number().optional().describe('Endpoint version to act on. Defaults to the current version.'),+})+/*** Update an existing endpoint.*/@@ -224,7 +228,7 @@ export const EndpointsMaterializationPreviewCreateParams = () => zod.object({})export const EndpointsMaterializationPreviewCreateBody = () => zod.object({- version: zod.number().optional(),+ version: zod.number().optional().describe('Endpoint version to preview. Defaults to the current version.'),bucket_overrides: zod.record(zod.string(), zod.string()).nullish()@@ -243,6 +247,10 @@ export const EndpointsMaterializationStatusRetrieveParams = () => zod.object({),})+export const EndpointsMaterializationStatusRetrieveQueryParams = () => zod.object({+ version: zod.number().optional().describe('Endpoint version to act on. Defaults to the current version.'),+})+/*** Ask AI to rewrite the endpoint's query into a semantically equivalent form that can be materialized. Only applicable to SQL (HogQL) endpoints that currently fail the materialization checks. The suggestion is validated against the live checks before being returned; nothing is saved. Requires the organization's AI data processing approval.*/@@ -277,10 +285,7 @@ export const EndpointsOpenapiSpecRetrieveParams = () => zod.object({})export const EndpointsOpenapiSpecRetrieveQueryParams = () => zod.object({- version: zod- .number()- .optional()- .describe('Specific endpoint version to generate the spec for. Defaults to latest.'),+ version: zod.number().optional().describe('Endpoint version to act on. Defaults to the current version.'),})/**diff --git a/services/mcp/src/tools/generated/endpoints.ts b/services/mcp/src/tools/generated/endpoints.tsindex f8747ea13dc1..e5759198e08a 100644--- a/services/mcp/src/tools/generated/endpoints.ts+++ b/services/mcp/src/tools/generated/endpoints.ts@@ -75,7 +75,8 @@ const endpointDelete = (): ToolBase<ReturnType<typeof EndpointDeleteSchema>, Schconst EndpointGetSchema = () => {const EndpointsRetrieveParams = orvalSchemas.EndpointsRetrieveParams()- return EndpointsRetrieveParams.omit({ project_id: true })+ const EndpointsRetrieveQueryParams = orvalSchemas.EndpointsRetrieveQueryParams()+ return EndpointsRetrieveParams.omit({ project_id: true }).extend(EndpointsRetrieveQueryParams.shape)}const endpointGet = (): ToolBase<@@ -89,6 +90,9 @@ const endpointGet = (): ToolBase<const result = await context.api.request<Schemas.EndpointVersionResponse>({method: 'GET',path: `/api/projects/${encodeURIComponent(String(projectId))}/endpoints/${encodeURIComponent(String(params.name))}/`,+ query: {+ version: params.version,+ },})return await withPostHogUrl(context, result, `/endpoints/${result.name}`)},@@ -141,7 +145,11 @@ const endpointMaterializationConditions = (): ToolBase<const EndpointMaterializationStatusSchema = () => {const EndpointsMaterializationStatusRetrieveParams = orvalSchemas.EndpointsMaterializationStatusRetrieveParams()- return EndpointsMaterializationStatusRetrieveParams.omit({ project_id: true })+ const EndpointsMaterializationStatusRetrieveQueryParams =+ orvalSchemas.EndpointsMaterializationStatusRetrieveQueryParams()+ return EndpointsMaterializationStatusRetrieveParams.omit({ project_id: true }).extend(+ EndpointsMaterializationStatusRetrieveQueryParams.shape+ )}const endpointMaterializationStatus = (): ToolBase<@@ -155,6 +163,9 @@ const endpointMaterializationStatus = (): ToolBase<const result = await context.api.request<Schemas.EndpointMaterialization>({method: 'GET',path: `/api/projects/${encodeURIComponent(String(projectId))}/endpoints/${encodeURIComponent(String(params.name))}/materialization_status/`,+ query: {+ version: params.version,+ },})return await withPostHogUrl(context, result, `/endpoints/${result.name}`)},@@ -420,7 +431,7 @@ const EndpointsMaterializationPreviewSchema = () => {const endpointsMaterializationPreview = (): ToolBase<ReturnType<typeof EndpointsMaterializationPreviewSchema>,- unknown+ WithPostHogUrl<Schemas.MaterializationPreviewResponse>> => ({name: 'endpoints-materialization-preview',schema: EndpointsMaterializationPreviewSchema(),@@ -433,7 +444,7 @@ const endpointsMaterializationPreview = (): ToolBase<if (params.bucket_overrides !== undefined) {body['bucket_overrides'] = params.bucket_overrides}- const result = await context.api.request<unknown>({+ const result = await context.api.request<Schemas.MaterializationPreviewResponse>({method: 'POST',path: `/api/projects/${encodeURIComponent(String(projectId))}/endpoints/${encodeURIComponent(String(params.name))}/materialization_preview/`,body,diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoint-get.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoint-get.jsonindex 9e5b1c2b1d59..7fd9093d891a 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoint-get.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoint-get.json@@ -3,6 +3,10 @@"properties": {"name": {"type": "string"+ },+ "version": {+ "description": "Endpoint version to act on. Defaults to the current version.",+ "type": "number"}},"required": ["name"],diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoint-materialization-status.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoint-materialization-status.jsonindex 9e5b1c2b1d59..7fd9093d891a 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoint-materialization-status.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoint-materialization-status.json@@ -3,6 +3,10 @@"properties": {"name": {"type": "string"+ },+ "version": {+ "description": "Endpoint version to act on. Defaults to the current version.",+ "type": "number"}},"required": ["name"],diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoint-openapi-spec.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoint-openapi-spec.jsonindex e33ad58ce416..7fd9093d891a 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoint-openapi-spec.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoint-openapi-spec.json@@ -5,7 +5,7 @@"type": "string"},"version": {- "description": "Specific endpoint version to generate the spec for. Defaults to latest.",+ "description": "Endpoint version to act on. Defaults to the current version.","type": "number"}},diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoints-materialization-preview.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoints-materialization-preview.jsonindex 3d8bf6c6ac68..a38f5a6d05dc 100644--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoints-materialization-preview.json+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/endpoints-materialization-preview.json@@ -22,6 +22,7 @@"type": "string"},"version": {+ "description": "Endpoint version to preview. Defaults to the current version.","type": "number"}},