Experiments (beta)

Experimentation is an add-on feature

Experimentation is available as an add-on for customers on an Enterprise plan. To learn more, read about our pricing. To upgrade your plan, contact Sales.

This feature is in beta

To use this feature, pass in a header including the LD-API-Version key with value set to beta. Use this header with each call. To learn more, read Beta resources.

Experimentation lets you validate the impact of features you roll out to your app or infrastructure. You can measure things like page views, clicks, load time, infrastructure costs, and more. By connecting metrics you create to flags in your LaunchDarkly environment, you can measure the changes in your users' behavior based on what flags they evaluate. To learn more, read About Experimentation.

You can manage experiments by using the dedicated experiment endpoints described below.

Customers on older contracts may have experiments created under an older data model. These experiments are listed in the LaunchDarkly user interface as "Legacy experiments." You can manage them by making PATCH requests to the flags API, and you can analyze them by making a GET request to the deprecated Get legacy experiment results endpoint. To learn more about legacy experiments, read Legacy experiments.

Click to expand details on using the PATCH requests to the flags API to manage legacy experiments

Managing legacy experiments

To manage legacy experiments, make the following PATCH requests to the flags API:

Adding an experiment

To add an experiment to a flag, add a new object to the /experiments/items/ property.

The object must contain:

  1. The key of the metric you want to use for the experiment.
  2. (Optional) A list of keys for the environments where the experiment should record data.
PATCH /api/v2/flags/{projKey}/{flagKey}
[
    {
        "op": "add",
        "path": "/experiments/items/0",
        "value": {
            "metricKey": "example-metric",
            "environments": []
        }
    }
]

Removing an experiment

To remove an experiment, remove the corresponding item from the experiments or items property.

PATCH /api/v2/flags/{projKey}/{flagKey}
[
    {
        "op": "remove",
        "path": "/experiments/items/0"
    }
]

Starting or resuming an experiment

To start recording data for an experiment in an environment, add the environment key to the list of environments for that experiment.

PATCH /api/v2/flags/{projKey}/{flagKey}
[
    {
        "op": "add",
        "path": "/experiments/items/0/environments/0",
        "value": "production"
    }
]

Stopping an experiment

To stop collecting data for an experiment in a specific environment, remove the environment from the list that experiment uses.

PATCH /api/v2/flags/{projKey}/{flagKey}
[
  {
    "op": "remove",
    "path": "/experiments/items/0/environments/0"
  }
]

Updating the baseline

To update the baseline for all experiments on a flag across all environments in the project, replace the baselineIdx property with the index of the new baseline variation.

PATCH /api/v2/flags/{projKey}/{flagKey}
[
  {
    "op": "replace",
    "path": "/experiments/baselineIdx",
    "value": 1
  }
]

Get legacy experiment results (deprecated)

Get detailed experiment result data for legacy experiments.

Request
path Parameters
projectKey
required
string <string>

The project key

featureFlagKey
required
string <string>

The feature flag key

environmentKey
required
string <string>

The environment key

metricKey
required
string <string>

The metric key

query Parameters
from
integer <int64>

A timestamp denoting the start of the data collection period, expressed as a Unix epoch time in milliseconds.

to
integer <int64>

A timestamp denoting the end of the data collection period, expressed as a Unix epoch time in milliseconds.

Responses
200

Experiment results response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/flags/{projectKey}/{featureFlagKey}/experiments/{environmentKey}/{metricKey}
Request samples
Response samples
application/json
{
  • "_links": {
    },
  • "metadata": [
    ],
  • "totals": [
    ],
  • "series": [
    ],
  • "stats": {
    },
  • "granularity": "string",
  • "metricSeen": {
    }
}

Reset experiment results

Reset all experiment results by deleting all existing data for an experiment.

Request
path Parameters
projectKey
required
string <string>

The project key

featureFlagKey
required
string <string>

The feature flag key

environmentKey
required
string <string>

The environment key

metricKey
required
string <string>

The metric's key

Responses
204

Experiment results reset successfully

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

delete/api/v2/flags/{projectKey}/{featureFlagKey}/experiments/{environmentKey}/{metricKey}/results
Request samples
Response samples
application/json
{
  • "code": "unauthorized",
  • "message": "Invalid access token"
}

Get experiments

Get details about all experiments in an environment.

Filtering experiments

LaunchDarkly supports the filter query param for filtering, with the following fields:

  • flagKey filters for only experiments that use the flag with the given key.
  • metricKey filters for only experiments that use the metric with the given key.
  • status filters for only experiments with an iteration with the given status. An iteration can have the status not_started, running or stopped.

For example, filter=flagKey:my-flag,status:running,metricKey:page-load-ms filters for experiments for the given flag key and the given metric key which have a currently running iteration.

Request
path Parameters
projectKey
required
string <string>

The project key

environmentKey
required
string <string>

The environment key

query Parameters
limit
integer <int64>

The maximum number of experiments to return. Defaults to 20.

offset
integer <int64>

Where to start in the list. Use this with pagination. For example, an offset of 10 skips the first ten items and then returns the next items in the list, up to the query limit.

filter
string <string>

A comma-separated list of filters. Each filter is of the form field:value. Supported fields are explained above.

expand
string <string>

A comma-separated list of properties that can reveal additional information in the response. Supported fields are explained above.

Responses
200

Experiment collection response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

405

Method not allowed

429

Rate limited

get/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments
Request samples
Response samples
application/json
{
  • "items": [
    ],
  • "total_count": 0,
  • "_links": {
    }
}

Create experiment

Create an experiment. To learn more, read Creating experiments.

Request
path Parameters
projectKey
required
string <string>

The project key

environmentKey
required
string <string>

The environment key

Request Body schema: application/json
name
required
string

The experiment name

description
string

The experiment description

maintainerId
required
string

The ID of the member who maintains this experiment.

key
required
string

The experiment key

required
object (IterationInput)
Responses
201

Experiment response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

post/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments
Request samples
application/json
{
  • "name": "Example experiment",
  • "description": "An example experiment, used in testing",
  • "maintainerId": "12ab3c45de678910fgh12345",
  • "key": "example-experiment",
  • "iteration": {
    }
}
Response samples
application/json
{
  • "_id": "12ab3c45de678910fgh12345",
  • "key": "example-experiment",
  • "name": "Example experiment",
  • "description": "An example experiment, used in testing",
  • "_maintainerId": "12ab3c45de678910fgh12345",
  • "_creationDate": 0,
  • "_links": {
    },
  • "currentIteration": {
    },
  • "draftIteration": {
    },
  • "previousIterations": [
    ]
}

Get experiment

Get details about an experiment.

Expanding the experiment response

LaunchDarkly supports four fields for expanding the "Get experiment" response. By default, these fields are not included in the response.

To expand the response, append the expand query parameter and add a comma-separated list with any of the following fields:

  • previousIterations includes all iterations prior to the current iteration. By default only the current iteration is included in the response.
  • draftIteration includes a draft of an iteration which has not been started yet, if any.
  • secondaryMetrics includes secondary metrics. By default only the primary metric is included in the response.
  • treatments includes all treatment and parameter details. By default treatment data is not included in the response.

For example, expand=draftIteration,treatments includes the draftIteration and treatments fields in the response.

Request
path Parameters
projectKey
required
string <string>

The project key

environmentKey
required
string <string>

The environment key

experimentKey
required
string <string>

The experiment key

Responses
200

Experiment response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

405

Method not allowed

429

Rate limited

get/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments/{experimentKey}
Request samples
Response samples
application/json
{
  • "_id": "12ab3c45de678910fgh12345",
  • "key": "example-experiment",
  • "name": "Example experiment",
  • "description": "An example experiment, used in testing",
  • "_maintainerId": "12ab3c45de678910fgh12345",
  • "_creationDate": 0,
  • "_links": {
    },
  • "currentIteration": {
    },
  • "draftIteration": {
    },
  • "previousIterations": [
    ]
}

Patch experiment

Update an experiment. Updating an experiment uses the semantic patch format.

To make a semantic patch request, you must append domain-model=launchdarkly.semanticpatch to your Content-Type header. To learn more, read Updates using semantic patch.

Instructions

Semantic patch requests support the following kind instructions for updating experiments.

updateName

Updates the experiment name.

Parameters
  • value: The new name.

updateDescription

Updates the experiment description.

Parameters
  • value: The new description.

startIteration

Starts a new iteration for this experiment.

stopIteration

Stops the current iteration for this experiment.

Request
path Parameters
projectKey
required
string <string>

The project key

environmentKey
required
string <string>

The environment key

experimentKey
required
string <string>

The experiment key

Request Body schema: application/json
comment
string

Optional comment describing the update

required
Array of objects (Instructions)
Responses
200

Experiment response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

patch/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments/{experimentKey}
Request samples
application/json
{
  • "comment": "Example comment describing the update",
  • "instructions": [
    ]
}
Response samples
application/json
{
  • "_id": "12ab3c45de678910fgh12345",
  • "key": "example-experiment",
  • "name": "Example experiment",
  • "description": "An example experiment, used in testing",
  • "_maintainerId": "12ab3c45de678910fgh12345",
  • "_creationDate": 0,
  • "_links": {
    },
  • "currentIteration": {
    },
  • "draftIteration": {
    },
  • "previousIterations": [
    ]
}

Create iteration

Create an experiment iteration. Experiment iterations let you record experiments in discrete blocks of time. To learn more, read Starting experiment iterations.

Request
path Parameters
projectKey
required
string <string>

The project key

environmentKey
required
string <string>

The environment key

experimentKey
required
string <string>

The experiment key

Request Body schema: application/json
hypothesis
required
string

The expected outcome of this experiment

canReshuffleTraffic
boolean

Whether to allow the experiment to reassign users to different variations (true) or keep users assigned to their initial variation (false). Defaults to true.

required
Array of objects (MetricsInput)
required
Array of objects (TreatmentsInput)
required
object (FlagsInput)
Responses
200

Iteration response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

post/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments/{experimentKey}/iterations
Request samples
application/json
{
  • "hypothesis": "Example hypothesis, the new button placement will increase conversion",
  • "canReshuffleTraffic": true,
  • "metrics": [
    ],
  • "treatments": [
    ],
  • "flags": {
    }
}
Response samples
application/json
{
  • "_id": "12ab3c45de678910fgh12345",
  • "hypothesis": "Example hypothesis, the new button placement will increase conversion",
  • "status": "running",
  • "createdAt": 0,
  • "startedAt": 0,
  • "endedAt": 0,
  • "winningTreatmentId": "122c9f3e-da26-4321-ba68-e0fc02eced58",
  • "winningReason": "We ran this iteration for two weeks and the winning variation was clear",
  • "canReshuffleTraffic": true,
  • "flags": {
    },
  • "primaryMetric": {
    },
  • "treatments": [
    ],
  • "secondaryMetrics": [
    ]
}

Get experiment results

Get results from an experiment for a particular metric.

Request
path Parameters
projectKey
required
string <string>

The project key

environmentKey
required
string <string>

The environment key

experimentKey
required
string <string>

The experiment key

metricKey
required
string <string>

The metric key

Responses
200

Experiment results response

400

Invalid request

401

Invalid access token

403

Forbidden

404

Invalid resource identifier

429

Rate limited

get/api/v2/projects/{projectKey}/environments/{environmentKey}/experiments/{experimentKey}/metrics/{metricKey}/results
Request samples
Response samples
application/json
{
  • "_links": {
    },
  • "treatmentResults": [
    ],
  • "metricSeen": {
    }
}