---
title: Create Environment Variables
description: Creates new environment variables for a given project. This endpoint will fail if any of the specified environment variable keys already exist, unless upsert is set to true.
docs_index: /docs/llms.txt
lastUpdated: 2026-10-23
product: v0 API
type: reference
prerequisites:
  - /docs/api/v1/quickstart
related:
  - /docs/api/v2/guides/environment-variables
---

> For an index of all documentation, see [/docs/llms.txt](/docs/llms.txt).

Creates new environment variables for a given project. This endpoint will fail if any of the specified environment variable keys already exist, unless upsert is set to true.

#### `POST /v1/projects/{projectId}/env-vars`

> **Deprecated**: v1 environment variables were connected to v0 Projects, which are deprecated. To add environment variables for a chat, see the [Environment Variables guide](/docs/api/v2/guides/environment-variables).

## Usage

```typescript
import { v0 } from 'v0-sdk'

// Create new environment variables (will fail if keys already exist)
const result = await v0.projects.createEnvVars({
  projectId: 'project_abc123',
  environmentVariables: [
    {
      key: 'DATABASE_URL',
      value: 'postgresql://user:pass@host:5432/db',
    },
    {
      key: 'API_SECRET_KEY',
      value: 'sk_1234567890abcdef',
    },
  ],
})

console.log(result)

// Upsert environment variables (will overwrite existing values)
const upsertResult = await v0.projects.createEnvVars({
  projectId: 'project_abc123',
  upsert: true,
  environmentVariables: [
    {
      key: 'DATABASE_URL',
      value: 'postgresql://newuser:newpass@newhost:5432/newdb',
    },
  ],
})

console.log(upsertResult)
```

```bash
curl -X POST https://api.v0.dev/v1/projects/project_abc123/env-vars   -H "Authorization: Bearer $V0_API_KEY"   -H "Content-Type: application/json"   -d '{
    "environmentVariables": [
      {
        "key": "DATABASE_URL",
        "value": "postgresql://user:pass@host:5432/db"
      },
      {
        "key": "API_SECRET_KEY",
        "value": "sk_1234567890abcdef"
      }
    ]
  }'
```

## API Signature

### Request

#### Path Parameters

- `projectId: string` The unique identifier of the project where environment variables should be created.

#### Query Parameters

- `decrypted?: 'true' | 'false'` Whether to return decrypted values. Defaults to false (encrypted).

#### Body

- `environmentVariables: object[]` An array of environment variables to create with key and value fields.
  - `item: object`
    - `key: string` The name of the environment variable.
    - `value: string` The value of the environment variable.
- `upsert?: boolean` Whether to overwrite existing environment variables with the same keys. Defaults to false.

### Response

- `object: 'list'`
- `data: object[]`
  - `item: object`
    - `id?: string` A unique identifier for the environment variable.
    - `object?: 'environment_variable'` The object type.
    - `key?: string` The name of the environment variable.
    - `value?: string` The value of the environment variable.
    - `decrypted?: boolean` Whether the value is decrypted or encrypted.
    - `createdAt?: number` The timestamp when the environment variable was created.
    - `updatedAt?: number` The timestamp when the environment variable was last updated.

---

For a semantic overview of all documentation, see [/docs/sitemap.md](/docs/sitemap.md)

For an index of all available documentation, see [/docs/llms.txt](/docs/llms.txt)

For agent-facing discovery, including API and MCP surfaces, see [/docs/agents.md](/docs/agents.md)