POST
/
v10
/
projects
/
{idOrName}
/
env
import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.projects.createProjectEnv({
    idOrName: "prj_XLKmu1DyR1eY7zq8UgeRKbA7yVLA",
    upsert: "true",
    teamId: "team_1a2b3c4d5e6f7g8h9i0j1k2l",
    slug: "my-team-url-slug",
    requestBody: {
      key: "API_URL",
      value: "https://api.vercel.com",
      type: "plain",
      target: [
        "preview",
      ],
      gitBranch: "feature-1",
      comment: "database connection string for production",
      customEnvironmentIds: [
        "env_1234567890",
      ],
    },
  });

  // Handle the result
  console.log(result);
}

run();
{
  "created": {
    "target": [
      "production"
    ],
    "type": "system",
    "sunsetSecretId": "<string>",
    "id": "<string>",
    "key": "<string>",
    "value": "<string>",
    "configurationId": "<string>",
    "createdAt": 123,
    "updatedAt": 123,
    "createdBy": "<string>",
    "updatedBy": "<string>",
    "gitBranch": "<string>",
    "edgeConfigId": "<string>",
    "edgeConfigTokenId": "<string>",
    "contentHint": {
      "type": "redis-url",
      "storeId": "<string>"
    },
    "internalContentHint": {
      "type": "flags-secret",
      "encryptedValue": "<string>"
    },
    "decrypted": true,
    "comment": "<string>",
    "customEnvironmentIds": [
      "<string>"
    ],
    "vsmValue": "<string>",
    "system": true
  },
  "failed": [
    {
      "error": {
        "code": "<string>",
        "message": "<string>",
        "key": "<string>",
        "envVarId": "<string>",
        "envVarKey": "<string>",
        "action": "<string>",
        "link": "<string>",
        "value": "<string>",
        "gitBranch": "<string>",
        "target": [
          "production"
        ],
        "project": "<string>"
      }
    }
  ]
}

Authorizations

Authorization
string
header
required

Default authentication mechanism

Path Parameters

idOrName
string
required

The unique project identifier or the project name

Example:

"prj_XLKmu1DyR1eY7zq8UgeRKbA7yVLA"

Query Parameters

upsert
string

Allow override of environment variable if it already exists

Example:

"true"

teamId
string

The Team identifier to perform the request on behalf of.

Example:

"team_1a2b3c4d5e6f7g8h9i0j1k2l"

slug
string

The Team slug to perform the request on behalf of.

Example:

"my-team-url-slug"

Body

application/json
key
string
required

The name of the environment variable

Example:

"API_URL"

value
string
required

The value of the environment variable

Example:

"https://api.vercel.com"

type
enum<string>
required

The type of environment variable

Available options:
system,
secret,
encrypted,
plain,
sensitive
Example:

"plain"

target
enum<string>[]
required

The target environment of the environment variable

Available options:
production,
preview,
development
Example:
["preview"]
gitBranch
string | null

If defined, the git branch of the environment variable (must have target=preview)

Maximum length: 250
Example:

"feature-1"

comment
string

A comment to add context on what this environment variable is for

Maximum length: 500
Example:

"database connection string for production"

customEnvironmentIds
string[]

The custom environment IDs associated with the environment variable

Response

201
application/json
The environment variable was created successfully
created
required
failed
object[]
required