> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vers.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Set (upsert) environment variables for the authenticated user.



## OpenAPI

````yaml /api-reference/openapi.json put /api/v2/env-vars
openapi: 3.1.0
info:
  title: Vers API
  description: >-
    REST API for creating, checkpointing, branching, and managing Vers computers
    and projects.
  version: 2.0.0
servers:
  - url: https://api.vers.sh
    description: Vers API
security:
  - bearerAuth: []
tags:
  - name: Computers
    description: Create, inspect, execute commands in, sleep, wake, and delete computers.
  - name: Branches
    description: Branch one or more computers from a live computer, checkpoint, or tag.
  - name: Checkpoints
    description: Capture, inspect, tag, and delete whole-computer checkpoints.
  - name: Projects
    description: >-
      Organize computers into projects with private service networks and grouped
      restores.
  - name: Operations
    description: Inspect and stream status events for asynchronous durable operations.
  - name: Images
    description: >-
      Import and manage custom OCI images, system images, and registry
      artifacts.
  - name: Repositories
    description: Manage checkpoint repositories, tags, and public catalog entries.
  - name: Domains
    description: Register and manage custom domains.
  - name: Environment Variables
    description: Manage account-level environment variables applied to new computers.
  - name: Account & System
    description: Inspect API key identity, usage, and control-plane health.
paths:
  /api/v2/env-vars:
    put:
      tags:
        - Environment Variables
      summary: Set (upsert) environment variables for the authenticated user.
      operationId: set_env_vars
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SetEnvVarsRequest'
        required: true
      responses:
        '200':
          description: Variables after the update
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvVarsResponse'
        '400':
          description: Validation error
        '401':
          description: Missing or invalid API key
components:
  schemas:
    SetEnvVarsRequest:
      type: object
      description: >-
        Request body for PUT /env_vars — sets (upserts) one or more environment
        variables.


        # Lifecycle model


        Environment variables are written to `/etc/environment` inside a VM
        **once

        at boot time** via a vsock `WriteFile` request. They are **not**
        live-synced

        to running VMs. This is intentional: VMs are ephemeral (create → use →

        destroy/branch), so env var changes naturally take effect on the next
        VM.


        The `replace` flag exists so callers can atomically express "I want
        exactly

        these variables and nothing else" without having to DELETE each stale
        key

        individually. Without it, the only way to remove a variable from future
        VMs

        is a separate `DELETE /env_vars/{key}` call per key.
      required:
        - vars
      properties:
        replace:
          type: boolean
          description: >-
            If true, delete all existing variables before writing the new set.

            This gives "set exactly these vars" semantics. Default: false
            (upsert).
        vars:
          type: object
          description: >-
            Key-value pairs to set. Keys must be valid shell identifiers

            (`^[A-Za-z_][A-Za-z0-9_]*$`, max 256 chars). Values max 8192 chars.


            When `replace` is false (default): existing keys are overwritten,
            keys

            not mentioned are left untouched (upsert semantics).


            When `replace` is true: all existing variables are deleted first,
            then

            only the provided vars are stored (replace-all semantics).
          additionalProperties:
            type: string
          propertyNames:
            type: string
    EnvVarsResponse:
      type: object
      description: Response body for GET /env_vars and PUT /env_vars.
      required:
        - vars
      properties:
        vars:
          type: object
          description: All environment variables currently set for the authenticated user.
          additionalProperties:
            type: string
          propertyNames:
            type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API key
      description: 'Vers API key (`VERS_API_KEY`) sent as `Authorization: Bearer <key>`.'

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.