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

# Create routing rule

> Creates a routing rule and attaches it to the numbers in `phoneNumbers`. Only `name` and `type` are required.



## OpenAPI

````yaml /api-reference/rest/openapi.yaml post /v2/sip/routing-rule
openapi: 3.1.0
info:
  title: Zero Runtime REST API
  version: '1.0'
  description: >-
    Create, configure, version and deploy agents, and wire SIP telephony to
    them.
servers:
  - url: https://api.zeroruntime.ai
security:
  - token: []
tags:
  - name: Agents
  - name: Versions
  - name: Deployment
  - name: Phone numbers
  - name: Routing rules
  - name: Calls
  - name: Batch calls
  - name: Knowledge bases
  - name: Knowledge base folders
paths:
  /v2/sip/routing-rule:
    post:
      tags:
        - Routing rules
      summary: Create routing rule
      description: >-
        Creates a routing rule and attaches it to the numbers in `phoneNumbers`.
        Only `name` and `type` are required.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              allOf:
                - type: object
                  required:
                    - name
                    - type
                  properties:
                    type:
                      type: string
                      enum:
                        - inbound
                        - outbound
                      description: Fixed for the life of the rule.
                - $ref: '#/components/schemas/RoutingRuleInput'
            examples:
              inbound:
                summary: Inbound rule
                value:
                  name: Support inbound
                  type: inbound
                  phoneNumbers:
                    - '+14155550100'
                  agentId: ag_7f2c91
                  agentMetadata:
                    queue: billing
                  room:
                    type: dynamic
                    prefix: sipNumber
                  includeHeaders: SIP_X_HEADERS
                  headersToAttributes:
                    X-Customer-Id: customerId
                  allowedNumbers: []
                  allowedIpAddresses: []
                  tags:
                    - support
                  recording: false
                  dtmf: false
                  noiseCancellation: false
                  hidePhoneNumber: false
              outbound:
                summary: Outbound rule
                value:
                  name: Support outbound
                  type: outbound
                  phoneNumbers:
                    - '+14155550100'
                  agentId: ag_7f2c91
                  room:
                    type: static
                    id: abcd-efgh-ijkl
                    pin: '4821'
                  includeHeaders: ALL
                  headers:
                    X-Campaign: renewals
                  recording: true
      responses:
        '201':
          description: The created rule.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RoutingRule'
        '400':
          description: >-
            The body didn't validate, a number isn't on your account, or a
            number already has an inbound rule. Nothing is written.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Message'
components:
  schemas:
    RoutingRuleInput:
      type: object
      properties:
        name:
          type: string
        phoneNumbers:
          type: array
          items:
            type: string
          description: >-
            E.164 numbers already on your account. Leave it out to attach
            numbers later.
        apiKey:
          type: string
          description: >-
            Optional. On create, leave it out to use the API key of the token
            you call with.
        agentId:
          type: string
          description: Agent to dispatch. Omit to dispatch none.
        agentMetadata:
          type: object
          additionalProperties:
            type: string
          description: Flat string map handed to the agent.
        room:
          $ref: '#/components/schemas/Room'
        includeHeaders:
          type: string
          enum:
            - ALL
            - SIP_X_HEADERS
            - NONE
          default: NONE
        headers:
          type: object
          additionalProperties:
            type: string
          description: Outbound only. Extra SIP headers to send.
        headersToAttributes:
          type: object
          additionalProperties:
            type: string
          description: Inbound only. Maps an incoming header onto a call attribute.
        allowedNumbers:
          type: array
          items:
            type: string
          description: Empty means no restriction.
        allowedIpAddresses:
          type: array
          items:
            type: string
          description: Empty means no restriction.
        tags:
          type: array
          items:
            type: string
        recording:
          type: boolean
          default: false
        dtmf:
          type: boolean
          default: false
        noiseCancellation:
          type: boolean
          default: false
        hidePhoneNumber:
          type: boolean
          default: false
    RoutingRule:
      allOf:
        - type: object
          properties:
            id:
              type: string
              example: rr_8k2m1x
            type:
              type: string
              enum:
                - inbound
                - outbound
            numbers:
              type: array
              items:
                type: string
            createdAt:
              type: string
              format: date-time
            updatedAt:
              type: string
              format: date-time
        - $ref: '#/components/schemas/RoutingRuleInput'
    Message:
      type: object
      properties:
        message:
          type: string
    Room:
      type: object
      default:
        type: dynamic
        prefix: blank
      properties:
        type:
          type: string
          enum:
            - dynamic
            - static
        prefix:
          type: string
          enum:
            - blank
            - participantNumber
            - sipNumber
            - random
        id:
          type: string
          description: Static rooms only.
        pin:
          type: string
          description: Static rooms only.
  securitySchemes:
    token:
      type: apiKey
      in: header
      name: Authorization
      description: Your API token, sent raw (no `Bearer` prefix).
      x-default: <auth-token>

````

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