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

# Policies SDK Reference

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

## Policies

### List Policies

Returns a paginated list of policies for the current project.

<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.policies.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.policies.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],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      limit?: number;
      startingAfter?: string;
      endingBefore?: string;
      projectId?: 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,
            "evaluators": [{  # optional
                "execute_on": Literal["input", "output", "both"],
                "id": str,
                "is_guardrail": Optional[bool],
                "sample_rate": Optional[float],
                "timeout": Optional[int],
            }],
            "limits": {  # optional
                "budget": {  # optional
                    "amount": float,
                    "currency": Literal["usd"],
                    "period": Literal["hour", "day", "week", "month"],
                },
                "requests": {  # optional
                    "amount": int,
                    "period": Literal["hour", "day", "week", "month"],
                },
                "tokens": {  # optional
                    "amount": int,
                    "period": Literal["hour", "day", "week", "month"],
                },
            },
            "models_config": {  # optional
                "mode": Literal["fallback", "latency_based", "weighted", "round_robin"],
                "models": [{
                    "display_name": Optional[str],
                    "integration_id": Optional[str],
                    "model": str,
                    "weight": Optional[float],
                }],
            },
            "project_id": str,
            "retry_config": {  # optional
                "count": int,
                "on_codes": List[int],  # optional
            },
            "slug": str,
            "timeout": int,
            "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;
        evaluators?: {
          executeOn: "input" | "output" | "both";
          id: string;
          isGuardrail?: boolean;
          sampleRate?: number;
          timeout?: number;
        }[];
        limits?: {
          budget?: {
            amount: number;
            currency: "usd";
            period: "hour" | "day" | "week" | "month";
          };
          requests?: {
            amount: number;
            period: "hour" | "day" | "week" | "month";
          };
          tokens?: {
            amount: number;
            period: "hour" | "day" | "week" | "month";
          };
        };
        modelsConfig?: {
          mode: "fallback" | "latency_based" | "weighted" | "round_robin";
          models: {
            displayName?: string;
            integrationId?: string;
            model: string;
            weight?: number;
          }[];
        };
        projectId: string;
        retryConfig?: {
          count: number;
          onCodes?: number[];
        };
        slug: string;
        timeout: number;
        updatedAt: Date;
        updatedById: string;
      }[];
      hasMore: boolean;
      object: string;
    }
    ```
  </CodeGroup>
</Expandable>

### Create a Policy

Creates a new router policy with model configuration, evaluators, retry settings, and limits.

<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.policies.create(display_name="Zelda80")

      # 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.policies.create({
      displayName: "Zelda80",
    });

    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],
        "evaluators": [{  # optional
            "execute_on": Literal["input", "output", "both"],  # required
            "id": str,  # required
            "is_guardrail": Optional[bool],
            "sample_rate": Optional[float],
            "timeout": Optional[int],
        }],
        "limits": {  # optional
            "budget": {  # optional
                "amount": float,  # required
                "currency": Literal["usd"],  # required
                "period": Literal["hour", "day", "week", "month"],  # required
            },
            "requests": {  # optional
                "amount": int,  # required
                "period": Literal["hour", "day", "week", "month"],  # required
            },
            "tokens": {  # optional
                "amount": int,  # required
                "period": Literal["hour", "day", "week", "month"],  # required
            },
        },
        "models_config": {  # optional
            "mode": Literal["fallback", "latency_based", "weighted", "round_robin"],  # required
            "models": [{  # required
                "display_name": Optional[str],
                "integration_id": Optional[str],
                "model": str,  # required
                "weight": Optional[float],
            }],
        },
        "project_id": Optional[str],
        "retry_config": {  # optional
            "count": int,  # required
            "on_codes": List[int],  # optional
        },
        "timeout": Optional[int],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      description?: string;
      displayName: string;  // required
      enabled?: boolean;
      evaluators?: {
        executeOn: "input" | "output" | "both";  // required
        id: string;  // required
        isGuardrail?: boolean;
        sampleRate?: number;
        timeout?: number;
      }[];
      limits?: {
        budget?: {
          amount: number;  // required
          currency: "usd";  // required
          period: "hour" | "day" | "week" | "month";  // required
        };
        requests?: {
          amount: number;  // required
          period: "hour" | "day" | "week" | "month";  // required
        };
        tokens?: {
          amount: number;  // required
          period: "hour" | "day" | "week" | "month";  // required
        };
      };
      modelsConfig?: {
        mode: "fallback" | "latency_based" | "weighted" | "round_robin";  // required
        models: {  // required
          displayName?: string;
          integrationId?: string;
          model: string;  // required
          weight?: number;
        }[];
      };
      projectId?: string;
      retryConfig?: {
        count: number;  // required
        onCodes?: number[];
      };
      timeout?: 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,
        "evaluators": [{  # optional
            "execute_on": Literal["input", "output", "both"],
            "id": str,
            "is_guardrail": Optional[bool],
            "sample_rate": Optional[float],
            "timeout": Optional[int],
        }],
        "limits": {  # optional
            "budget": {  # optional
                "amount": float,
                "currency": Literal["usd"],
                "period": Literal["hour", "day", "week", "month"],
            },
            "requests": {  # optional
                "amount": int,
                "period": Literal["hour", "day", "week", "month"],
            },
            "tokens": {  # optional
                "amount": int,
                "period": Literal["hour", "day", "week", "month"],
            },
        },
        "models_config": {  # optional
            "mode": Literal["fallback", "latency_based", "weighted", "round_robin"],
            "models": [{
                "display_name": Optional[str],
                "integration_id": Optional[str],
                "model": str,
                "weight": Optional[float],
            }],
        },
        "project_id": str,
        "retry_config": {  # optional
            "count": int,
            "on_codes": List[int],  # optional
        },
        "slug": str,
        "timeout": int,
        "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;
      evaluators?: {
        executeOn: "input" | "output" | "both";
        id: string;
        isGuardrail?: boolean;
        sampleRate?: number;
        timeout?: number;
      }[];
      limits?: {
        budget?: {
          amount: number;
          currency: "usd";
          period: "hour" | "day" | "week" | "month";
        };
        requests?: {
          amount: number;
          period: "hour" | "day" | "week" | "month";
        };
        tokens?: {
          amount: number;
          period: "hour" | "day" | "week" | "month";
        };
      };
      modelsConfig?: {
        mode: "fallback" | "latency_based" | "weighted" | "round_robin";
        models: {
          displayName?: string;
          integrationId?: string;
          model: string;
          weight?: number;
        }[];
      };
      projectId: string;
      retryConfig?: {
        count: number;
        onCodes?: number[];
      };
      slug: string;
      timeout: number;
      updatedAt: Date;
      updatedById: string;
    }
    ```
  </CodeGroup>
</Expandable>

### Delete a Policy

Deletes an existing policy 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.policies.delete(policy_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.policies.delete({
      policyId: "<id>",
    });

  }

  run();
  ```
</CodeGroup>

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

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

### Retrieve a Policy

Retrieves the details of an existing policy 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.policies.retrieve(policy_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.policies.retrieve({
      policyId: "<id>",
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

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

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      policyId: 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,
        "evaluators": [{  # optional
            "execute_on": Literal["input", "output", "both"],
            "id": str,
            "is_guardrail": Optional[bool],
            "sample_rate": Optional[float],
            "timeout": Optional[int],
        }],
        "limits": {  # optional
            "budget": {  # optional
                "amount": float,
                "currency": Literal["usd"],
                "period": Literal["hour", "day", "week", "month"],
            },
            "requests": {  # optional
                "amount": int,
                "period": Literal["hour", "day", "week", "month"],
            },
            "tokens": {  # optional
                "amount": int,
                "period": Literal["hour", "day", "week", "month"],
            },
        },
        "models_config": {  # optional
            "mode": Literal["fallback", "latency_based", "weighted", "round_robin"],
            "models": [{
                "display_name": Optional[str],
                "integration_id": Optional[str],
                "model": str,
                "weight": Optional[float],
            }],
        },
        "project_id": str,
        "retry_config": {  # optional
            "count": int,
            "on_codes": List[int],  # optional
        },
        "slug": str,
        "timeout": int,
        "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;
      evaluators?: {
        executeOn: "input" | "output" | "both";
        id: string;
        isGuardrail?: boolean;
        sampleRate?: number;
        timeout?: number;
      }[];
      limits?: {
        budget?: {
          amount: number;
          currency: "usd";
          period: "hour" | "day" | "week" | "month";
        };
        requests?: {
          amount: number;
          period: "hour" | "day" | "week" | "month";
        };
        tokens?: {
          amount: number;
          period: "hour" | "day" | "week" | "month";
        };
      };
      modelsConfig?: {
        mode: "fallback" | "latency_based" | "weighted" | "round_robin";
        models: {
          displayName?: string;
          integrationId?: string;
          model: string;
          weight?: number;
        }[];
      };
      projectId: string;
      retryConfig?: {
        count: number;
        onCodes?: number[];
      };
      slug: string;
      timeout: number;
      updatedAt: Date;
      updatedById: string;
    }
    ```
  </CodeGroup>
</Expandable>

### Update a Policy

Partially updates an existing policy. 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.policies.update(policy_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.policies.update({
      policyId: "<id>",
      requestBody: {},
    });

    console.log(result);
  }

  run();
  ```
</CodeGroup>

<Expandable title="Parameters">
  <CodeGroup>
    ```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
        "policy_id": str,  # required
        "description": Optional[str],
        "display_name": Optional[str],
        "enabled": Optional[bool],
        "evaluators": [{  # optional
            "execute_on": Literal["input", "output", "both"],  # required
            "id": str,  # required
            "is_guardrail": Optional[bool],
            "sample_rate": Optional[float],
            "timeout": Optional[int],
        }],
        "limits": {  # optional
            "budget": {  # optional
                "amount": float,  # required
                "currency": Literal["usd"],  # required
                "period": Literal["hour", "day", "week", "month"],  # required
            },
            "requests": {  # optional
                "amount": int,  # required
                "period": Literal["hour", "day", "week", "month"],  # required
            },
            "tokens": {  # optional
                "amount": int,  # required
                "period": Literal["hour", "day", "week", "month"],  # required
            },
        },
        "models_config": {  # optional
            "mode": Literal["fallback", "latency_based", "weighted", "round_robin"],  # required
            "models": [{  # required
                "display_name": Optional[str],
                "integration_id": Optional[str],
                "model": str,  # required
                "weight": Optional[float],
            }],
        },
        "project_id": Optional[str],
        "retry_config": {  # optional
            "count": int,  # required
            "on_codes": List[int],  # optional
        },
        "timeout": Optional[int],
    }
    ```

    ```typescript Node.js theme={"theme":{"light":"github-light","dark":"github-dark"}}
    {
      policyId: string;  // required
      requestBody: {  // required
        description?: string;
        displayName?: string;
        enabled?: boolean;
        evaluators?: {
          executeOn: "input" | "output" | "both";  // required
          id: string;  // required
          isGuardrail?: boolean;
          sampleRate?: number;
          timeout?: number;
        }[];
        limits?: {
          budget?: {
            amount: number;  // required
            currency: "usd";  // required
            period: "hour" | "day" | "week" | "month";  // required
          };
          requests?: {
            amount: number;  // required
            period: "hour" | "day" | "week" | "month";  // required
          };
          tokens?: {
            amount: number;  // required
            period: "hour" | "day" | "week" | "month";  // required
          };
        };
        modelsConfig?: {
          mode: "fallback" | "latency_based" | "weighted" | "round_robin";  // required
          models: {  // required
            displayName?: string;
            integrationId?: string;
            model: string;  // required
            weight?: number;
          }[];
        };
        projectId?: string;
        retryConfig?: {
          count: number;  // required
          onCodes?: number[];
        };
        timeout?: 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,
        "evaluators": [{  # optional
            "execute_on": Literal["input", "output", "both"],
            "id": str,
            "is_guardrail": Optional[bool],
            "sample_rate": Optional[float],
            "timeout": Optional[int],
        }],
        "limits": {  # optional
            "budget": {  # optional
                "amount": float,
                "currency": Literal["usd"],
                "period": Literal["hour", "day", "week", "month"],
            },
            "requests": {  # optional
                "amount": int,
                "period": Literal["hour", "day", "week", "month"],
            },
            "tokens": {  # optional
                "amount": int,
                "period": Literal["hour", "day", "week", "month"],
            },
        },
        "models_config": {  # optional
            "mode": Literal["fallback", "latency_based", "weighted", "round_robin"],
            "models": [{
                "display_name": Optional[str],
                "integration_id": Optional[str],
                "model": str,
                "weight": Optional[float],
            }],
        },
        "project_id": str,
        "retry_config": {  # optional
            "count": int,
            "on_codes": List[int],  # optional
        },
        "slug": str,
        "timeout": int,
        "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;
      evaluators?: {
        executeOn: "input" | "output" | "both";
        id: string;
        isGuardrail?: boolean;
        sampleRate?: number;
        timeout?: number;
      }[];
      limits?: {
        budget?: {
          amount: number;
          currency: "usd";
          period: "hour" | "day" | "week" | "month";
        };
        requests?: {
          amount: number;
          period: "hour" | "day" | "week" | "month";
        };
        tokens?: {
          amount: number;
          period: "hour" | "day" | "week" | "month";
        };
      };
      modelsConfig?: {
        mode: "fallback" | "latency_based" | "weighted" | "round_robin";
        models: {
          displayName?: string;
          integrationId?: string;
          model: string;
          weight?: number;
        }[];
      };
      projectId: string;
      retryConfig?: {
        count: number;
        onCodes?: number[];
      };
      slug: string;
      timeout: number;
      updatedAt: Date;
      updatedById: string;
    }
    ```
  </CodeGroup>
</Expandable>
