Set environment variables
Create or update environment variables for an environment in a single atomic
request.
By default this is an upsert: each variable in the payload is created if new
or fully overwritten if the key already exists, and any variable not in the
payload is left untouched. This lets you change one variable without
re-sending the others, which matters for write-only secrets you can no longer
read back.
Set prune: true to make it a full replace instead: after upserting, every
variable not in the payload is deleted. Sending prune: true with an empty
variables list resets the environment by deleting every variable.
Each variable is written exactly as sent, never merged, so omitted optional
fields fall back to their defaults rather than the previous value. Values are
always encrypted at rest. Set kind: recoverable to allow a value to be read
back; it defaults to writeonly, which can never be read back through the API.
Required Permissions
Your root key must have one of the following permissions:
environment.*.set_environment_variables(for any environment)environment.<environment_id>.set_environment_variables(for a specific environment)
Authorization
Body
application/jsonIdentifies a resource by either its unique ID or its slug.
Accepts a prefixed ID (such as 'proj_' or 'app_') or a slug.
Length: 3–255Pattern: ^[a-zA-Z0-9_-]+$
Identifies a resource by either its unique ID or its slug.
Accepts a prefixed ID (such as 'proj_' or 'app_') or a slug.
Length: 3–255Pattern: ^[a-zA-Z0-9_-]+$
Identifies a resource by either its unique ID or its slug.
Accepts a prefixed ID (such as 'proj_' or 'app_') or a slug.
Length: 3–255Pattern: ^[a-zA-Z0-9_-]+$
The variables to upsert. Each entry is created if its key is new or fully
overwritten if the key already exists. Existing variables whose keys are
not in this list are left untouched, unless prune is true.
Each entry is written exactly as sent, never merged with the current
state. Only value is required; omitted optional fields (kind,
description) fall back to their defaults rather than any previous value,
so overwriting a variable without a description clears it.
Each key may appear at most once; a duplicate key is rejected with a 400.
The whole operation is atomic: if any part fails the environment is left
unchanged. All values are encrypted at rest. Limited to 50 variables per
request.
Items: max 50
Show child attributesHide child attributes
The variable name. Must be a POSIX shell name: letters, digits, and
underscores only, and must not start with a digit. Other names are
unreachable from shells and most runtimes.
Length: 1–256Pattern: ^[A-Za-z_][A-Za-z0-9_]*$
The variable value. Always encrypted at rest. The limit is enforced
server-side in UTF-8 bytes, so a multibyte value may be rejected before
it reaches this code-point maximum.
Length: 1–16384
How the value may be read back. writeonly values can never be read back
through the API; recoverable values can be decrypted. Values are encrypted
at rest either way.
Default: "writeonly"
recoverablewriteonlyOptional. Defaults to false. When false, the variables above are upserted
and any existing variable not in the list is kept. When true, this becomes
a full replace: after upserting, every variable not in the list is deleted.
Combined with an empty variables list, prune: true resets the entire
environment by deleting every variable.
Default: false
Responses
requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
Show child attributesHide child attributes
400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 409 (Conflict), and 500 (Internal Server Error).Show child attributesHide child attributes
JSON path indicating exactly where in the request the error occurred. This helps pinpoint the problematic field or parameter. Examples include:
- 'body.name' (field in request body)
- 'body.items[3].tags' (nested array element)
- 'path.apiId' (path parameter)
- 'query.limit' (query parameter)
Use this location to identify exactly which part of your request needs correction.
requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
Show child attributesHide child attributes
400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 409 (Conflict), and 500 (Internal Server Error).requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
Show child attributesHide child attributes
400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 409 (Conflict), and 500 (Internal Server Error).requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
Show child attributesHide child attributes
400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 409 (Conflict), and 500 (Internal Server Error).requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
Show child attributesHide child attributes
400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 409 (Conflict), and 500 (Internal Server Error).requestId is particularly important when troubleshooting issues with the Unkey support team.Show child attributesHide child attributes
Show child attributesHide child attributes
400 (Bad Request), 401 (Unauthorized), 403 (Forbidden), 404 (Not Found), 409 (Conflict), and 500 (Internal Server Error).