Policies
List Policies
Returns a paginated list of policies for the current project.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)
Show Parameters
Show Parameters
{
"limit": Optional[int],
"starting_after": Optional[str],
"ending_before": Optional[str],
"project_id": Optional[str],
}
Show Response
Show Response
{
"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],
},
"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", "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],
},
"slug": str,
"timeout": int,
"updated_at": date,
"updated_by_id": str,
},
"has_more": bool,
"object": str,
}
Create a Policy
Creates a new router policy with model configuration, evaluators, retry settings, and limits.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)
Show Parameters
Show Parameters
{
"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],
},
"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", "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],
},
"timeout": Optional[int],
}
Show Response
Show Response
{
"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],
},
"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", "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],
},
"slug": str,
"timeout": int,
"updated_at": date,
"updated_by_id": str,
}
Delete a Policy
Deletes an existing policy by ID.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 ...
Show Parameters
Show Parameters
{
"policy_id": str, # required
}
Retrieve a Policy
Retrieves the details of an existing policy by ID.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)
Show Parameters
Show Parameters
{
"policy_id": str, # required
}
Show Response
Show Response
{
"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],
},
"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", "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],
},
"slug": str,
"timeout": int,
"updated_at": date,
"updated_by_id": str,
}
Update a Policy
Partially updates an existing policy. Only provided fields are updated.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)
Show Parameters
Show Parameters
{
"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],
},
"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", "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],
},
"timeout": Optional[int],
}
Show Response
Show Response
{
"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],
},
"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", "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],
},
"slug": str,
"timeout": int,
"updated_at": date,
"updated_by_id": str,
}