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

# Upsert environment variables



## OpenAPI

````yaml https://api.specular.dev/openapi.json put /branches/{id}/env-vars
openapi: 3.0.0
info:
  title: Specular API
  description: Backend-as-a-Service API for managing projects and branches
  version: 1.0.0
servers:
  - url: https://api.specular.dev
    description: Production server
  - url: http://localhost:3000
    description: Development server
security:
  - bearerAuth: []
paths:
  /branches/{id}/env-vars:
    put:
      tags:
        - Branches
      summary: Upsert environment variables
      parameters:
        - schema:
            type: string
          in: path
          name: id
          required: true
          description: Branch ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - vars
              properties:
                vars:
                  type: array
                  description: Environment variables to upsert
                  items:
                    type: object
                    required:
                      - name
                      - value
                    properties:
                      name:
                        type: string
                      value:
                        type: string
        required: true
      responses:
        '200':
          description: Environment variables upserted
          content:
            application/json:
              schema:
                description: Environment variables upserted
                type: object
                properties:
                  environmentVariables:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        name:
                          type: string
                        value:
                          type: string
                        createdAt:
                          type: string
                          format: date-time
                        updatedAt:
                          type: string
                          format: date-time
        '400':
          description: Bad request (e.g., reserved environment variable)
          content:
            application/json:
              schema:
                description: Bad request (e.g., reserved environment variable)
                type: object
                properties:
                  error:
                    type: string
                  message:
                    type: string
        '401':
          description: Authentication required
          content:
            application/json:
              schema:
                description: Authentication required
                type: object
                properties:
                  error:
                    type: string
        '404':
          description: Branch not found
          content:
            application/json:
              schema:
                description: Branch not found
                type: object
                properties:
                  error:
                    type: string
                  message:
                    type: string
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: 'Bearer authentication with API key (format: Bearer sk_xxx)'

````