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

# RoutingRules SDK Reference

> SDK reference for the RoutingRules API, available in Node.js and Python.

## RoutingRules

### List RoutingRules

Returns a paginated list of routing rules for the current project, ordered by priority ascending.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.routing_rules.list(limit=10)

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.routingRules.list({});

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "limit": Optional[int],
        "starting_after": Optional[str],
        "ending_before": Optional[str],
        "project_id": Optional[str],
        "search": Optional[str],
        "enabled": OptionalNullable[bool],
        "model": List[str],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      limit?: number;
      startingAfter?: string;
      endingBefore?: string;
      projectId?: string;
      search?: string;
      enabled?: boolean;
      model?: string[];
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "data": {
            "id": str,
            "created_at": date,
            "created_by_id": str,
            "description": Optional[str],
            "display_name": str,
            "enabled": bool,
            "expression": {  # optional
                "cel": str,
                "config": Dict[str, Any],
            },
            "models_config": {  # optional
                "mode": Literal["fallback", "weighted", "round_robin"],
                "models": {
                    "display_name": Optional[str],
                    "integration_id": Optional[str],
                    "model": str,
                    "weight": Optional[float],
                },
            },
            "priority": int,
            "project_id": str,
            "updated_at": date,
            "updated_by_id": str,
        },
        "has_more": bool,
        "object": str,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      data: {
        id: string;
        createdAt: Date;
        createdById: string;
        description?: string;
        displayName: string;
        enabled: boolean;
        expression?: {
          cel: string;
          config?: Record<string, any>;
        };
        modelsConfig?: {
          mode: string;
          models: {
            displayName?: string;
            integrationId?: string;
            model: string;
            weight?: number;
          };
        };
        priority: number;
        projectId: string;
        updatedAt: Date;
        updatedById: string;
      };
      hasMore: boolean;
      object: string;
    }
    ```
  </CodeGroup>
</Expandable>

### Create a RoutingRule

Creates a new routing rule with expression, models configuration, and priority settings.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.routing_rules.create(display_name="Freeda_Beahan")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.routingRules.create({
      displayName: "Freeda_Beahan",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "display_name": str,  # required
        "description": Optional[str],
        "enabled": Optional[bool],
        "expression": {  # optional
            "cel": str,  # required
        },
        "models_config": {  # optional
            "mode": Literal["fallback", "weighted", "round_robin"],  # required
            "models": {  # required
                "display_name": Optional[str],
                "integration_id": Optional[str],
                "model": str,  # required
                "weight": Optional[float],
            },
        },
        "priority": Optional[int],
        "project_id": Optional[str],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      description?: string;
      displayName: string;  // required
      enabled?: boolean;
      expression?: {
        cel: string;  // required
      };
      modelsConfig?: {
        mode: string;  // required
        models: {  // required
          displayName?: string;
          integrationId?: string;
          model: string;  // required
          weight?: number;
        };
      };
      priority?: number;
      projectId?: string;
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "id": str,
        "created_at": date,
        "created_by_id": str,
        "description": Optional[str],
        "display_name": str,
        "enabled": bool,
        "expression": {  # optional
            "cel": str,
            "config": Dict[str, Any],
        },
        "models_config": {  # optional
            "mode": Literal["fallback", "weighted", "round_robin"],
            "models": {
                "display_name": Optional[str],
                "integration_id": Optional[str],
                "model": str,
                "weight": Optional[float],
            },
        },
        "priority": int,
        "project_id": str,
        "updated_at": date,
        "updated_by_id": str,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      id: string;
      createdAt: Date;
      createdById: string;
      description?: string;
      displayName: string;
      enabled: boolean;
      expression?: {
        cel: string;
        config?: Record<string, any>;
      };
      modelsConfig?: {
        mode: string;
        models: {
          displayName?: string;
          integrationId?: string;
          model: string;
          weight?: number;
        };
      };
      priority: number;
      projectId: string;
      updatedAt: Date;
      updatedById: string;
    }
    ```
  </CodeGroup>
</Expandable>

### List Used Models

Returns the distinct model refs referenced across all routing rules in scope.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.routing_rules.list_used_models()

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.routingRules.listUsedModels();

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "models": List[str],
        "object": str,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      models: string[];
      object: string;
    }
    ```
  </CodeGroup>
</Expandable>

### Delete a RoutingRule

Deletes an existing routing rule by ID.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      orq.routing_rules.delete(routing_rule_id="<id>")

      # Use the SDK ...

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    await orq.routingRules.delete({
      routingRuleId: "<id>",
    });

  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "routing_rule_id": str,  # required
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      routingRuleId: string;  // required
    }
    ```
  </CodeGroup>
</Expandable>

### Retrieve a RoutingRule

Retrieves the details of an existing routing rule by ID.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.routing_rules.retrieve(routing_rule_id="<id>")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.routingRules.retrieve({
      routingRuleId: "<id>",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "routing_rule_id": str,  # required
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      routingRuleId: string;  // required
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "id": str,
        "created_at": date,
        "created_by_id": str,
        "description": Optional[str],
        "display_name": str,
        "enabled": bool,
        "expression": {  # optional
            "cel": str,
            "config": Dict[str, Any],
        },
        "models_config": {  # optional
            "mode": Literal["fallback", "weighted", "round_robin"],
            "models": {
                "display_name": Optional[str],
                "integration_id": Optional[str],
                "model": str,
                "weight": Optional[float],
            },
        },
        "priority": int,
        "project_id": str,
        "updated_at": date,
        "updated_by_id": str,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      id: string;
      createdAt: Date;
      createdById: string;
      description?: string;
      displayName: string;
      enabled: boolean;
      expression?: {
        cel: string;
        config?: Record<string, any>;
      };
      modelsConfig?: {
        mode: string;
        models: {
          displayName?: string;
          integrationId?: string;
          model: string;
          weight?: number;
        };
      };
      priority: number;
      projectId: string;
      updatedAt: Date;
      updatedById: string;
    }
    ```
  </CodeGroup>
</Expandable>

### Update a RoutingRule

Partially updates an existing routing rule. Only provided fields are updated.

<CodeGroup>
  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
  from orq_ai_sdk import Orq
  import os

  with Orq(
      api_key=os.getenv("ORQ_API_KEY", ""),
  ) as orq:

      res = orq.routing_rules.update(routing_rule_id="<id>")

      # Handle response
      print(res)

  ```

  ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
  import { Orq } from "@orq-ai/node";

  const orq = new Orq({
    apiKey: process.env["ORQ_API_KEY"] ?? "",
  });

  async function run() {
    const result = await orq.routingRules.update({
      routingRuleId: "<id>",
      requestBody: {},
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "routing_rule_id": str,  # required
        "description": Optional[str],
        "display_name": Optional[str],
        "enabled": Optional[bool],
        "expression": {  # optional
            "cel": str,  # required
        },
        "models_config": {  # optional
            "mode": Literal["fallback", "weighted", "round_robin"],  # required
            "models": {  # required
                "display_name": Optional[str],
                "integration_id": Optional[str],
                "model": str,  # required
                "weight": Optional[float],
            },
        },
        "priority": Optional[int],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      routingRuleId: string;  // required
      requestBody: {  // required
        description?: string;
        displayName?: string;
        enabled?: boolean;
        expression?: {
          cel: string;  // required
        };
        modelsConfig?: {
          mode: string;  // required
          models: {  // required
            displayName?: string;
            integrationId?: string;
            model: string;  // required
            weight?: number;
          };
        };
        priority?: number;
      };
    }
    ```
  </CodeGroup>
</Expandable>

<Expandable title="Response">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "id": str,
        "created_at": date,
        "created_by_id": str,
        "description": Optional[str],
        "display_name": str,
        "enabled": bool,
        "expression": {  # optional
            "cel": str,
            "config": Dict[str, Any],
        },
        "models_config": {  # optional
            "mode": Literal["fallback", "weighted", "round_robin"],
            "models": {
                "display_name": Optional[str],
                "integration_id": Optional[str],
                "model": str,
                "weight": Optional[float],
            },
        },
        "priority": int,
        "project_id": str,
        "updated_at": date,
        "updated_by_id": str,
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      id: string;
      createdAt: Date;
      createdById: string;
      description?: string;
      displayName: string;
      enabled: boolean;
      expression?: {
        cel: string;
        config?: Record<string, any>;
      };
      modelsConfig?: {
        mode: string;
        models: {
          displayName?: string;
          integrationId?: string;
          model: string;
          weight?: number;
        };
      };
      priority: number;
      projectId: string;
      updatedAt: Date;
      updatedById: string;
    }
    ```
  </CodeGroup>
</Expandable>
