Experiments

For instructions on how to authenticate to use this endpoint, see API overview.

Endpoints

GET
POST
GET
PATCH
DELETE
POST
POST
POST
POST
POST
POST
POST
POST
POST
POST
POST
GET
POST
POST

List all experiments

List experiments for the current project. Supports filtering by status and archival state.

Required API key scopes

experiment:read

Query parameters

  • archived
    boolean
  • created_by_id
    integer
  • feature_flag_id
    integer
  • limit
    integer
  • offset
    integer
  • order
    string
  • prompt_name
    string
  • search
    string
  • status
    string
    One of: "all""complete""draft""paused""running""stopped"

Response


Example request

GET /api/projects/:project_id/experiments
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/

Example response

Status 200
RESPONSE
{
"count": 123,
"next": "http://api.example.org/accounts/?offset=400&limit=100",
"previous": "http://api.example.org/accounts/?offset=200&limit=100",
"results": [
{
"id": 0,
"name": "string",
"description": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"feature_flag_key": "string",
"feature_flag": {},
"holdout": {
"id": 0,
"name": "string",
"description": "string",
"filters": null,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
},
"holdout_id": 0,
"exposure_cohort": 0,
"parameters": {
"excluded_variants": null,
"feature_flag_variants": null,
"minimum_detectable_effect": null,
"rollout_percentage": null
},
"secondary_metrics": null,
"saved_metrics": [
{
"id": 0,
"experiment": 0,
"saved_metric": 0,
"metadata": null,
"created_at": "2019-08-24T14:15:22Z",
"query": null,
"name": "string"
}
],
"saved_metrics_ids": [
null
],
"filters": null,
"archived": false,
"deleted": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"type": "web",
"exposure_criteria": {
"exposure_config": null,
"filterTestAccounts": null
},
"metrics": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"metrics_secondary": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"stats_config": null,
"scheduling_config": null,
"allow_unknown_events": false,
"_create_in_folder": "string",
"conclusion": "won",
"conclusion_comment": "string",
"primary_metrics_ordered_uuids": null,
"secondary_metrics_ordered_uuids": null,
"only_count_matured_users": true,
"update_feature_flag_params": false,
"status": "draft",
"user_access_level": "string"
}
]
}

Create experiments

Also available via the PostHog MCP server:

  • experiment-createCreate experiment

Create a new experiment in draft status with optional metrics.

Required API key scopes

experiment:write

Request parameters

  • name
    string
  • description
    stringnull
  • start_date
    stringnull
  • end_date
    stringnull
  • feature_flag_key
    string
  • holdout_id
    integernull
  • parameters
  • secondary_metrics
  • saved_metrics_ids
    arraynull
  • filters
  • archived
    boolean
    Default: false
  • deleted
    booleannull
  • type
  • exposure_criteria
  • metrics
  • metrics_secondary
  • stats_config
  • scheduling_config
  • allow_unknown_events
    boolean
    Default: false
  • _create_in_folder
    string
  • conclusion
  • conclusion_comment
    stringnull
  • primary_metrics_ordered_uuids
  • secondary_metrics_ordered_uuids
  • only_count_matured_users
    boolean
  • update_feature_flag_params
    boolean
    Default: false

Response


Example request

POST /api/projects/:project_id/experiments
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/\
-d name="string",\
-d feature_flag_key="string"

Example response

Status 201
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"feature_flag_key": "string",
"feature_flag": {},
"holdout": {
"id": 0,
"name": "string",
"description": "string",
"filters": null,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
},
"holdout_id": 0,
"exposure_cohort": 0,
"parameters": {
"excluded_variants": null,
"feature_flag_variants": null,
"minimum_detectable_effect": null,
"rollout_percentage": null
},
"secondary_metrics": null,
"saved_metrics": [
{
"id": 0,
"experiment": 0,
"saved_metric": 0,
"metadata": null,
"created_at": "2019-08-24T14:15:22Z",
"query": null,
"name": "string"
}
],
"saved_metrics_ids": [
null
],
"filters": null,
"archived": false,
"deleted": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"type": "web",
"exposure_criteria": {
"exposure_config": null,
"filterTestAccounts": null
},
"metrics": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"metrics_secondary": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"stats_config": null,
"scheduling_config": null,
"allow_unknown_events": false,
"_create_in_folder": "string",
"conclusion": "won",
"conclusion_comment": "string",
"primary_metrics_ordered_uuids": null,
"secondary_metrics_ordered_uuids": null,
"only_count_matured_users": true,
"update_feature_flag_params": false,
"status": "draft",
"user_access_level": "string"
}

Retrieve experiments

Also available via the PostHog MCP server:

  • experiment-getGet experiment details

Retrieve a single experiment by ID, including its current status, metrics, feature flag, and results metadata.

Required API key scopes

experiment:read

Path parameters

  • id
    integer

Response


Example request

GET /api/projects/:project_id/experiments/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/

Example response

Status 200
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"feature_flag_key": "string",
"feature_flag": {},
"holdout": {
"id": 0,
"name": "string",
"description": "string",
"filters": null,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
},
"holdout_id": 0,
"exposure_cohort": 0,
"parameters": {
"excluded_variants": null,
"feature_flag_variants": null,
"minimum_detectable_effect": null,
"rollout_percentage": null
},
"secondary_metrics": null,
"saved_metrics": [
{
"id": 0,
"experiment": 0,
"saved_metric": 0,
"metadata": null,
"created_at": "2019-08-24T14:15:22Z",
"query": null,
"name": "string"
}
],
"saved_metrics_ids": [
null
],
"filters": null,
"archived": false,
"deleted": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"type": "web",
"exposure_criteria": {
"exposure_config": null,
"filterTestAccounts": null
},
"metrics": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"metrics_secondary": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"stats_config": null,
"scheduling_config": null,
"allow_unknown_events": false,
"_create_in_folder": "string",
"conclusion": "won",
"conclusion_comment": "string",
"primary_metrics_ordered_uuids": null,
"secondary_metrics_ordered_uuids": null,
"only_count_matured_users": true,
"update_feature_flag_params": false,
"status": "draft",
"user_access_level": "string"
}

Update experiments

Also available via the PostHog MCP server:

  • experiment-updateUpdate experiment

Update an experiment. Use this to modify experiment properties such as name, description, metrics, variants, and configuration. Metrics can be added, changed and removed at any time.

Required API key scopes

experiment:write

Path parameters

  • id
    integer

Request parameters

  • name
    string
  • description
    stringnull
  • start_date
    stringnull
  • end_date
    stringnull
  • feature_flag_key
    string
  • holdout_id
    integernull
  • parameters
  • secondary_metrics
  • saved_metrics_ids
    arraynull
  • filters
  • archived
    boolean
    Default: false
  • deleted
    booleannull
  • type
  • exposure_criteria
  • metrics
  • metrics_secondary
  • stats_config
  • scheduling_config
  • allow_unknown_events
    boolean
    Default: false
  • _create_in_folder
    string
  • conclusion
  • conclusion_comment
    stringnull
  • primary_metrics_ordered_uuids
  • secondary_metrics_ordered_uuids
  • only_count_matured_users
    boolean
  • update_feature_flag_params
    boolean
    Default: false

Response


Example request

PATCH /api/projects/:project_id/experiments/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X PATCH \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/\
-d name="string"

Example response

Status 200
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"feature_flag_key": "string",
"feature_flag": {},
"holdout": {
"id": 0,
"name": "string",
"description": "string",
"filters": null,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
},
"holdout_id": 0,
"exposure_cohort": 0,
"parameters": {
"excluded_variants": null,
"feature_flag_variants": null,
"minimum_detectable_effect": null,
"rollout_percentage": null
},
"secondary_metrics": null,
"saved_metrics": [
{
"id": 0,
"experiment": 0,
"saved_metric": 0,
"metadata": null,
"created_at": "2019-08-24T14:15:22Z",
"query": null,
"name": "string"
}
],
"saved_metrics_ids": [
null
],
"filters": null,
"archived": false,
"deleted": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"type": "web",
"exposure_criteria": {
"exposure_config": null,
"filterTestAccounts": null
},
"metrics": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"metrics_secondary": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"stats_config": null,
"scheduling_config": null,
"allow_unknown_events": false,
"_create_in_folder": "string",
"conclusion": "won",
"conclusion_comment": "string",
"primary_metrics_ordered_uuids": null,
"secondary_metrics_ordered_uuids": null,
"only_count_matured_users": true,
"update_feature_flag_params": false,
"status": "draft",
"user_access_level": "string"
}

Delete experiments

Hard delete of this model is not allowed. Use a patch API call to set "deleted" to true

Required API key scopes

experiment:write

Path parameters

  • id
    integer

Example request

DELETE /api/projects/:project_id/experiments/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X DELETE \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/

Example response

Status 405 No response body

Create experiments archive

Archive an ended experiment.

Hides the experiment from the default list view. The experiment can be restored at any time by updating archived=false. Returns 400 if the experiment is already archived or has not ended yet.

Required API key scopes

experiment:write

Path parameters

  • id
    integer

Response


Example request

POST /api/projects/:project_id/experiments/:id/archive
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/archive/

Example response

Status 200
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"feature_flag_key": "string",
"feature_flag": {},
"holdout": {
"id": 0,
"name": "string",
"description": "string",
"filters": null,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
},
"holdout_id": 0,
"exposure_cohort": 0,
"parameters": {
"excluded_variants": null,
"feature_flag_variants": null,
"minimum_detectable_effect": null,
"rollout_percentage": null
},
"secondary_metrics": null,
"saved_metrics": [
{
"id": 0,
"experiment": 0,
"saved_metric": 0,
"metadata": null,
"created_at": "2019-08-24T14:15:22Z",
"query": null,
"name": "string"
}
],
"saved_metrics_ids": [
null
],
"filters": null,
"archived": false,
"deleted": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"type": "web",
"exposure_criteria": {
"exposure_config": null,
"filterTestAccounts": null
},
"metrics": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"metrics_secondary": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"stats_config": null,
"scheduling_config": null,
"allow_unknown_events": false,
"_create_in_folder": "string",
"conclusion": "won",
"conclusion_comment": "string",
"primary_metrics_ordered_uuids": null,
"secondary_metrics_ordered_uuids": null,
"only_count_matured_users": true,
"update_feature_flag_params": false,
"status": "draft",
"user_access_level": "string"
}

Create experiments copy to project

Mixin for ViewSets to handle ApprovalRequired exceptions from decorated serializers.

This mixin intercepts ApprovalRequired exceptions raised by the @approval_gate decorator on serializer methods and converts them into proper HTTP 409 Conflict responses with change request details.

Required API key scopes

experiment:write

Path parameters

  • id
    integer

Request parameters

  • target_team_id
    integer
  • feature_flag_key
    string
  • name
    string

Response


Example request

POST /api/projects/:project_id/experiments/:id/copy_to_project
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/copy_to_project/\
-d target_team_id="integer"

Example response

Status 200
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"feature_flag_key": "string",
"feature_flag": {},
"holdout": {
"id": 0,
"name": "string",
"description": "string",
"filters": null,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
},
"holdout_id": 0,
"exposure_cohort": 0,
"parameters": {
"excluded_variants": null,
"feature_flag_variants": null,
"minimum_detectable_effect": null,
"rollout_percentage": null
},
"secondary_metrics": null,
"saved_metrics": [
{
"id": 0,
"experiment": 0,
"saved_metric": 0,
"metadata": null,
"created_at": "2019-08-24T14:15:22Z",
"query": null,
"name": "string"
}
],
"saved_metrics_ids": [
null
],
"filters": null,
"archived": false,
"deleted": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"type": "web",
"exposure_criteria": {
"exposure_config": null,
"filterTestAccounts": null
},
"metrics": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"metrics_secondary": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"stats_config": null,
"scheduling_config": null,
"allow_unknown_events": false,
"_create_in_folder": "string",
"conclusion": "won",
"conclusion_comment": "string",
"primary_metrics_ordered_uuids": null,
"secondary_metrics_ordered_uuids": null,
"only_count_matured_users": true,
"update_feature_flag_params": false,
"status": "draft",
"user_access_level": "string"
}

Create experiments create exposure cohort for experiment

Mixin for ViewSets to handle ApprovalRequired exceptions from decorated serializers.

This mixin intercepts ApprovalRequired exceptions raised by the @approval_gate decorator on serializer methods and converts them into proper HTTP 409 Conflict responses with change request details.

Required API key scopes

experiment:write

Path parameters

  • id
    integer

Request parameters

  • name
    string
  • description
    stringnull
  • start_date
    stringnull
  • end_date
    stringnull
  • feature_flag_key
    string
  • holdout_id
    integernull
  • parameters
  • secondary_metrics
  • saved_metrics_ids
    arraynull
  • filters
  • archived
    boolean
    Default: false
  • deleted
    booleannull
  • type
  • exposure_criteria
  • metrics
  • metrics_secondary
  • stats_config
  • scheduling_config
  • allow_unknown_events
    boolean
    Default: false
  • _create_in_folder
    string
  • conclusion
  • conclusion_comment
    stringnull
  • primary_metrics_ordered_uuids
  • secondary_metrics_ordered_uuids
  • only_count_matured_users
    boolean
  • update_feature_flag_params
    boolean
    Default: false

Example request

POST /api/projects/:project_id/experiments/:id/create_exposure_cohort_for_experiment
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/create_exposure_cohort_for_experiment/\
-d name="string",\
-d feature_flag_key="string"

Example response

Status 200 No response body

Create experiments duplicate

Mixin for ViewSets to handle ApprovalRequired exceptions from decorated serializers.

This mixin intercepts ApprovalRequired exceptions raised by the @approval_gate decorator on serializer methods and converts them into proper HTTP 409 Conflict responses with change request details.

Required API key scopes

experiment:write

Path parameters

  • id
    integer

Request parameters

  • name
    string
  • description
    stringnull
  • start_date
    stringnull
  • end_date
    stringnull
  • feature_flag_key
    string
  • holdout_id
    integernull
  • parameters
  • secondary_metrics
  • saved_metrics_ids
    arraynull
  • filters
  • archived
    boolean
    Default: false
  • deleted
    booleannull
  • type
  • exposure_criteria
  • metrics
  • metrics_secondary
  • stats_config
  • scheduling_config
  • allow_unknown_events
    boolean
    Default: false
  • _create_in_folder
    string
  • conclusion
  • conclusion_comment
    stringnull
  • primary_metrics_ordered_uuids
  • secondary_metrics_ordered_uuids
  • only_count_matured_users
    boolean
  • update_feature_flag_params
    boolean
    Default: false

Example request

POST /api/projects/:project_id/experiments/:id/duplicate
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/duplicate/\
-d name="string",\
-d feature_flag_key="string"

Example response

Status 200 No response body

Create experiments end

End a running experiment without shipping a variant.

Sets end_date to now and marks the experiment as stopped. The feature flag is NOT modified — users continue to see their assigned variants and exposure events ($feature_flag_called) continue to be recorded. However, only data up to end_date is included in experiment results.

Use this when:

  • You want to freeze the results window without changing which variant users see.
  • A variant was already shipped manually via the feature flag UI and the experiment just needs to be marked complete.

The end_date can be adjusted after ending via PATCH if it needs to be backdated (e.g. to match when the flag was actually paused).

Other options:

  • Use ship_variant to end the experiment AND roll out a single variant to 100%% of users.
  • Use pause to deactivate the flag without ending the experiment (stops variant assignment but does not freeze results).

Returns 400 if the experiment is not running.

Required API key scopes

experiment:write

Path parameters

  • id
    integer

Request parameters

  • conclusion
  • conclusion_comment
    stringnull

Response


Example request

POST /api/projects/:project_id/experiments/:id/end
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/end/\
-d conclusion=undefined

Example response

Status 200
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"feature_flag_key": "string",
"feature_flag": {},
"holdout": {
"id": 0,
"name": "string",
"description": "string",
"filters": null,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
},
"holdout_id": 0,
"exposure_cohort": 0,
"parameters": {
"excluded_variants": null,
"feature_flag_variants": null,
"minimum_detectable_effect": null,
"rollout_percentage": null
},
"secondary_metrics": null,
"saved_metrics": [
{
"id": 0,
"experiment": 0,
"saved_metric": 0,
"metadata": null,
"created_at": "2019-08-24T14:15:22Z",
"query": null,
"name": "string"
}
],
"saved_metrics_ids": [
null
],
"filters": null,
"archived": false,
"deleted": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"type": "web",
"exposure_criteria": {
"exposure_config": null,
"filterTestAccounts": null
},
"metrics": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"metrics_secondary": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"stats_config": null,
"scheduling_config": null,
"allow_unknown_events": false,
"_create_in_folder": "string",
"conclusion": "won",
"conclusion_comment": "string",
"primary_metrics_ordered_uuids": null,
"secondary_metrics_ordered_uuids": null,
"only_count_matured_users": true,
"update_feature_flag_params": false,
"status": "draft",
"user_access_level": "string"
}

Create experiments launch

Launch a draft experiment.

Validates the experiment is in draft state, activates its linked feature flag, sets start_date to the current server time, and transitions the experiment to running. Returns 400 if the experiment has already been launched or if the feature flag configuration is invalid (e.g. missing "control" variant or fewer than 2 variants).

Required API key scopes

experiment:write

Path parameters

  • id
    integer

Response


Example request

POST /api/projects/:project_id/experiments/:id/launch
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/launch/

Example response

Status 200
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"feature_flag_key": "string",
"feature_flag": {},
"holdout": {
"id": 0,
"name": "string",
"description": "string",
"filters": null,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
},
"holdout_id": 0,
"exposure_cohort": 0,
"parameters": {
"excluded_variants": null,
"feature_flag_variants": null,
"minimum_detectable_effect": null,
"rollout_percentage": null
},
"secondary_metrics": null,
"saved_metrics": [
{
"id": 0,
"experiment": 0,
"saved_metric": 0,
"metadata": null,
"created_at": "2019-08-24T14:15:22Z",
"query": null,
"name": "string"
}
],
"saved_metrics_ids": [
null
],
"filters": null,
"archived": false,
"deleted": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"type": "web",
"exposure_criteria": {
"exposure_config": null,
"filterTestAccounts": null
},
"metrics": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"metrics_secondary": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"stats_config": null,
"scheduling_config": null,
"allow_unknown_events": false,
"_create_in_folder": "string",
"conclusion": "won",
"conclusion_comment": "string",
"primary_metrics_ordered_uuids": null,
"secondary_metrics_ordered_uuids": null,
"only_count_matured_users": true,
"update_feature_flag_params": false,
"status": "draft",
"user_access_level": "string"
}

Create experiments pause

Pause a running experiment.

Deactivates the linked feature flag so it is no longer returned by the /decide endpoint. Users fall back to the application default (typically the control experience), and no new exposure events are recorded (i.e. $feature_flag_called is not fired). Returns 400 if the experiment is not running or is already paused.

Required API key scopes

experiment:write

Path parameters

  • id
    integer

Response


Example request

POST /api/projects/:project_id/experiments/:id/pause
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/pause/

Example response

Status 200
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"feature_flag_key": "string",
"feature_flag": {},
"holdout": {
"id": 0,
"name": "string",
"description": "string",
"filters": null,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
},
"holdout_id": 0,
"exposure_cohort": 0,
"parameters": {
"excluded_variants": null,
"feature_flag_variants": null,
"minimum_detectable_effect": null,
"rollout_percentage": null
},
"secondary_metrics": null,
"saved_metrics": [
{
"id": 0,
"experiment": 0,
"saved_metric": 0,
"metadata": null,
"created_at": "2019-08-24T14:15:22Z",
"query": null,
"name": "string"
}
],
"saved_metrics_ids": [
null
],
"filters": null,
"archived": false,
"deleted": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"type": "web",
"exposure_criteria": {
"exposure_config": null,
"filterTestAccounts": null
},
"metrics": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"metrics_secondary": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"stats_config": null,
"scheduling_config": null,
"allow_unknown_events": false,
"_create_in_folder": "string",
"conclusion": "won",
"conclusion_comment": "string",
"primary_metrics_ordered_uuids": null,
"secondary_metrics_ordered_uuids": null,
"only_count_matured_users": true,
"update_feature_flag_params": false,
"status": "draft",
"user_access_level": "string"
}

Create experiments recalculate timeseries

Mixin for ViewSets to handle ApprovalRequired exceptions from decorated serializers.

This mixin intercepts ApprovalRequired exceptions raised by the @approval_gate decorator on serializer methods and converts them into proper HTTP 409 Conflict responses with change request details.

Required API key scopes

experiment:write

Path parameters

  • id
    integer

Request parameters

  • name
    string
  • description
    stringnull
  • start_date
    stringnull
  • end_date
    stringnull
  • feature_flag_key
    string
  • holdout_id
    integernull
  • parameters
  • secondary_metrics
  • saved_metrics_ids
    arraynull
  • filters
  • archived
    boolean
    Default: false
  • deleted
    booleannull
  • type
  • exposure_criteria
  • metrics
  • metrics_secondary
  • stats_config
  • scheduling_config
  • allow_unknown_events
    boolean
    Default: false
  • _create_in_folder
    string
  • conclusion
  • conclusion_comment
    stringnull
  • primary_metrics_ordered_uuids
  • secondary_metrics_ordered_uuids
  • only_count_matured_users
    boolean
  • update_feature_flag_params
    boolean
    Default: false

Example request

POST /api/projects/:project_id/experiments/:id/recalculate_timeseries
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/recalculate_timeseries/\
-d name="string",\
-d feature_flag_key="string"

Example response

Status 200 No response body

Create experiments reset

Reset an experiment back to draft state.

Clears start/end dates, conclusion, and archived flag. The feature flag is left unchanged — users continue to see their assigned variants.

Previously collected events still exist but won't be included in results unless the start date is manually adjusted after re-launch.

Returns 400 if the experiment is already in draft state.

Required API key scopes

experiment:write

Path parameters

  • id
    integer

Response


Example request

POST /api/projects/:project_id/experiments/:id/reset
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/reset/

Example response

Status 200
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"feature_flag_key": "string",
"feature_flag": {},
"holdout": {
"id": 0,
"name": "string",
"description": "string",
"filters": null,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
},
"holdout_id": 0,
"exposure_cohort": 0,
"parameters": {
"excluded_variants": null,
"feature_flag_variants": null,
"minimum_detectable_effect": null,
"rollout_percentage": null
},
"secondary_metrics": null,
"saved_metrics": [
{
"id": 0,
"experiment": 0,
"saved_metric": 0,
"metadata": null,
"created_at": "2019-08-24T14:15:22Z",
"query": null,
"name": "string"
}
],
"saved_metrics_ids": [
null
],
"filters": null,
"archived": false,
"deleted": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"type": "web",
"exposure_criteria": {
"exposure_config": null,
"filterTestAccounts": null
},
"metrics": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"metrics_secondary": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"stats_config": null,
"scheduling_config": null,
"allow_unknown_events": false,
"_create_in_folder": "string",
"conclusion": "won",
"conclusion_comment": "string",
"primary_metrics_ordered_uuids": null,
"secondary_metrics_ordered_uuids": null,
"only_count_matured_users": true,
"update_feature_flag_params": false,
"status": "draft",
"user_access_level": "string"
}

Create experiments resume

Resume a paused experiment.

Reactivates the linked feature flag so it is returned by /decide again. Users are re-bucketed deterministically into the same variants they had before the pause, and exposure tracking resumes. Returns 400 if the experiment is not running or is not paused.

Required API key scopes

experiment:write

Path parameters

  • id
    integer

Response


Example request

POST /api/projects/:project_id/experiments/:id/resume
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/resume/

Example response

Status 200
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"feature_flag_key": "string",
"feature_flag": {},
"holdout": {
"id": 0,
"name": "string",
"description": "string",
"filters": null,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
},
"holdout_id": 0,
"exposure_cohort": 0,
"parameters": {
"excluded_variants": null,
"feature_flag_variants": null,
"minimum_detectable_effect": null,
"rollout_percentage": null
},
"secondary_metrics": null,
"saved_metrics": [
{
"id": 0,
"experiment": 0,
"saved_metric": 0,
"metadata": null,
"created_at": "2019-08-24T14:15:22Z",
"query": null,
"name": "string"
}
],
"saved_metrics_ids": [
null
],
"filters": null,
"archived": false,
"deleted": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"type": "web",
"exposure_criteria": {
"exposure_config": null,
"filterTestAccounts": null
},
"metrics": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"metrics_secondary": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"stats_config": null,
"scheduling_config": null,
"allow_unknown_events": false,
"_create_in_folder": "string",
"conclusion": "won",
"conclusion_comment": "string",
"primary_metrics_ordered_uuids": null,
"secondary_metrics_ordered_uuids": null,
"only_count_matured_users": true,
"update_feature_flag_params": false,
"status": "draft",
"user_access_level": "string"
}

Create experiments ship variant

Ship a variant and (optionally) end the experiment.

Updates the feature flag so the selected variant gets 100% of the variant distribution. By default, existing release conditions on the flag are preserved untouched — the variant is served only to users who already match them. Pass release_to_everyone: true to also prepend a catch-all release condition that rolls the variant out to 100% of users (overrides any existing release conditions on the flag).

Can be called on both running and stopped experiments. If the experiment is still running, it will also be ended (end_date set and status marked as stopped). If the experiment has already ended, only the flag is rewritten - this supports the "end first, ship later" workflow.

If an approval policy requires review before changes on the flag take effect, the API returns 409 with a change_request_id. The experiment is NOT ended until the change request is approved and the user retries.

Returns 400 if the experiment is in draft state, the variant_key is not found on the flag, or the experiment has no linked feature flag.

Required API key scopes

experiment:write

Path parameters

  • id
    integer

Request parameters

  • conclusion
  • conclusion_comment
    stringnull
  • variant_key
    string
  • release_to_everyone
    boolean
    Default: false

Response


Example request

POST /api/projects/:project_id/experiments/:id/ship_variant
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/ship_variant/\
-d variant_key="string"

Example response

Status 200
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"feature_flag_key": "string",
"feature_flag": {},
"holdout": {
"id": 0,
"name": "string",
"description": "string",
"filters": null,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
},
"holdout_id": 0,
"exposure_cohort": 0,
"parameters": {
"excluded_variants": null,
"feature_flag_variants": null,
"minimum_detectable_effect": null,
"rollout_percentage": null
},
"secondary_metrics": null,
"saved_metrics": [
{
"id": 0,
"experiment": 0,
"saved_metric": 0,
"metadata": null,
"created_at": "2019-08-24T14:15:22Z",
"query": null,
"name": "string"
}
],
"saved_metrics_ids": [
null
],
"filters": null,
"archived": false,
"deleted": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"type": "web",
"exposure_criteria": {
"exposure_config": null,
"filterTestAccounts": null
},
"metrics": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"metrics_secondary": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"stats_config": null,
"scheduling_config": null,
"allow_unknown_events": false,
"_create_in_folder": "string",
"conclusion": "won",
"conclusion_comment": "string",
"primary_metrics_ordered_uuids": null,
"secondary_metrics_ordered_uuids": null,
"only_count_matured_users": true,
"update_feature_flag_params": false,
"status": "draft",
"user_access_level": "string"
}

Retrieve experiments timeseries results

Mixin for ViewSets to handle ApprovalRequired exceptions from decorated serializers.

This mixin intercepts ApprovalRequired exceptions raised by the @approval_gate decorator on serializer methods and converts them into proper HTTP 409 Conflict responses with change request details.

Required API key scopes

experiment:read

Path parameters

  • id
    integer

Query parameters

  • fingerprint
    string
  • metric_uuid
    string

Example request

GET /api/projects/:project_id/experiments/:id/timeseries_results
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/timeseries_results/

Example response

Status 200 No response body

Create experiments unarchive

Unarchive an archived experiment.

Restores the experiment to the default list view. Returns 400 if the experiment is not currently archived.

Required API key scopes

experiment:write

Path parameters

  • id
    integer

Response


Example request

POST /api/projects/:project_id/experiments/:id/unarchive
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/:id/unarchive/

Example response

Status 200
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"feature_flag_key": "string",
"feature_flag": {},
"holdout": {
"id": 0,
"name": "string",
"description": "string",
"filters": null,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
},
"holdout_id": 0,
"exposure_cohort": 0,
"parameters": {
"excluded_variants": null,
"feature_flag_variants": null,
"minimum_detectable_effect": null,
"rollout_percentage": null
},
"secondary_metrics": null,
"saved_metrics": [
{
"id": 0,
"experiment": 0,
"saved_metric": 0,
"metadata": null,
"created_at": "2019-08-24T14:15:22Z",
"query": null,
"name": "string"
}
],
"saved_metrics_ids": [
null
],
"filters": null,
"archived": false,
"deleted": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"type": "web",
"exposure_criteria": {
"exposure_config": null,
"filterTestAccounts": null
},
"metrics": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"metrics_secondary": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"stats_config": null,
"scheduling_config": null,
"allow_unknown_events": false,
"_create_in_folder": "string",
"conclusion": "won",
"conclusion_comment": "string",
"primary_metrics_ordered_uuids": null,
"secondary_metrics_ordered_uuids": null,
"only_count_matured_users": true,
"update_feature_flag_params": false,
"status": "draft",
"user_access_level": "string"
}

Create experiments create from prompt

Create an experiment that compares N versions of an LLM prompt using a metric template.

The user picks 2+ versions of an existing LLMPrompt and 1+ metric templates (cost / latency / eval_pass_rate). The endpoint builds the matching variants (control + test-N, each named after its prompt version) and attaches one metric per selected template, each scoped to the prompt's $ai_prompt_name. Resulting experiment is in draft state.

Required API key scopes

experiment:writellm_prompt:read

Request parameters

  • prompt_name
    string
  • versions
    array
  • templates
    Click to open
    array
  • name
    string
  • feature_flag_key
    string
  • description
    string

Response


Example request

POST /api/projects/:project_id/experiments/create_from_prompt
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/experiments/create_from_prompt/\
-d prompt_name="string",\
-d versions="array",\
-d templates="array"

Example response

Status 200
RESPONSE
{
"id": 0,
"name": "string",
"description": "string",
"start_date": "2019-08-24T14:15:22Z",
"end_date": "2019-08-24T14:15:22Z",
"feature_flag_key": "string",
"feature_flag": {},
"holdout": {
"id": 0,
"name": "string",
"description": "string",
"filters": null,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
},
"holdout_id": 0,
"exposure_cohort": 0,
"parameters": {
"excluded_variants": null,
"feature_flag_variants": null,
"minimum_detectable_effect": null,
"rollout_percentage": null
},
"secondary_metrics": null,
"saved_metrics": [
{
"id": 0,
"experiment": 0,
"saved_metric": 0,
"metadata": null,
"created_at": "2019-08-24T14:15:22Z",
"query": null,
"name": "string"
}
],
"saved_metrics_ids": [
null
],
"filters": null,
"archived": false,
"deleted": true,
"created_by": {
"id": 0,
"uuid": "095be615-a8ad-4c33-8e9c-c7612fbf6c9f",
"distinct_id": "string",
"first_name": "string",
"last_name": "string",
"email": "user@example.com",
"is_email_verified": true,
"hedgehog_config": {},
"role_at_organization": "engineering"
},
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z",
"type": "web",
"exposure_criteria": {
"exposure_config": null,
"filterTestAccounts": null
},
"metrics": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"metrics_secondary": [
{
"completion_event": null,
"conversion_window": null,
"denominator": null,
"denominator_outlier_handling": null,
"goal": null,
"ignore_zeros": null,
"kind": "ExperimentMetric",
"lower_bound_percentile": null,
"metric_type": "funnel",
"name": null,
"numerator": null,
"numerator_outlier_handling": null,
"retention_window_end": null,
"retention_window_start": null,
"retention_window_unit": null,
"series": null,
"source": null,
"start_event": null,
"start_handling": null,
"upper_bound_percentile": null,
"uuid": null
}
],
"stats_config": null,
"scheduling_config": null,
"allow_unknown_events": false,
"_create_in_folder": "string",
"conclusion": "won",
"conclusion_comment": "string",
"primary_metrics_ordered_uuids": null,
"secondary_metrics_ordered_uuids": null,
"only_count_matured_users": true,
"update_feature_flag_params": false,
"status": "draft",
"user_access_level": "string"
}

Community questions

Questions about this page? or post a community question.