---
title: Create flag variables
slug: feature-experimentation/docs/create-flag-variables
docTags: 
createdAt: 2026-08-05T20:39:57.000Z
---

See [Create flag variables](docId\:dPSPfhC9H-Te6fz55LF0Z) in the user documentation to see the available variable types, detailed examples, and step-by-step instructions for creating variables using the Feature Experimentation UI.

For a specific use-case example using an image carousel iOS, see [Flag variable example with an image carousel](docId:7NDj4WSjTmifRK4jw_-My).

## Create flag variable

### Use the Feature Experimentation REST API

Use the [Create Variable Definition](docId\:TdI7GNQF2rIZlptGjCGuU) endpoint.

**Endpoint** – `POST https://api.optimizely.com/flags/v1/projects/PROJECT_ID/flags/FLAG_KEY/variable_definitions`

**Authentication** – Include your API key in the `Authorization` header as a Bearer token. See [Generate tokens and use the REST APIs](docId\:pQfa5KPTbmy6crey-nsrd).

**Request example**

```curl
curl --request POST \
     --url https://api.optimizely.com/flags/v1/projects/PROJECT_ID/flags/FLAG_KEY/variable_definitions \
     --header 'accept: application/json' \
     --header 'authorization: Bearer TOKEN' \
     --header 'content-type: application/json' \
     --data '
{
  "type": "TYPE",
  "default_value": "DEFAULT_VALUE",
  "description": "VARIABLE_DESCRIPTION",
  "key": "VARIABLE_KEY"
}
'
```

**Response example**

```json
{
  "key": "show_amounts",
  "description": "If inventory is shown, this variable controls what is displayed: available/unavailable vs the actual inventory amount.",
  "type": "boolean",
  "default_value": "false",
  "created_time": "2025-09-12T16:23:14.258485Z",
  "updated_time": "2025-09-12T16:23:14.258487Z",
  "role": "admin"
}
```

See the [Create Variable Definition](docId\:TdI7GNQF2rIZlptGjCGuU) endpoint reference for the full list of parameters. You can also follow the [REST API cookbook](docId\:hxlniGd5F_X7vj_ttanPB) and see step three to create events.

### Use the Feature Experimentation UI

See [Create flag variables](docId\:dPSPfhC9H-Te6fz55LF0Z) in the user documentation.

## Implement variables

After you have created your variables, the next step is to [create flag variations](docId\:AL5ZUtJib5Fw1nN4WDQYL). Variations let you avoid hard-coding variables in your application and let you group and reuse variable values using flag rules.
