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

# Add gateway to SIP trunk API

> Add a carrier SIP host that outbound calls are sent to via POST /trunk/trunks/{trunk_id}/gateways; gateways are tried in priority order.



## OpenAPI

````yaml POST /trunk/trunks/{trunk_id}/gateways
openapi: 3.1.0
info:
  title: Bolna API
  description: >-
    Use and leverage Bolna Voice AI using APIs through HTTP requests from any
    language in your applications and workflows.
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.bolna.ai
    description: Production server
security:
  - bearerAuth: []
tags:
  - name: SIP trunks
    description: >-
      Bring-your-own-carrier SIP trunks, their gateways, carrier IPs and
      numbers.
paths:
  /trunk/trunks/{trunk_id}/gateways:
    post:
      tags:
        - SIP trunks
      description: >
        Adds a gateway: a carrier SIP host that outbound calls on this trunk are
        sent to. A trunk has at most 8 gateways.


        Outbound calls try gateways in ascending `priority` (ties in the order
        they were added). When the carrier fails a call in a way another gateway
        could fix, the next gateway is tried; a definitive answer such as busy
        or declined ends the call.
      parameters:
        - in: path
          name: trunk_id
          required: true
          schema:
            type: string
            format: uuid
          description: The trunk's `id`
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TrunkGatewayRequest'
            example:
              host: sip.example.com
              port: 5060
              priority: 1
      responses:
        '200':
          description: The added gateway
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrunkGateway'
        '400':
          description: >-
            The trunk already has 8 gateways, or `host` is a private, non-public
            or non-canonical IPv4 address
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrunkMessageError'
              example:
                message: a trunk has at most 8 gateways
        '404':
          description: No live trunk with this ID belongs to your account
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrunkMessageError'
        '409':
          description: >-
            Another trunk on Bolna already dials this host or address, and this
            trunk or that one has no carrier credentials (`gateway_conflict`)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrunkCodedError'
        '422':
          description: >-
            `host` is not an IPv4 address or DNS name, `port` is outside
            1–65535, `priority` is outside 0–100, or the body has an unknown
            field
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrunkValidationError'
components:
  schemas:
    TrunkGatewayRequest:
      type: object
      required:
        - host
      properties:
        host:
          type: string
          description: >-
            The carrier's SIP host, as an IPv4 address or a DNS name. A literal
            address must be public.
          example: sip.example.com
        port:
          type: integer
          minimum: 1
          maximum: 65535
          default: 5060
          description: The carrier's SIP port.
        priority:
          type: integer
          minimum: 0
          maximum: 100
          default: 0
          description: Order in which gateways are tried; lowest first.
    TrunkGateway:
      type: object
      properties:
        id:
          type: string
          format: uuid
        trunk_id:
          type: string
          format: uuid
        host:
          type: string
          example: sip.example.com
        resolved_ips:
          type: array
          nullable: true
          items:
            type: string
          description: The public IPv4 addresses `host` resolved to when it was saved.
          example:
            - 203.0.113.30
        port:
          type: integer
          example: 5060
        priority:
          type: integer
          example: 1
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        is_deleted:
          type: boolean
        deleted_at:
          type: string
          format: date-time
          nullable: true
    TrunkMessageError:
      type: object
      description: >-
        Error body for `400`, `403` and `404` responses from the SIP trunk
        endpoints.
      required:
        - message
      properties:
        message:
          type: string
          description: >-
            Human-readable reason. On a `404` it names the ID that was not
            found.
    TrunkCodedError:
      type: object
      description: >-
        Error body for `409` responses from the SIP trunk endpoints.
        `detail.code` is stable and machine-readable.
      required:
        - detail
      properties:
        detail:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              enum:
                - number_taken
                - gateway_conflict
                - convert_in_progress
                - conflict
              description: >
                - `number_taken`: the number is already live on a trunk.

                - `gateway_conflict`: a gateway is shared with another trunk
                without carrier credentials on both.

                - `convert_in_progress`: the trunk is mid-migration from a
                legacy SIP trunk.

                - `conflict`: the change clashes with an existing record.
            message:
              type: string
              description: Human-readable reason.
    TrunkValidationError:
      type: object
      description: >-
        Error body for `422` responses from the SIP trunk endpoints. The
        rejected input is never echoed back.
      properties:
        detail:
          type: array
          items:
            type: object
            properties:
              loc:
                type: array
                items:
                  oneOf:
                    - type: string
                    - type: integer
                description: Where the error is, such as `["body", "channels"]`.
              msg:
                type: string
                description: What is wrong.
              type:
                type: string
                description: >-
                  Pydantic error type, such as `value_error` or
                  `less_than_equal`.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````

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