---
title: "Create a gateway on a SIP trunk"
method: POST
path: "/v1/voice/trunks/{trunk_id}/gateways"
tags: ["voice-trunks"]
---

# Create a gateway on a SIP trunk

`POST /v1/voice/trunks/{trunk_id}/gateways`

## Request

- Base URL: `https://us1.platform.bird.com`
- URL: `https://us1.platform.bird.com/v1/voice/trunks/{trunk_id}/gateways`
- Auth: one of:
  - HTTP bearer
  - API key in cookie `bird_session`

Adds a gateway address for forwarding inbound calls to this trunk.

Gateways are tried in `priority` order, lowest first, until one answers.
Gateways with equal priority share calls evenly. `sip_uri` identifies the
peer host, while `destination_format` and `origination_format` control the
called and calling number formats. Both number formats default to E.164.

A SIP URI already registered on this trunk returns `409 Conflict`. An
invalid SIP URI, a SIP URI carrying a user part, or a malformed number
format returns `422`. A trunk outside the workspace returns `404 Not Found`.
A trunk without inbound calling enabled returns `412 Precondition Failed`.

A trunk supports at most 20 gateways. Creating another returns 422; delete a gateway before adding its replacement. SIP ports must be between 1 and 65535.

## Headers

- `Idempotency-Key` string
- `X-Workspace-Id` string
- `X-Organization-Id` string

## Request body

- VoiceTrunkGatewayCreate
  - `sip_uri` string, required: SIP URI an inbound call to this trunk should be forwarded to. Give the host only, with an optional port: which number is dialed there comes from `destination_format`, so a URI carrying a user part is rejected.
  - `priority` integer, required: The order gateways are tried in, lowest first. Give two gateways the same priority to share calls between them evenly.
  - `origination_format` string: How this gateway wants the calling number spelled. Write a template whose `{number}` stands for the number without its leading `+`; the result is stated in the `P-Asserted-Identity` header of the delivered call. Omit it for E.164, which is `+{number}`. The template may add digits, letters and the characters `-_.!~*'()&=+$,;?/%#` around `{number}`, which may appear at most once, and anything else in braces is rejected so a misspelled placeholder cannot reach a call. A format with no `{number}` at all states the same identity on every call, which is what a peer that only accepts one authorized number wants. The call then carries nothing about who really called.
  - `destination_format` string: How this gateway formats the dialed number. In the template, `{number}` represents the number without its leading `+`. The result is placed before the `sip_uri` host. For example, `1234#{number}` formats `+31201234567` as `sip:1234#31201234567@pbx.example.com:5060`. Omit it for E.164, which is `+{number}`. A format with no `{number}` at all sends every number this trunk answers to one fixed number, so `777000447973` reaches `sip:777000447973@pbx.example.com:5060` whatever was dialed. The same rules as `origination_format` apply to what the template may contain.

## Response `201`

Gateway created.

- VoiceTrunkGateway: One address an inbound call to this trunk is forwarded to, and how that peer wants the call's two numbers spelled. A trunk can have several, tried in priority order until one answers.
  - `id` string, required
  - `trunk_id` string, required
  - `sip_uri` string, required: SIP URI an inbound call to this trunk is forwarded to. The host only: which number is dialed at that host comes from `destination_format`, because it changes with every call.
  - `priority` integer, required: The order gateways are tried in, lowest first. Gateways sharing a priority take an equal share of calls, and any of them may be tried first on a given call.
  - `origination_format` string, required: How the calling number is spelled to this gateway, as a template whose `{number}` stands for the number without its leading `+`. It is stated in the `P-Asserted-Identity` header of the delivered call. A gateway that has not asked for anything else reports `+{number}`, which is E.164. A format with no `{number}` states that same identity on every call, whoever called.
  - `destination_format` string, required: How this gateway formats the dialed number. In the template, `{number}` represents the number without its leading `+`. The result is placed before the `sip_uri` host. For example, `1234#{number}` formats `+31201234567` as `sip:1234#31201234567@pbx.example.com:5060`. A gateway that has not asked for anything else reports `+{number}`, which is E.164. A format with no `{number}` is dialed as it stands, so every number the trunk answers reaches that one number.
  - `created_at` string, date-time, required
  - `updated_at` string, date-time, required

## Other responses

- `400`: Bad request
- `401`: Authentication required
- `403`: Insufficient permissions
- `404`: Resource not found
- `409`: Resource conflict
- `412`: Precondition failed
- `422`: The request has invalid field values, violates a business rule, or carries a query parameter the endpoint does not declare. Field validation errors use `type: validation_error` and include the affected fields in `details`. Business-rule errors identify the failed rule in `type`.
- `429`: Rate limit exceeded
- `500`: Internal server error
- `503`: The service is temporarily unavailable. If `Retry-After` is present, wait for that delay before retrying; otherwise, retry with exponential backoff. Reuse the same idempotency key and request when retrying a mutation.

---

[API](https://skmtc.dev/messagebird/apis/bird-api.md) · [All operations](https://skmtc.dev/messagebird/apis/bird-api/llms.txt) · [OpenAPI document](https://skmtc.dev/messagebird/apis/bird-api/revisions/6dfce1179799?raw)
