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

# Set port mappings

> Bulk-replace all port mappings for this CVM. Writes to DB and applies to VMM.



## OpenAPI

````yaml /openapi.json put /api/v1/cvms/{cvm_id}/ports
openapi: 3.1.0
info:
  title: Phala Cloud API
  version: 0.1.0
servers:
  - url: https://cloud-api.phala.com
security: []
tags:
  - name: CVMs
    description: Confidential Virtual Machine (CVM) lifecycle management on Phala Network
  - name: Apps
    description: App template management and CVM deployment from app blueprints
  - name: Webhooks
    description: Manage webhook endpoints and monitor delivery history
  - name: SSH Keys
    description: SSH public key management for CVM access
  - name: KMS
    description: >-
      Key Management Service — key derivation, on-chain anchoring, and
      inspection
  - name: Instance Types
    description: Available hardware configurations for CVM deployment
  - name: Attestations
    description: Remote attestation and TEE verification endpoints
paths:
  /api/v1/cvms/{cvm_id}/ports:
    put:
      tags:
        - CVMs
        - cvms-network-config
      summary: Set port mappings
      description: >-
        Bulk-replace all port mappings for this CVM. Writes to DB and applies to
        VMM.
      operationId: handle_set_port_mappings_api_v1_cvms__cvm_id__ports_put
      parameters:
        - name: cvm_id
          in: path
          required: true
          schema:
            type: string
            title: Cvm Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdatePortMappingsRequest'
      responses:
        '200':
          description: Updated port mappings
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/PortMappingResponse'
                title: >-
                  Response Handle Set Port Mappings Api V1 Cvms  Cvm Id  Ports
                  Put
        '400':
          description: Invalid request
        '403':
          description: Feature not enabled for this workspace
        '404':
          description: CVM not found
        '409':
          description: Port conflict during concurrent updates
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    UpdatePortMappingsRequest:
      properties:
        ports:
          items:
            $ref: '#/components/schemas/PortMappingEntry'
          type: array
          title: Ports
      type: object
      required:
        - ports
      title: UpdatePortMappingsRequest
      description: Bulk-replace all port mappings for a CVM.
    PortMappingResponse:
      properties:
        id:
          type: string
          pattern: ^pm_.+
          format: hashid
          title: HashedId[cvm_port_mappings]
          description: A hashed identifier that maps to an internal database ID
          examples:
            - pm_0123abcd
        host_port:
          type: integer
          title: Host Port
        vm_port:
          type: integer
          title: Vm Port
        protocol:
          type: string
          title: Protocol
        host_address:
          type: string
          title: Host Address
      type: object
      required:
        - id
        - host_port
        - vm_port
        - protocol
        - host_address
      title: PortMappingResponse
      description: Port mapping with server-assigned ID.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    PortMappingEntry:
      properties:
        vm_port:
          type: integer
          maximum: 65535
          minimum: 1
          title: Vm Port
        protocol:
          type: string
          pattern: ^(tcp|udp)$
          title: Protocol
          default: tcp
      type: object
      required:
        - vm_port
      title: PortMappingEntry
      description: Single requested port mapping rule.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````