Set environment variables
Changed onCreate 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)
Request
- Base URLhttps://api.unkey.com
- URLhttps://api.unkey.com/v2/environments.setEnvironmentVariables
- AuthHTTP bearer
Request body
Example request
{
"project": "proj_1234abcd",
"app": "proj_1234abcd",
"environment": "proj_1234abcd",
"variables": [
{
"key": "DATABASE_URL",
"value": "postgresql://user:pass@host:5432/db",
"kind": "writeonly",
"description": "Primary database connection string"
}
]
}Response
Successfully set the environment variables.
Example response
{
"meta": {
"requestId": "req_123"
}
}Changes
- info
the
//request property's maxLength was increased from4096to16384
- info
- info
the endpoint scheme security
bearerwas added to the API - info
the endpoint scheme security
rootKeywas removed from the API
- info