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

# Create a routing rule



## OpenAPI

````yaml /api-reference/openapi.yaml post /api/llm-gateway/admin/routing-rules
openapi: 3.1.0
info:
  title: Barndoor.ai Public API
  description: Unified public API specification for Barndoor.ai platform
  version: 2.18.0
servers:
  - url: https://{host}
    description: Barndoor public API
    variables:
      host:
        default: platform.barndoor.ai
        description: >-
          The host serving your Barndoor deployment. Defaults to production;
          override it for another environment or a dedicated deployment.
security:
  - ApiKey: []
  - OAuth2:
      - openid
      - profile
      - email
tags:
  - name: dlp
    x-group: Data Control Center
  - name: identity
    x-group: Identity
  - name: llm-gateway
    x-group: LLM Gateway
  - name: notification
    x-group: Notifications
  - name: policy
    x-group: Policies
  - name: registry
    x-group: MCP Gateway
  - name: system-management
    x-group: Log Exports
paths:
  /api/llm-gateway/admin/routing-rules:
    post:
      tags:
        - llm-gateway
      summary: Create a routing rule
      operationId: create_routing_rule
      parameters:
        - name: policy_id
          in: query
          description: >-
            The routing policy these rules belong to. Required — the handler's
            `Query<PolicyScope>` extractor rejects a request without it with a
            400.
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RoutingRuleDraft'
        required: true
      responses:
        '201':
          description: The created rule, with any conflicts it introduces
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RoutingRuleWriteResponse'
        '400':
          description: Missing or unparseable `policy_id` query parameter
        '401':
          description: Missing or invalid credentials
        '403':
          description: Caller is not permitted to act on this resource in this organization
        '404':
          description: No such resource in this organization
        '422':
          description: The rule is well-formed but breaks an authoring rule
components:
  schemas:
    RoutingRuleDraft:
      type: object
      description: What an admin sends to create or replace a rule.
      required:
        - name
        - description
      properties:
        deny_slots:
          type: array
          items:
            type: integer
            format: int32
        description:
          type: string
        enabled:
          type: boolean
        floor_slot:
          type:
            - integer
            - 'null'
          format: int32
        name:
          type: string
    RoutingRuleWriteResponse:
      allOf:
        - $ref: '#/components/schemas/RoutingRule'
        - type: object
          required:
            - conflicts
          properties:
            conflicts:
              type: array
              items:
                $ref: '#/components/schemas/RuleConflict'
              description: >-
                Conflicts this rule now has with the policy's others. Present on
                a

                successful write — the save happened; this is advisory.
    RoutingRule:
      type: object
      description: >-
        A rule as stored. `floor_slot` and `deny_slots` are 0-based indices into
        the

        owning policy's `slots` array.
      required:
        - id
        - org_id
        - policy_id
        - name
        - description
        - deny_slots
        - enabled
      properties:
        deny_slots:
          type: array
          items:
            type: integer
            format: int32
          description: >-
            Slots this rule forbids outright. A ban outranks a floor when the
            two

            cannot both be satisfied (decision 15).
        description:
          type: string
          description: >-
            Plain English, read by the router to decide whether a request
            matches.
        enabled:
          type: boolean
        floor_slot:
          type:
            - integer
            - 'null'
          format: int32
          description: Never serve below this slot. `None` means the rule sets no floor.
        id:
          type: string
          format: uuid
        name:
          type: string
        org_id:
          type: string
          format: uuid
        policy_id:
          type: string
          format: uuid
    RuleConflict:
      type: object
      description: >-
        Two rules that cannot both be honoured, or one that contradicts itself.


        Reported, never blocking (decision 15). The admin may have a reason we
        do

        not know about, and at runtime the ban wins — so a conflict degrades an

        answer rather than breaking a request. Refusing the save would be us

        overruling an admin on a judgement call that is theirs.
      required:
        - rule
        - conflicts_with
        - detail
      properties:
        conflicts_with:
          type: string
        detail:
          type: string
        rule:
          type: string
  securitySchemes:
    ApiKey:
      type: http
      scheme: bearer
      description: >-
        A Barndoor API key, sent as `Authorization: Bearer <key>`. Keys are
        prefixed `bdai_` and are opaque — do not attempt to decode one.
        Interchangeable with an OAuth 2.0 access token.
    OAuth2:
      type: oauth2
      x-issuer: https://auth.barndoor.ai/realms/barndoor
      description: >-
        An OAuth 2.0 access token from Barndoor's identity provider, sent as
        `Authorization: Bearer <token>`. Public clients must use PKCE.
        Interchangeable with an API key.
      flows:
        authorizationCode:
          authorizationUrl: >-
            https://auth.barndoor.ai/realms/barndoor/protocol/openid-connect/auth
          tokenUrl: >-
            https://auth.barndoor.ai/realms/barndoor/protocol/openid-connect/token
          scopes:
            openid: Issue an OIDC ID token identifying the caller.
            profile: Read the caller's basic profile claims.
            email: Read the caller's email address.
            offline_access: Issue a refresh token. Optional — no operation requires it.
        clientCredentials:
          tokenUrl: >-
            https://auth.barndoor.ai/realms/barndoor/protocol/openid-connect/token
          scopes:
            openid: Issue an OIDC ID token identifying the caller.
            profile: Read the caller's basic profile claims.
            email: Read the caller's email address.
            offline_access: Issue a refresh token. Optional — no operation requires it.

````

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