> ## 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.

# Deploy Version to Environment

> Points one environment at a version: deploy, promote, switch or roll back. Needs deployments on for the agent. The permission depends on the environment: `agents:publish` for `dev`, `agents:promote` for `staging`, `agents:deploy` for `prod`. On `prod` the version gets 100% of calls, which ends any A/B test. Deploying an older version than the current one is recorded as a rollback. Send `expectedVersionId` (and for `prod`, `expectedDeployment`) to refuse the change if someone else deployed in the meantime.



## OpenAPI

````yaml /api-reference/openapi.json put /v2/voice-agents/{voiceAgentId}/environments/{environmentId}/version
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/{environmentId}/version:
    put:
      summary: Deploy a version to an environment
      description: >-
        Points one environment at a version: deploy, promote, switch or roll
        back. Needs deployments on for the agent. The permission depends on the
        environment: `agents:publish` for `dev`, `agents:promote` for `staging`,
        `agents:deploy` for `prod`. On `prod` the version gets 100% of calls,
        which ends any A/B test. Deploying an older version than the current one
        is recorded as a rollback. Send `expectedVersionId` (and for `prod`,
        `expectedDeployment`) to refuse the change if someone else deployed in
        the meantime.
      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: path
          name: environmentId
          required: true
          description: ID of the environment (from the list of environments).
          schema:
            type: string
            format: uuid
            example: 5b9d1e7f-2c3a-4f8b-8d16-7e9f0a1b2c3d
        - 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:
                - versionId
              properties:
                versionId:
                  type: string
                  format: uuid
                  description: The version to run in this environment.
                  example: a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d
                expectedVersionId:
                  type: string
                  format: uuid
                  nullable: true
                  description: >-
                    Optional. The version you saw the environment running
                    (`publishedVersionId`), `null` if none. If it differs now,
                    nothing changes (409).
                  example: d4c3b2a1-6f5e-4b7a-9d8c-5d4c3b2a1f0e
                expectedDeployment:
                  type: array
                  minItems: 1
                  description: >-
                    Optional, for `prod`. The A/B split you saw. If it differs
                    now, nothing changes (409).
                  items:
                    type: object
                    required:
                      - versionNumber
                      - weight
                    properties:
                      versionNumber:
                        type: integer
                        minimum: 1
                        example: 3
                      weight:
                        type: integer
                        minimum: 0
                        maximum: 100
                        description: Share of calls, in percent.
                        example: 100
            examples:
              staging:
                summary: Promote to staging
                value:
                  versionId: a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d
                  expectedVersionId: null
              prod:
                summary: Deploy to prod, refuse if anything moved
                value:
                  versionId: a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d
                  expectedVersionId: d4c3b2a1-6f5e-4b7a-9d8c-5d4c3b2a1f0e
                  expectedDeployment:
                    - versionNumber: 3
                      weight: 100
              plain:
                summary: Deploy without checks
                value:
                  versionId: a1b2c3d4-5e6f-4a7b-8c9d-0e1f2a3b4c5d
      responses:
        '200':
          description: Deployed. Returns the environment.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: success
                  data:
                    $ref: '#/components/schemas/AgentEnvironment'
        '400':
          description: >-
            Invalid request: `environmentId`, `versionId` or `expectedVersionId`
            not a UUID, a malformed `expectedDeployment`, or an
            `Idempotency-Key` over 255 characters.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '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 this environment (`PermissionDenied`, `params.action`
            names it).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentEnvironmentError'
        '404':
          description: Voice agent, environment or version not found on this agent.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '409':
          description: >-
            Nothing changed: the environment or the A/B split moved since you
            looked (`ReleaseStale`). `params.current` has the environment's
            `publishedVersionId` and prod's `deployment` now. Also
            `IdempotencyKeyInProgress`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentEnvironmentError'
        '422':
          description: >-
            Deployments are off for this agent (`NotAllowedInState`,
            `params.reason` `VERSIONING_OFF`), the version is still pending
            (`VERSION_PENDING`), or `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:
    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'
    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
    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
    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
    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.