---
title: "Create environment variable"
method: POST
path: "/v2/actors/{actorId}/versions/{versionNumber}/env-vars"
tags: ["Actors/Actor versions"]
---

# Create environment variable

`POST /v2/actors/{actorId}/versions/{versionNumber}/env-vars`

Creates an environment variable of an Actor using values specified in a
[EnvVar object](#/reference/actors/environment-variable-object) passed as
JSON in the POST payload.

The request must specify `name` and `value` parameters (as strings) in the
JSON payload and a `Content-Type: application/json` HTTP header.

```
{
    "name": "ENV_VAR_NAME",
    "value": "my-env-var"
}
```

The response is the [EnvVar
object](#/reference/actors/environment-variable-object) as returned by the [Get environment
variable](#/reference/actors/environment-variable-object/get-environment-variable)
endpoint.

## Path parameters

- `actorId` string, required
- `versionNumber` string, required

## Request body

- EnvVarRequest
  - `name` string, required — The name of the environment variable.
  - `value` string, required — The value of the environment variable. If `isSecret` is `true`, this value isn't returned by the API.
  - `isSecret` boolean, nullable — Whether the environment variable is encrypted. Secret values aren't returned by the API.

## Response `201`

- EnvVarResponse
  - `data` EnvVar, required
    - `name` string, required — The name of the environment variable.
    - `value` string — The value of the environment variable. If `isSecret` is `true`, this value isn't returned by the API.
    - `isSecret` boolean, nullable — Whether the environment variable is encrypted. Secret values aren't returned by the API.

## Other responses

- `400` — Bad request - invalid input parameters or request body.
- `401` — Unauthorized - authentication required or invalid token.
- `403` — Forbidden - insufficient permissions to perform this action.
- `404` — Not found - the requested resource does not exist.
- `405` — Method not allowed.
- `413` — Payload too large - the request body exceeds the size limit.
- `415` — Unsupported media type - the Content-Encoding of the request is not supported.
- `429` — Too many requests - rate limit exceeded.

## Changes

- **2026-08-28** `0a98d6a098a4` — 8 warning
  - added the new `cannot-publish-actor-task` enum value to the `error/type` response property for the response status `400`
  - added the new `cannot-publish-actor-task` enum value to the `error/type` response property for the response status `401`
  - added the new `cannot-publish-actor-task` enum value to the `error/type` response property for the response status `403`
  - added the new `cannot-publish-actor-task` enum value to the `error/type` response property for the response status `404`
  - …4 more
- **2026-07-31** `5ceb2cdfe616` — 1 info
  - api operation id `act_version_envVars_post` removed and replaced with `actor_version_envVars_post`
- **2026-07-26** `b94a8abdfff1` — 8 warning
  - added the new `cannot-monetize-without-payout-billing-info` enum value to the `error/type` response property for the response status `400`
  - added the new `cannot-monetize-without-payout-billing-info` enum value to the `error/type` response property for the response status `401`
  - added the new `cannot-monetize-without-payout-billing-info` enum value to the `error/type` response property for the response status `403`
  - added the new `cannot-monetize-without-payout-billing-info` enum value to the `error/type` response property for the response status `404`
  - …4 more

[Change history](https://skmtc.dev/apify/apis/apify-api/changes/v2/actors/:actorId/versions/:versionNumber/env-vars/post.md)

---

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