# Set variables

Give each [environment](/docs/concepts/project-lifecycle.md#environments) its own variables, the settings it hands to your app such as `LOG_LEVEL`, so Production can differ from Preview.

## Before you start

You need a project. See [Create a project](/docs/projects/create-project.md).

## Add a variable

**Studio**

1. In your project, open **Runtime** > **Environments**.
2. Click **Production**.
3. Under **Environment variables**, click **Add variable**.
4. Enter a **Key**, such as `LOG_LEVEL`.
5. Enter a **Value**, such as `debug`.
6. Click **Add variables**. You should now see "Variable added" and `LOG_LEVEL` under **Environment variables**, with its value hidden as `••••••••`.

To add several at once, open **Paste** in the dialog and paste `KEY=value` lines instead.

To change a value, add the same **Key** again with the new **Value**. Studio says "Variable saved".

**API**

1. Set `PROJECT` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT=<id>`.
2. Get the project with your [API key](/docs/authentication/api-keys.md):

```bash
curl https://api.veryfront.com/projects/$PROJECT \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

3. Set `ENVIRONMENT_ID` to the `id` of the entry named `production` in its `environments`: `export ENVIRONMENT_ID=<id>`.
4. Add the variable. Send it again with a new value to change it:

```bash
curl -X PUT https://api.veryfront.com/projects/$PROJECT/environments/$ENVIRONMENT_ID/variables/LOG_LEVEL \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"value": "debug"}'
```

5. List the variables. You should now see `LOG_LEVEL` with its `value` hidden as `"********"`:

```bash
curl https://api.veryfront.com/projects/$PROJECT/environments/$ENVIRONMENT_ID/variables \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

## Delete a variable

**Studio**

1. Open the **⋯** menu on the variable's row.
2. Click **Delete**. Anything that reads it fails until you add it again.
3. Click **Delete variable**. You should now see "No variables yet." under **Environment variables**.

**API**

1. Delete the variable:

```bash
curl -X DELETE https://api.veryfront.com/projects/$PROJECT/environments/$ENVIRONMENT_ID/variables/LOG_LEVEL \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

2. List the variables again. You should now see `"data": []`:

```bash
curl https://api.veryfront.com/projects/$PROJECT/environments/$ENVIRONMENT_ID/variables \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

### Try it in a sandbox

```playground
step: Set PROJECT | export PROJECT=$VERYFRONT_PROJECT_ID
step: Get the project | curl https://api.veryfront.com/projects/$PROJECT -H "Authorization: Bearer $VERYFRONT_API_KEY"
step: Set ENVIRONMENT_ID | export ENVIRONMENT_ID=$(curl -s https://api.veryfront.com/projects/$PROJECT -H "Authorization: Bearer $VERYFRONT_API_KEY" | jq -r '.environments[] | select(.name == "production") | .id')
step: Add the variable | curl -X PUT https://api.veryfront.com/projects/$PROJECT/environments/$ENVIRONMENT_ID/variables/LOG_LEVEL -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"value": "debug"}'
step: List the variables | curl https://api.veryfront.com/projects/$PROJECT/environments/$ENVIRONMENT_ID/variables -H "Authorization: Bearer $VERYFRONT_API_KEY" | grep '"key":"LOG_LEVEL"'
step: Delete the variable | curl -X DELETE https://api.veryfront.com/projects/$PROJECT/environments/$ENVIRONMENT_ID/variables/LOG_LEVEL -H "Authorization: Bearer $VERYFRONT_API_KEY"
check: curl https://api.veryfront.com/projects/$PROJECT/environments/$ENVIRONMENT_ID/variables -H "Authorization: Bearer $VERYFRONT_API_KEY"
expect: "data":[]
```

## With MCP

1. Call `veryfront__list_environments` with `{ "project_reference": "my-project" }`, and take the `id` of `production`.
2. Call `veryfront__write_environment_variable` with `{ "project_reference": "my-project", "environment_id": "<the id>", "key": "LOG_LEVEL", "value": "debug" }`.
3. Call `veryfront__list_environment_variables` with `{ "project_reference": "my-project", "environment_id": "<the id>" }`. `LOG_LEVEL` is listed with its value masked.
4. To delete it, call `veryfront__delete_environment_variable` with `{ "project_reference": "my-project", "environment_id": "<the id>", "key": "LOG_LEVEL", "confirm": true }`.
5. Call `veryfront__list_environment_variables` again. It worked when `data` is `[]`.

## Next steps

* [Publish](/docs/deployment/publish.md)
* [Add an environment](/docs/runtime/add-environment.md)
