---
title: "updateEnvironmentVariable"
method: PUT
path: "/v1/environments/{key}"
tags: ["environments"]
---

# updateEnvironmentVariable

`PUT /v1/environments/{key}`

Create or update an environment variable. Acts as an upsert — creates the variable if it does not exist. If `group` is provided and the group does not yet exist, it is created automatically.

## Request body

- EnvironmentVariableUpdateRequest
  - `type` 'String' | 'SecretString'
  - `value` string
  - `description` string
  - `group` string
  - `protected` boolean — Whether the variable is protected from editing

## Response `200`

Updated environment variable

- EnvironmentVariable
  - `key` string, required
  - `type` 'String' | 'SecretString', required
  - `description` string
  - `group` string — Optional group name for organising variables in the UI
  - `value` string — Value is returned for String type, omitted for SecretString
  - `protected` boolean — Whether the variable is protected from editing
  - `created_at` string, date-time, required
  - `updated_at` string, date-time, required

## Other responses

- `201` — Created environment variable
- `400` — Invalid request
- `401` — Unauthorized
- `403` — Forbidden
- `500` — Internal server error

---

[API](https://skmtc.dev/epilot/apis/environments-api.md) · [All operations](https://skmtc.dev/epilot/apis/environments-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/epilot/environments-api/revisions/6e9b212bbe77/schema)
