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

# Save Agent Environment Values

> Every voice agent has three environments: `dev`, `staging` and `prod`. Each one runs a version of the agent and has its own values for environment variables, which the agent reads as `{{key}}` (for example an API host that differs between testing and production). `prod` is live: calls and phone numbers not routed elsewhere run there. Saves the values of all three environments at once. Send every environment from the list, with its `id` and unchanged `name`: values are the only thing you can change. Changing an environment's values needs the permission for that environment: `agents:publish` for `dev`, `agents:promote` for `staging`, and `agents:update_live_values` for `prod` (prod values reach the next call without a deploy). Send `baseRevisions` to avoid overwriting someone else's save: if an environment changed since you read it, nothing is saved and you get 409 with the current values.



## OpenAPI

````yaml /api-reference/openapi.json put /v2/voice-agents/{voiceAgentId}/environments
openapi: 3.0.1
info:
  title: Hamsa API
  description: >-
    The Hamsa API: voice agents and their calls, phone numbers, batch calls and
    knowledge bases; speech to text, text to speech, voices and AI content.
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.tryhamsa.com
security: []
paths:
  /v2/voice-agents/{voiceAgentId}/environments:
    put:
      summary: Save environment values
      description: >-
        Every voice agent has three environments: `dev`, `staging` and `prod`.
        Each one runs a version of the agent and has its own values for
        environment variables, which the agent reads as `{{key}}` (for example
        an API host that differs between testing and production). `prod` is
        live: calls and phone numbers not routed elsewhere run there. Saves the
        values of all three environments at once. Send every environment from
        the list, with its `id` and unchanged `name`: values are the only thing
        you can change. Changing an environment's values needs the permission
        for that environment: `agents:publish` for `dev`, `agents:promote` for
        `staging`, and `agents:update_live_values` for `prod` (prod values reach
        the next call without a deploy). Send `baseRevisions` to avoid
        overwriting someone else's save: if an environment changed since you
        read it, nothing is saved and you get 409 with the current values.
      parameters:
        - in: path
          name: voiceAgentId
          required: true
          description: ID of the voice agent.
          schema:
            type: string
            format: uuid
            example: d949f13f-40d2-4e48-ac86-b66633070603
        - in: header
          name: Idempotency-Key
          required: false
          description: >-
            Optional. Send a unique value to retry safely: a retry with the same
            key within 10 minutes returns the first response instead of applying
            the change again. Reusing a key with a different body is refused
            (422 `IdempotencyKeyReused`); a retry while the first request is
            still running gets 409 `IdempotencyKeyInProgress`.
          schema:
            type: string
            maxLength: 255
            example: b3f1c2d4-save-1
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - environments
              properties:
                environments:
                  type: array
                  minItems: 1
                  description: All three environments, as returned by the list.
                  items:
                    type: object
                    required:
                      - name
                      - variables
                    properties:
                      id:
                        type: string
                        minLength: 1
                        description: >-
                          Environment ID from the list. An entry without one is
                          refused (422): environments can't be created.
                        example: 3f2a8c4e-1b7d-4e9a-9c25-6d8e0f1a2b3c
                      name:
                        type: string
                        minLength: 1
                        maxLength: 20
                        enum:
                          - dev
                          - staging
                          - prod
                        description: The environment's current name. Renaming is refused.
                        example: dev
                      isDefault:
                        type: boolean
                        description: >-
                          Ignored: `prod` is always the default. Accepted so you
                          can send back what you read.
                        example: false
                      isLocked:
                        type: boolean
                        description: >-
                          Accepted so you can send back what you read. `false`
                          is refused.
                        example: true
                      variables:
                        type: array
                        nullable: true
                        items:
                          $ref: '#/components/schemas/AgentEnvironmentVariable'
                        description: >-
                          All of the environment's values: this replaces them.
                          `null` or `[]` clears them. A key can be missing from
                          some environments; a call there reads it as empty.
                baseRevisions:
                  type: object
                  additionalProperties:
                    type: string
                    minLength: 1
                  description: >-
                    Optional. The `revision` of each environment when you read
                    it, by environment ID. Without it, the last save wins.
                  example:
                    3f2a8c4e-1b7d-4e9a-9c25-6d8e0f1a2b3c: e1f2a3b4-c5d6-4e7f-8a9b-0c1d2e3f4a5b
                    5b9d1e7f-2c3a-4f8b-8d16-7e9f0a1b2c3d: f2a3b4c5-d6e7-4f8a-9b0c-1d2e3f4a5b6c
                    8c4e2a6b-3d9f-4a1c-9e27-0f1b2c3d4e5f: a3b4c5d6-e7f8-4a9b-8c1d-2e3f4a5b6c7d
            examples:
              safe:
                summary: Save all three, refuse if someone else saved
                value:
                  environments:
                    - id: 3f2a8c4e-1b7d-4e9a-9c25-6d8e0f1a2b3c
                      name: dev
                      variables:
                        - key: api_host
                          value: https://dev.example.com
                    - id: 5b9d1e7f-2c3a-4f8b-8d16-7e9f0a1b2c3d
                      name: staging
                      variables:
                        - key: api_host
                          value: https://staging.example.com
                    - id: 8c4e2a6b-3d9f-4a1c-9e27-0f1b2c3d4e5f
                      name: prod
                      variables:
                        - key: api_host
                          value: https://api.example.com
                  baseRevisions:
                    3f2a8c4e-1b7d-4e9a-9c25-6d8e0f1a2b3c: e1f2a3b4-c5d6-4e7f-8a9b-0c1d2e3f4a5b
                    5b9d1e7f-2c3a-4f8b-8d16-7e9f0a1b2c3d: f2a3b4c5-d6e7-4f8a-9b0c-1d2e3f4a5b6c
                    8c4e2a6b-3d9f-4a1c-9e27-0f1b2c3d4e5f: a3b4c5d6-e7f8-4a9b-8c1d-2e3f4a5b6c7d
              last_write_wins:
                summary: Save without conflict check
                value:
                  environments:
                    - id: 3f2a8c4e-1b7d-4e9a-9c25-6d8e0f1a2b3c
                      name: dev
                      isDefault: false
                      isLocked: true
                      variables:
                        - key: api_host
                          value: https://dev.example.com
                    - id: 5b9d1e7f-2c3a-4f8b-8d16-7e9f0a1b2c3d
                      name: staging
                      isDefault: false
                      isLocked: true
                      variables: null
                    - id: 8c4e2a6b-3d9f-4a1c-9e27-0f1b2c3d4e5f
                      name: prod
                      isDefault: true
                      isLocked: true
                      variables:
                        - key: api_host
                          value: https://api.example.com
      responses:
        '200':
          description: Saved. Returns the environments as they are now.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      status:
                        type: string
                        enum:
                          - SAVED
                        example: SAVED
                      agentId:
                        type: string
                        format: uuid
                        example: d949f13f-40d2-4e48-ac86-b66633070603
                      environments:
                        type: array
                        items:
                          $ref: '#/components/schemas/AgentEnvironment'
                        description: >-
                          The three environments, in the order `dev`, `staging`,
                          `prod`.
                    example:
                      status: SAVED
                      agentId: d949f13f-40d2-4e48-ac86-b66633070603
                      environments:
                        - id: 3f2a8c4e-1b7d-4e9a-9c25-6d8e0f1a2b3c
                          name: dev
                          isDefault: false
                          isLocked: true
                          revision: e1f2a3b4-c5d6-4e7f-8a9b-0c1d2e3f4a5b
                          variables:
                            - key: api_host
                              value: https://dev.example.com
                          savedBy:
                            id: b7d9e979-4a16-437b-8571-4ed92a94faa8
                            name: Lina Haddad
                          updatedAt: '2026-10-28T09:14:02.000Z'
                          publishedVersionId: a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d
                          deployedBy:
                            id: b7d9e979-4a16-437b-8571-4ed92a94faa8
                            name: Lina Haddad
                          deployedAt: '2026-10-30T15:40:11.000Z'
                        - id: 5b9d1e7f-2c3a-4f8b-8d16-7e9f0a1b2c3d
                          name: staging
                          isDefault: false
                          isLocked: true
                          revision: f2a3b4c5-d6e7-4f8a-9b0c-1d2e3f4a5b6c
                          variables:
                            - key: api_host
                              value: https://staging.example.com
                          savedBy:
                            id: b7d9e979-4a16-437b-8571-4ed92a94faa8
                            name: Lina Haddad
                          updatedAt: '2026-10-28T09:14:02.000Z'
                          publishedVersionId: null
                        - id: 8c4e2a6b-3d9f-4a1c-9e27-0f1b2c3d4e5f
                          name: prod
                          isDefault: true
                          isLocked: true
                          revision: a3b4c5d6-e7f8-4a9b-8c1d-2e3f4a5b6c7d
                          variables:
                            - key: api_host
                              value: https://api.example.com
                          savedBy:
                            id: b7d9e979-4a16-437b-8571-4ed92a94faa8
                            name: Lina Haddad
                          updatedAt: '2026-10-28T09:14:02.000Z'
                          publishedVersionId: a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d
                          deployedBy:
                            id: b7d9e979-4a16-437b-8571-4ed92a94faa8
                            name: Lina Haddad
                          deployedAt: '2026-10-30T15:40:11.000Z'
        '400':
          description: >-
            Invalid body: a key is not valid, repeats, is a runtime name or
            matches an agent variable, or a value is empty
            (`EnvironmentValueMissing`, with `params.missing` listing each key
            and environment).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentEnvironmentError'
        '401':
          description: 'Unauthorized: missing or invalid API key.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '403':
          description: >-
            Your API key or role does not have `agents:update`, or the
            permission for an environment whose values you changed
            (`PermissionDenied`, `params.action` names it).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentEnvironmentError'
        '404':
          description: Voice agent not found in this project.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '409':
          description: >-
            Not saved: an environment changed since your `baseRevisions` (the
            body has `success: true` and the current values).
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: success
                  data:
                    type: object
                    properties:
                      status:
                        type: string
                        enum:
                          - CONFLICT
                        example: CONFLICT
                      reason:
                        type: string
                        enum:
                          - STALE
                        example: STALE
                      staleEnvironmentIds:
                        type: array
                        items:
                          type: string
                          format: uuid
                        description: Environments that changed since your `baseRevisions`.
                        example:
                          - 5b9d1e7f-2c3a-4f8b-8d16-7e9f0a1b2c3d
                      environments:
                        type: array
                        items:
                          $ref: '#/components/schemas/AgentEnvironment'
                        description: The environments as they are now.
        '422':
          description: >-
            An environment was added, renamed, left out or repeated, or
            `isLocked` is `false` (`FixedEnvironments`, `params.reason` is
            `FIXED_ENVIRONMENTS`). Also `IdempotencyKeyReused`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentEnvironmentError'
        '500':
          description: Server Side Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
      security:
        - ApiKeyAuth: []
components:
  schemas:
    AgentEnvironmentVariable:
      type: object
      required:
        - key
        - value
      properties:
        key:
          type: string
          minLength: 1
          maxLength: 64
          pattern: ^[A-Za-z][A-Za-z0-9_]*$
          description: >-
            Variable name, used as `{{key}}` in the agent. Starts with a letter;
            letters, digits and `_` only. Keys are case-insensitive, can't
            repeat a name the runtime fills in (such as `current_time`,
            `call_id`, `agent_name`, or anything starting with `current_time_`
            or `current_calendar_`), and can't match one of the agent's own
            variables.
          example: api_host
        value:
          type: string
          minLength: 1
          maxLength: 4096
          description: The value in this environment. It can't be empty.
          example: https://staging.example.com
    AgentEnvironment:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Environment ID.
          example: 5b9d1e7f-2c3a-4f8b-8d16-7e9f0a1b2c3d
        name:
          type: string
          enum:
            - dev
            - staging
            - prod
          description: Every agent has exactly these three environments.
          example: staging
        isDefault:
          type: boolean
          description: >-
            `true` for `prod` only: anything not routed to another environment
            runs there.
          example: false
        isLocked:
          type: boolean
          description: 'Always `true`: environments can''t be added, renamed or removed.'
          example: true
        revision:
          type: string
          format: uuid
          description: >-
            ID of the current values. Send it back in `baseRevisions` when you
            save, to detect edits made by someone else.
          example: f2a3b4c5-d6e7-4f8a-9b0c-1d2e3f4a5b6c
        variables:
          type: array
          items:
            $ref: '#/components/schemas/AgentEnvironmentVariable'
          description: The environment's values.
        savedBy:
          $ref: '#/components/schemas/AgentEnvironmentActor'
          description: Who last saved the values.
        updatedAt:
          type: string
          format: date-time
          description: When the values were last saved.
          example: '2026-10-28T09:14:02.000Z'
        publishedVersionId:
          type: string
          format: uuid
          nullable: true
          description: >-
            The version this environment runs. `null` until a version is
            deployed to it.
          example: a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d
        deployedBy:
          $ref: '#/components/schemas/AgentEnvironmentActor'
          description: Who deployed `publishedVersionId`. Absent until then.
        deployedAt:
          type: string
          format: date-time
          description: When `publishedVersionId` was deployed. Absent until then.
          example: '2026-10-30T15:40:11.000Z'
    AgentEnvironmentError:
      type: object
      properties:
        code:
          type: integer
          example: 8409
        message:
          type: string
          example: >-
            This environment or the A/B split changed since you last looked.
            Review the current state and try again.
        messageKey:
          type: string
          example: ReleaseStale
        params:
          type: object
          additionalProperties: true
          description: Details for the error, such as `reason`.
          example:
            reason: STALE
    ErrorSchema:
      type: object
      properties:
        code:
          type: integer
          description: >-
            Service error code: the HTTP status with a service prefix (for
            example `8404`). Missing when the service has no code for that
            status.
          example: 8404
        message:
          type: string
          description: >-
            What went wrong. Some services (calls and recordings) put the error
            key here, for example `CallNotFoundOrUnavailable`, and send no
            `messageKey`.
          example: Policy not found!
        messageKey:
          type: string
          description: >-
            Stable key for the error, safe to match on in code. Not returned by
            every service.
          example: PolicyNotFound
        params:
          type: object
          additionalProperties: true
          description: >-
            Details for some errors (for example `reason`). Not returned by
            every service.
          example:
            reason: NO_DRAFT
    AgentEnvironmentActor:
      type: object
      description: A project member.
      properties:
        id:
          type: string
          format: uuid
          example: b7d9e979-4a16-437b-8571-4ed92a94faa8
        name:
          type: string
          example: Lina Haddad
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        Pass the API key in the Authorization header, You need to put Token
        keyword before the API key. e.g. 'Authorization: Token <api-key>'

````

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