curl --request POST \
--url https://api.portkey.ai/v1/policies/usage-limits \
--header 'Content-Type: application/json' \
--header 'x-portkey-api-key: <api-key>' \
--data '
{
"name": "Monthly Cost Limit per API Key",
"conditions": [
{
"key": "workspace_id",
"value": "workspace-123"
}
],
"group_by": [
{
"key": "api_key"
}
],
"type": "cost",
"credit_limit": 1000,
"alert_threshold": 800,
"periodic_reset": "monthly"
}
'{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"object": "policy_usage_limits"
}Create Usage Limits Policy
Create a new usage limits policy to control total usage (cost or tokens) over a period.
POST
/
policies
/
usage-limits
curl --request POST \
--url https://api.portkey.ai/v1/policies/usage-limits \
--header 'Content-Type: application/json' \
--header 'x-portkey-api-key: <api-key>' \
--data '
{
"name": "Monthly Cost Limit per API Key",
"conditions": [
{
"key": "workspace_id",
"value": "workspace-123"
}
],
"group_by": [
{
"key": "api_key"
}
],
"type": "cost",
"credit_limit": 1000,
"alert_threshold": 800,
"periodic_reset": "monthly"
}
'{
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"object": "policy_usage_limits"
}Authorizations
Body
application/json
Array of conditions that define which requests the policy applies to
Minimum array length:
1Show child attributes
Show child attributes
Array of group by fields that define how usage is aggregated
Minimum array length:
1Show child attributes
Show child attributes
Policy type
Available options:
cost, tokens Maximum usage allowed
Required range:
x >= 0Policy name
Maximum string length:
255Example:
"Monthly Cost Limit"
Threshold at which to send alerts. Must be less than credit_limit.
Required range:
x >= 0Reset period. If not provided, limit is cumulative.
Available options:
monthly, weekly Workspace ID or slug. Required if not using API key authentication.
Organization ID. Required if not using API key authentication.
Was this page helpful?
⌘I

