> ## 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.

# Routing Rules SDK Reference

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

## Routing Rules

### List Routing Rules

Returns routing rules ordered by ascending priority. Supports cursor pagination, search, status, project, and referenced-model filters.

```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({
    limit: 10,
  });

  console.log(result);
}

run();
```

**Parameters**

```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": Optional[bool],
    "model": List[str],  # optional
}
```

```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[];
}
```

**Response**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "object": str,
    "data": [{
        "id": str,
        "created_at": str,
        "updated_at": str,
        "created_by_id": str,
        "updated_by_id": str,
        "project_id": str,
        "display_name": str,
        "description": str,
        "enabled": bool,
        "expression": {  # optional
            "config": Dict[str, Any],  # optional
            "cel": Optional[str],
        },
        "models_config": {  # optional
            "mode": Optional[str],
            "models": [{  # optional
                "model": Optional[str],
                "display_name": Optional[str],
                "weight": Optional[float],
                "integration_id": Optional[str],
            }],
            "fallback_on_codes": List[int],  # optional
        },
        "plugins": [{
            "id": Optional[str],
            "language": Optional[str],
            "entities": List[str],  # optional
            "on_failure": Optional[str],
            "threshold": Optional[float],
            "mask": List[str],  # optional
            "regions": List[str],  # optional
            "entity_thresholds": Dict[str, float],  # optional
            "models_config": {  # optional
                "mode": Optional[str],
                "models": [{  # optional
                    "model": Optional[str],
                    "display_name": Optional[str],
                    "weight": Optional[float],
                    "integration_id": Optional[str],
                }],
                "fallback_on_codes": List[int],  # optional
            },
            "checks": Dict[str, SignalsCheck],  # optional
        }],
        "priority": int,
        "cache_config": {  # optional
            "ttl": int,
        },
    }],
    "has_more": bool,
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  object: string;
  data: {
    id: string;
    createdAt: Date;
    updatedAt: Date;
    createdById: string;
    updatedById: string;
    projectId: string;
    displayName: string;
    description: string;
    enabled: boolean;
    expression?: {
      config?: Record<string, unknown>;
      cel?: string;
    };
    modelsConfig?: {
      mode?: string;
      models?: {
        model?: string;
        displayName?: string;
        weight?: number;
        integrationId?: string;
      }[];
      fallbackOnCodes?: number[];
    };
    plugins: {
      id?: string;
      language?: string;
      entities?: string[];
      onFailure?: string;
      threshold?: number;
      mask?: string[];
      regions?: string[];
      entityThresholds?: Record<string, number>;
      modelsConfig?: {
        mode?: string;
        models?: {
          model?: string;
          displayName?: string;
          weight?: number;
          integrationId?: string;
        }[];
        fallbackOnCodes?: number[];
      };
      checks?: Record<string, SignalsCheck>;
    }[];
    priority: number;
    cacheConfig?: {
      ttl: number;
    };
  }[];
  hasMore: boolean;
}
```

### Create a Routing Rule

Creates a routing rule with metadata and optional model, plugin, priority, and matching configuration. Rules default to disabled when `enabled` is omitted.

```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="Route to Claude")

    # 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: "Route to Claude",
  });

  console.log(result);
}

run();
```

**Parameters**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "display_name": str,  # required
    "description": Optional[str],
    "project_id": Optional[str],
    "enabled": Optional[bool],
    "expression": {  # optional
        "config": Dict[str, Any],  # optional
        "cel": Optional[str],
    },
    "models_config": {  # optional
        "mode": Optional[str],
        "models": [{  # optional
            "model": Optional[str],
            "display_name": Optional[str],
            "weight": Optional[float],
            "integration_id": Optional[str],
        }],
        "fallback_on_codes": List[int],  # optional
    },
    "plugins": [{  # optional
        "id": Optional[str],
        "language": Optional[str],
        "entities": List[str],  # optional
        "on_failure": Optional[str],
        "threshold": Optional[float],
        "mask": List[str],  # optional
        "regions": List[str],  # optional
        "entity_thresholds": Dict[str, float],  # optional
        "models_config": Optional[RoutingRuleModelsConfig],
        "checks": Dict[str, SignalsCheck],  # optional
    }],
    "priority": Optional[int],
    "cache_config": {  # optional
        "ttl": int,  # required
    },
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  displayName: string;  // required
  description?: string;
  projectId?: string;
  enabled?: boolean;
  expression?: {
    config?: Record<string, unknown>;
    cel?: string;
  };
  modelsConfig?: {
    mode?: string;
    models?: {
      model?: string;
      displayName?: string;
      weight?: number;
      integrationId?: string;
    }[];
    fallbackOnCodes?: number[];
  };
  plugins?: {
    id?: string;
    language?: string;
    entities?: string[];
    onFailure?: string;
    threshold?: number;
    mask?: string[];
    regions?: string[];
    entityThresholds?: Record<string, number>;
    modelsConfig?: {
      mode?: string;
      models?: {
        model?: string;
        displayName?: string;
        weight?: number;
        integrationId?: string;
      }[];
      fallbackOnCodes?: number[];
    };
    checks?: Record<string, SignalsCheck>;
  }[];
  priority?: number;
  cacheConfig?: {
    ttl: number;  // required
  };
}
```

**Response**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "id": str,
    "created_at": str,
    "updated_at": str,
    "created_by_id": str,
    "updated_by_id": str,
    "project_id": str,
    "display_name": str,
    "description": str,
    "enabled": bool,
    "expression": {  # optional
        "config": Dict[str, Any],  # optional
        "cel": Optional[str],
    },
    "models_config": {  # optional
        "mode": Optional[str],
        "models": [{  # optional
            "model": Optional[str],
            "display_name": Optional[str],
            "weight": Optional[float],
            "integration_id": Optional[str],
        }],
        "fallback_on_codes": List[int],  # optional
    },
    "plugins": [{
        "id": Optional[str],
        "language": Optional[str],
        "entities": List[str],  # optional
        "on_failure": Optional[str],
        "threshold": Optional[float],
        "mask": List[str],  # optional
        "regions": List[str],  # optional
        "entity_thresholds": Dict[str, float],  # optional
        "models_config": {  # optional
            "mode": Optional[str],
            "models": [{  # optional
                "model": Optional[str],
                "display_name": Optional[str],
                "weight": Optional[float],
                "integration_id": Optional[str],
            }],
            "fallback_on_codes": List[int],  # optional
        },
        "checks": Dict[str, SignalsCheck],  # optional
    }],
    "priority": int,
    "cache_config": {  # optional
        "ttl": int,
    },
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  id: string;
  createdAt: Date;
  updatedAt: Date;
  createdById: string;
  updatedById: string;
  projectId: string;
  displayName: string;
  description: string;
  enabled: boolean;
  expression?: {
    config?: Record<string, unknown>;
    cel?: string;
  };
  modelsConfig?: {
    mode?: string;
    models?: {
      model?: string;
      displayName?: string;
      weight?: number;
      integrationId?: string;
    }[];
    fallbackOnCodes?: number[];
  };
  plugins: {
    id?: string;
    language?: string;
    entities?: string[];
    onFailure?: string;
    threshold?: number;
    mask?: string[];
    regions?: string[];
    entityThresholds?: Record<string, number>;
    modelsConfig?: {
      mode?: string;
      models?: {
        model?: string;
        displayName?: string;
        weight?: number;
        integrationId?: string;
      }[];
      fallbackOnCodes?: number[];
    };
    checks?: Record<string, SignalsCheck>;
  }[];
  priority: number;
  cacheConfig?: {
    ttl: number;
  };
}
```

### List Used Models

Returns the distinct model references used by routing rules in the requested scope.

```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();
```

**Parameters**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "project_id": Optional[str],
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  projectId?: string;
}
```

**Response**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "object": str,
    "models": List[str],
}
```

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

### Retrieve a Routing Rule

Retrieves a routing rule by its unique identifier.

```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();
```

**Parameters**

```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
}
```

**Response**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "id": str,
    "created_at": str,
    "updated_at": str,
    "created_by_id": str,
    "updated_by_id": str,
    "project_id": str,
    "display_name": str,
    "description": str,
    "enabled": bool,
    "expression": {  # optional
        "config": Dict[str, Any],  # optional
        "cel": Optional[str],
    },
    "models_config": {  # optional
        "mode": Optional[str],
        "models": [{  # optional
            "model": Optional[str],
            "display_name": Optional[str],
            "weight": Optional[float],
            "integration_id": Optional[str],
        }],
        "fallback_on_codes": List[int],  # optional
    },
    "plugins": [{
        "id": Optional[str],
        "language": Optional[str],
        "entities": List[str],  # optional
        "on_failure": Optional[str],
        "threshold": Optional[float],
        "mask": List[str],  # optional
        "regions": List[str],  # optional
        "entity_thresholds": Dict[str, float],  # optional
        "models_config": {  # optional
            "mode": Optional[str],
            "models": [{  # optional
                "model": Optional[str],
                "display_name": Optional[str],
                "weight": Optional[float],
                "integration_id": Optional[str],
            }],
            "fallback_on_codes": List[int],  # optional
        },
        "checks": Dict[str, SignalsCheck],  # optional
    }],
    "priority": int,
    "cache_config": {  # optional
        "ttl": int,
    },
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  id: string;
  createdAt: Date;
  updatedAt: Date;
  createdById: string;
  updatedById: string;
  projectId: string;
  displayName: string;
  description: string;
  enabled: boolean;
  expression?: {
    config?: Record<string, unknown>;
    cel?: string;
  };
  modelsConfig?: {
    mode?: string;
    models?: {
      model?: string;
      displayName?: string;
      weight?: number;
      integrationId?: string;
    }[];
    fallbackOnCodes?: number[];
  };
  plugins: {
    id?: string;
    language?: string;
    entities?: string[];
    onFailure?: string;
    threshold?: number;
    mask?: string[];
    regions?: string[];
    entityThresholds?: Record<string, number>;
    modelsConfig?: {
      mode?: string;
      models?: {
        model?: string;
        displayName?: string;
        weight?: number;
        integrationId?: string;
      }[];
      fallbackOnCodes?: number[];
    };
    checks?: Record<string, SignalsCheck>;
  }[];
  priority: number;
  cacheConfig?: {
    ttl: number;
  };
}
```

### Delete a Routing Rule

Permanently deletes a routing rule.

```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>")

```

```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();
```

**Parameters**

```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
}
```

### Update a Routing Rule

Partially updates routing-rule metadata or configuration. Project scope is immutable.

```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>", display_name="<value>")

    # 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>",
    updateRoutingRuleRequest: {
      displayName: "<value>",
    },
  });

  console.log(result);
}

run();
```

**Parameters**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "routing_rule_id": str,  # required
    "display_name": Optional[str],
    "description": Optional[str],
    "enabled": Optional[bool],
    "expression": {  # optional
        "config": Dict[str, Any],  # optional
        "cel": Optional[str],
    },
    "models_config": {  # optional
        "mode": Optional[str],
        "models": [{  # optional
            "model": Optional[str],
            "display_name": Optional[str],
            "weight": Optional[float],
            "integration_id": Optional[str],
        }],
        "fallback_on_codes": List[int],  # optional
    },
    "plugins": [{  # optional
        "id": Optional[str],
        "language": Optional[str],
        "entities": List[str],  # optional
        "on_failure": Optional[str],
        "threshold": Optional[float],
        "mask": List[str],  # optional
        "regions": List[str],  # optional
        "entity_thresholds": Dict[str, float],  # optional
        "models_config": Optional[RoutingRuleModelsConfig],
        "checks": Dict[str, SignalsCheck],  # optional
    }],
    "priority": Optional[int],
    "cache_config": {  # optional
        "ttl": int,  # required
    },
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  routingRuleId: string;  // required
  updateRoutingRuleRequest: {  // required
    displayName?: string;
    description?: string;
    enabled?: boolean;
    expression?: {
      config?: Record<string, unknown>;
      cel?: string;
    };
    modelsConfig?: {
      mode?: string;
      models?: {
        model?: string;
        displayName?: string;
        weight?: number;
        integrationId?: string;
      }[];
      fallbackOnCodes?: number[];
    };
    plugins?: {
      id?: string;
      language?: string;
      entities?: string[];
      onFailure?: string;
      threshold?: number;
      mask?: string[];
      regions?: string[];
      entityThresholds?: Record<string, number>;
      modelsConfig?: {
        mode?: string;
        models?: {
          model?: string;
          displayName?: string;
          weight?: number;
          integrationId?: string;
        }[];
        fallbackOnCodes?: number[];
      };
      checks?: Record<string, SignalsCheck>;
    }[];
    priority?: number;
    cacheConfig?: {
      ttl: number;  // required
    };
  };
}
```

**Response**

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
    "id": str,
    "created_at": str,
    "updated_at": str,
    "created_by_id": str,
    "updated_by_id": str,
    "project_id": str,
    "display_name": str,
    "description": str,
    "enabled": bool,
    "expression": {  # optional
        "config": Dict[str, Any],  # optional
        "cel": Optional[str],
    },
    "models_config": {  # optional
        "mode": Optional[str],
        "models": [{  # optional
            "model": Optional[str],
            "display_name": Optional[str],
            "weight": Optional[float],
            "integration_id": Optional[str],
        }],
        "fallback_on_codes": List[int],  # optional
    },
    "plugins": [{
        "id": Optional[str],
        "language": Optional[str],
        "entities": List[str],  # optional
        "on_failure": Optional[str],
        "threshold": Optional[float],
        "mask": List[str],  # optional
        "regions": List[str],  # optional
        "entity_thresholds": Dict[str, float],  # optional
        "models_config": {  # optional
            "mode": Optional[str],
            "models": [{  # optional
                "model": Optional[str],
                "display_name": Optional[str],
                "weight": Optional[float],
                "integration_id": Optional[str],
            }],
            "fallback_on_codes": List[int],  # optional
        },
        "checks": Dict[str, SignalsCheck],  # optional
    }],
    "priority": int,
    "cache_config": {  # optional
        "ttl": int,
    },
}
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  id: string;
  createdAt: Date;
  updatedAt: Date;
  createdById: string;
  updatedById: string;
  projectId: string;
  displayName: string;
  description: string;
  enabled: boolean;
  expression?: {
    config?: Record<string, unknown>;
    cel?: string;
  };
  modelsConfig?: {
    mode?: string;
    models?: {
      model?: string;
      displayName?: string;
      weight?: number;
      integrationId?: string;
    }[];
    fallbackOnCodes?: number[];
  };
  plugins: {
    id?: string;
    language?: string;
    entities?: string[];
    onFailure?: string;
    threshold?: number;
    mask?: string[];
    regions?: string[];
    entityThresholds?: Record<string, number>;
    modelsConfig?: {
      mode?: string;
      models?: {
        model?: string;
        displayName?: string;
        weight?: number;
        integrationId?: string;
      }[];
      fallbackOnCodes?: number[];
    };
    checks?: Record<string, SignalsCheck>;
  }[];
  priority: number;
  cacheConfig?: {
    ttl: number;
  };
}
```


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