---
title: "Create a feature flag"
method: POST
path: "/api/v2/flags/{projectKey}"
tags: ["Feature flags"]
---

# Create a feature flag

`POST /api/v2/flags/{projectKey}`

Create a feature flag with the given name, key, and variations.

<details>
<summary>Click to expand instructions for <strong>creating a migration flag</strong></summary>

### Creating a migration flag

When you create a migration flag, the variations are pre-determined based on the number of stages in the migration.

To create a migration flag, omit the `variations` and `defaults` information. Instead, provide a `purpose` of `migration`, and `migrationSettings`. If you create a migration flag with six stages, `contextKind` is required. Otherwise, it should be omitted.

Here's an example:

```json
{
  "key": "flag-key-123",
  "purpose": "migration",
  "migrationSettings": {
    "stageCount": 6,
    "contextKind": "account"
  }
}
```

To learn more, read [Migration Flags](https://launchdarkly.com/docs/home/flags/migration).

</details>

## Path parameters

- `projectKey` string, string, required — The project key

## Query parameters

- `clone` string, string — The key of the feature flag to be cloned. The key identifies the flag in your code. For example, setting `clone=flagKey` copies the full targeting configuration for all environments, including `on/off` state, from the original flag to the new flag.

## Request body

- FeatureFlagBody
  - `name` string, required — A human-friendly name for the feature flag
  - `key` string, required — A unique key used to reference the flag in your code
  - `description` string — Description of the feature flag. Defaults to an empty string.
  - `includeInSnippet` boolean — Deprecated, use <code>clientSideAvailability</code>. Whether this flag should be made available to the client-side JavaScript SDK. Defaults to <code>false</code>.
  - `clientSideAvailability` ClientSideAvailabilityPost
    - `usingEnvironmentId` boolean, required — Whether to enable availability for client-side SDKs. Defaults to <code>false</code>.
    - `usingMobileKey` boolean, required — Whether to enable availability for mobile SDKs. Defaults to <code>true</code>.
  - `variations` Variation[] — An array of possible variations for the flag. The variation values must be unique. If omitted, two boolean variations of <code>true</code> and <code>false</code> will be used.
    - `_id` string — The ID of the variation. Leave empty when you are creating a flag.
    - `value` unknown, required
    - `description` string — Description of the variation. Defaults to an empty string, but is omitted from the response if not set.
    - `name` string — A human-friendly name for the variation. Defaults to an empty string, but is omitted from the response if not set.
  - `temporary` boolean — Whether the flag is a temporary flag. Defaults to <code>true</code>.
  - `tags` string[] — Tags for the feature flag. Defaults to an empty array.
  - `customProperties` CustomProperties
  - `defaults` Defaults
    - `onVariation` integer, required — The index, from the array of variations for this flag, of the variation to serve by default when targeting is on.
    - `offVariation` integer, required — The index, from the array of variations for this flag, of the variation to serve by default when targeting is off.
  - `purpose` 'migration' | 'holdout' — Purpose of the flag
  - `migrationSettings` MigrationSettingsPost
    - `contextKind` string — Context kind for a migration with 6 stages, where data is being moved
    - `stageCount` integer, required
  - `maintainerId` string — The ID of the member who maintains this feature flag
  - `maintainerTeamKey` string — The key of the team that maintains this feature flag
  - `initialPrerequisites` FlagPrerequisitePost[] — Initial set of prerequisite flags for all environments
    - `key` string, required — Flag key of the prerequisite flag
    - `variationId` string, required — ID of a variation of the prerequisite flag
  - `isFlagOn` boolean — Whether to automatically turn the flag on across all environments at creation. Defaults to <code>false</code>.

## Response `201`

Global flag response

- FeatureFlag
  - `name` string, required — A human-friendly name for the feature flag
  - `kind` 'boolean' | 'multivariate', required — Kind of feature flag
  - `description` string — Description of the feature flag
  - `key` string, required — A unique key used to reference the flag in your code
  - `_version` integer, required — Version of the feature flag
  - `creationDate` integer, required
  - `includeInSnippet` boolean — Deprecated, use <code>clientSideAvailability</code>. Whether this flag should be made available to the client-side JavaScript SDK
  - `clientSideAvailability` ClientSideAvailability
    - `usingMobileKey` boolean
    - `usingEnvironmentId` boolean
  - `variations` Variation[], required — An array of possible variations for the flag
    - `_id` string — The ID of the variation. Leave empty when you are creating a flag.
    - `value` unknown, required
    - `description` string — Description of the variation. Defaults to an empty string, but is omitted from the response if not set.
    - `name` string — A human-friendly name for the variation. Defaults to an empty string, but is omitted from the response if not set.
  - `temporary` boolean, required — Whether the flag is a temporary flag
  - `tags` string[], required — Tags for the feature flag
  - `_links` object, required — The location and content type of related resources
  - `maintainerId` string — Associated maintainerId for the feature flag
  - `_maintainer` MemberSummary
    - `_links` object, required — The location and content type of related resources
    - `_id` string, required — The member's ID
    - `firstName` string — The member's first name
    - `lastName` string — The member's last name
    - `role` string, required — The member's base role. If the member has no additional roles, this role will be in effect.
    - `email` string, required — The member's email address
  - `maintainerTeamKey` string — The key of the associated team that maintains this feature flag
  - `_maintainerTeam` MaintainerTeam
    - `key` string, required — The key of the maintainer team
    - `name` string, required — A human-friendly name for the maintainer team
    - `_links` object — The location and content type of related resources
  - `goalIds` string[] — Deprecated, use <code>experiments</code> instead
  - `experiments` ExperimentInfoRep, required
    - `baselineIdx` integer, required
    - `items` LegacyExperimentRep[], required
      - `metricKey` string
      - `_metric` MetricListingRep
        - `experimentCount` integer — The number of experiments using this metric
        - `metricGroupCount` integer — The number of metric groups using this metric
        - `activeExperimentCount` integer — The number of active experiments using this metric
        - `activeGuardedRolloutCount` integer — The number of active guarded rollouts using this metric
        - `_id` string, required — The ID of this metric
        - `_versionId` string, required — The version ID of the metric
        - `_version` integer — Version of the metric
        - `key` string, required — A unique key to reference the metric
        - `name` string, required — A human-friendly name for the metric
        - `kind` 'pageview' | 'click' | 'custom', required — The kind of event the metric tracks
        - `_attachedFlagCount` integer — The number of feature flags currently attached to this metric
        - `_links` object, required — The location and content type of related resources
        - `_site` Link
          - `href` string
          - `type` string
        - `_access` Access
          - `denied` AccessDenied[], required
            - `action` string, required
            - `reason` AccessDeniedReason, required
              - …
          - `allowed` AccessAllowedRep[], required
            - `action` string, required
            - `reason` AccessAllowedReason, required
              - …
        - `tags` string[], required — Tags for the metric
        - `_creationDate` integer, required
        - `lastModified` Modification
          - `date` string, date-time
        - `maintainerId` string — The ID of the member who maintains this metric
        - `_maintainer` MemberSummary
          - `_links` object, required — The location and content type of related resources
          - `_id` string, required — The member's ID
          - `firstName` string — The member's first name
          - `lastName` string — The member's last name
          - `role` string, required — The member's base role. If the member has no additional roles, this role will be in effect.
          - `email` string, required — The member's email address
        - `description` string — Description of the metric
        - `category` string — The category of the metric
        - `isNumeric` boolean — For custom metrics, whether to track numeric changes in value against a baseline (<code>true</code>) or to track a conversion when an end user takes an action (<code>false</code>).
        - `successCriteria` 'HigherThanBaseline' | 'LowerThanBaseline' — For custom metrics, the success criteria
        - `unit` string — For numeric custom metrics, the unit of measure
        - `eventKey` string — For custom metrics, the event key to use in your code
        - `randomizationUnits` string[] — An array of randomization units allowed for this metric
        - `filters` Filter
          - `type` 'group' | 'contextAttribute' | 'eventProperty', required — Filter type. One of [contextAttribute, eventProperty, group]
          - `attribute` string — If not a group node, the context attribute name or event property name to filter on
          - `op` string, required
          - `values` unknown[], required — The context attribute / event property values or group member nodes
            - unknown
          - `contextKind` string — For context attribute filters, the context kind.
          - `negate` boolean, required — If set, then take the inverse of the operator. 'in' becomes 'not in'.
        - `unitAggregationType` 'average' | 'sum' — The method by which multiple unit event values are aggregated
        - `analysisType` 'mean' | 'percentile' — The method for analyzing metric events
        - `percentileValue` integer — The percentile for the analysis method. An integer denoting the target percentile between 0 and 100. Required when <code>analysisType</code> is <code>percentile</code>.
        - `eventDefault` MetricEventDefaultRep
          - `disabled` boolean — Whether to disable defaulting missing unit events when calculating results. Defaults to false
          - `value` number — The default value applied to missing unit events. Set to 0 when <code>disabled</code> is false. No other values are currently supported.
        - `dataSource` MetricDataSourceRefRep, required
          - `key` string, required
          - `environmentKey` string
          - `_name` string
          - `_integrationKey` string
        - `lastSeen` integer
        - `archived` boolean — Whether the metric version is archived
        - `archivedAt` integer
        - `selector` string — For click metrics, the CSS selectors
        - `urls` UrlMatcher[]
      - `environments` string[]
      - `_environmentSettings` object
  - `customProperties` CustomProperties, required
  - `archived` boolean, required — Boolean indicating if the feature flag is archived
  - `archivedDate` integer
  - `deprecated` boolean — Boolean indicating if the feature flag is deprecated
  - `deprecatedDate` integer
  - `defaults` Defaults
    - `onVariation` integer, required — The index, from the array of variations for this flag, of the variation to serve by default when targeting is on.
    - `offVariation` integer, required — The index, from the array of variations for this flag, of the variation to serve by default when targeting is off.
  - `_purpose` string
  - `migrationSettings` FlagMigrationSettingsRep
    - `contextKind` string — The context kind targeted by this migration flag. Only applicable for six-stage migrations.
    - `stageCount` integer — The number of stages for this migration flag
  - `environments` object — Details on the environments for this flag. Only returned if the request is filtered by environment, using the <code>filterEnv</code> query parameter.

## Other responses

- `400` — Invalid request
- `401` — Invalid access token
- `409` — Status conflict
- `429` — Rate limited

## Changes

- **2026-02-28** `69c5c9aafe78` — 10 info
  - added the optional property `environments/additionalProperties/rules/items/disabled` to the response with the `201` status
  - added the optional property `experiments/items/items/_metric/_version` to the response with the `201` status
  - added the optional property `experiments/items/items/_metric/activeExperimentCount` to the response with the `201` status
  - added the optional property `experiments/items/items/_metric/activeGuardedRolloutCount` to the response with the `201` status
  - …6 more

[Change history](https://skmtc.dev/launchdarkly/apis/launchdarkly-rest-api/changes/api/v2/flags/:projectKey/post.md)

---

[API](https://skmtc.dev/launchdarkly/apis/launchdarkly-rest-api.md) · [All operations](https://skmtc.dev/launchdarkly/apis/launchdarkly-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/launchdarkly/launchdarkly-rest-api/revisions/69c5c9aafe78/schema)
